1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00
CC-Tweaked/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java

44 lines
1.2 KiB
Java
Raw Normal View History

/*
* This file is part of ComputerCraft - http://www.computercraft.info
2019-01-01 01:10:18 +00:00
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.shared.util.InventoryUtil;
2019-04-03 22:27:10 +00:00
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
2019-04-03 22:27:10 +00:00
import net.minecraft.util.Hand;
2017-05-06 23:07:42 +00:00
import javax.annotation.Nonnull;
public class ContainerHeldItem extends Container
{
private final ItemStack m_stack;
2019-04-03 22:27:10 +00:00
private final Hand m_hand;
2019-04-03 22:27:10 +00:00
public ContainerHeldItem( int id, PlayerEntity player, Hand hand )
{
2019-04-03 22:27:10 +00:00
super( null, id );
m_hand = hand;
2019-04-03 22:27:10 +00:00
m_stack = InventoryUtil.copyItem( player.getStackInHand( hand ) );
}
2017-05-11 00:08:26 +00:00
@Nonnull
public ItemStack getStack()
{
return m_stack;
}
@Override
2019-04-03 22:27:10 +00:00
public boolean canUse( @Nonnull PlayerEntity player )
{
if( !player.isAlive() ) return false;
2019-04-03 22:27:10 +00:00
ItemStack stack = player.getStackInHand( m_hand );
return stack == m_stack || !stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem();
}
}