Fire all entity interaction events in TurtlePlaceCommand

This allows turtles to interact with entities correctly.
This commit is contained in:
SquidDev 2017-05-01 15:39:03 +01:00
parent d050ca9849
commit bbbbccf63d
9 changed files with 167 additions and 159 deletions

View File

@ -53,9 +53,10 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@ -366,14 +367,14 @@ public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle )
player.openGui( instance, ComputerCraft.turtleGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() );
}
public static void openPrintoutGUI( EntityPlayer player )
public static void openPrintoutGUI( EntityPlayer player, EnumHand hand )
{
player.openGui( ComputerCraft.instance, ComputerCraft.printoutGUIID, player.getEntityWorld(), 0, 0, 0 );
player.openGui( ComputerCraft.instance, ComputerCraft.printoutGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 );
}
public static void openPocketComputerGUI( EntityPlayer player )
public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
player.openGui( ComputerCraft.instance, ComputerCraft.pocketComputerGUIID, player.getEntityWorld(), 0, 0, 0 );
player.openGui( ComputerCraft.instance, ComputerCraft.pocketComputerGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 );
}
public static File getBaseDir()

View File

@ -34,11 +34,11 @@
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent;
@ -176,7 +176,7 @@ public ModelResourceLocation getModelLocation( ItemStack stack )
"advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", "advanced_pocket_computer_on_modem_on", "advanced_pocket_computer_blinking_modem_on",
} );
// Setup item colours
// Setup
mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.disk), ComputerCraft.Items.disk);
mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.diskExpanded), ComputerCraft.Items.diskExpanded);
@ -312,9 +312,9 @@ public Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle )
}
@Override
public Object getPrintoutGUI( InventoryPlayer inventory )
public Object getPrintoutGUI( EntityPlayer player, EnumHand hand )
{
ContainerHeldItem container = new ContainerHeldItem( inventory );
ContainerHeldItem container = new ContainerHeldItem( player, hand );
if( container.getStack() != null && container.getStack().getItem() instanceof ItemPrintout )
{
return new GuiPrintout( container );
@ -323,9 +323,9 @@ public Object getPrintoutGUI( InventoryPlayer inventory )
}
@Override
public Object getPocketComputerGUI( InventoryPlayer inventory )
public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
ContainerHeldItem container = new ContainerHeldItem( inventory );
ContainerHeldItem container = new ContainerHeldItem( player, hand );
if( container.getStack() != null && container.getStack().getItem() instanceof ItemPocketComputer )
{
return new GuiPocketComputer( container );

View File

@ -12,7 +12,9 @@
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -88,13 +90,13 @@ public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer )
}
@Override
public Object getPrintoutGUI( InventoryPlayer inventory )
public Object getPrintoutGUI( EntityPlayer player, EnumHand hand )
{
return null;
}
@Override
public Object getPocketComputerGUI( InventoryPlayer inventory )
public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
return null;
}

View File

@ -8,19 +8,19 @@
import dan200.computercraft.shared.util.InventoryUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
public class ContainerHeldItem extends Container
{
private final ItemStack m_stack;
private final int m_slot;
private final EnumHand m_hand;
public ContainerHeldItem( InventoryPlayer player )
public ContainerHeldItem( EntityPlayer player, EnumHand hand )
{
m_slot = player.currentItem;
m_stack = InventoryUtil.copyItem( player.getStackInSlot( m_slot ) );
m_hand = hand;
m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
}
public ItemStack getStack()
@ -33,7 +33,7 @@ public boolean canInteractWith( EntityPlayer player )
{
if( player != null && player.isEntityAlive() )
{
ItemStack stack = player.inventory.getStackInSlot( m_slot );
ItemStack stack = player.getHeldItem( m_hand );
if( (stack == m_stack) || (stack != null && m_stack != null && stack.getItem() == m_stack.getItem()) )
{
return true;

View File

@ -85,10 +85,9 @@ public ActionResult<ItemStack> onItemRightClick( ItemStack stack, World world, E
{
if( !world.isRemote )
{
ComputerCraft.openPrintoutGUI( player );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
ComputerCraft.openPrintoutGUI( player, hand );
}
return new ActionResult<ItemStack>( EnumActionResult.PASS, stack );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
}
private static ItemStack createFromTitleAndText( Type type, String title, String[] text, String[] colours )

View File

@ -30,11 +30,13 @@
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.text.translation.I18n;;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import java.util.List;
;
public class ItemPocketComputer extends Item implements IComputerItem, IMedia
{
public ItemPocketComputer()
@ -169,10 +171,9 @@ public ActionResult<ItemStack> onItemRightClick( ItemStack stack, World world, E
{
computer.turnOn();
}
ComputerCraft.openPocketComputerGUI( player );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
ComputerCraft.openPocketComputerGUI( player, hand );
}
return new ActionResult<ItemStack>( EnumActionResult.PASS, stack );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
}
@Override

View File

@ -63,6 +63,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
@ -148,10 +149,10 @@ public String getRecordInfo( ItemStack recordStack )
public abstract Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
@Override
public abstract Object getPrintoutGUI( InventoryPlayer inventory );
public abstract Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
@Override
public abstract Object getPocketComputerGUI( InventoryPlayer inventory );
public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
public abstract File getWorldDir( World world );
@ -164,8 +165,7 @@ public void handlePacket( final ComputerCraftPacket packet, final EntityPlayer p
if (listener.isCallingFromMinecraftThread())
{
processPacket( packet, player );
}
else
} else
{
listener.addScheduledTask( new Runnable()
{
@ -546,11 +546,11 @@ public Object getServerGuiElement( int id, EntityPlayer player, World world, int
}
case ComputerCraft.printoutGUIID:
{
return new ContainerHeldItem( player.inventory );
return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.MAIN_HAND );
}
case ComputerCraft.pocketComputerGUIID:
{
return new ContainerHeldItem( player.inventory );
return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
}
}
return null;
@ -604,11 +604,11 @@ public Object getClientGuiElement( int id, EntityPlayer player, World world, int
}
case ComputerCraft.printoutGUIID:
{
return getPrintoutGUI( player.inventory );
return getPrintoutGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
}
case ComputerCraft.pocketComputerGUIID:
{
return getPocketComputerGUI( player.inventory );
return getPocketComputerGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
}
}
return null;

View File

@ -14,6 +14,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -38,8 +39,8 @@ public interface IComputerCraftProxy
public Object getComputerGUI( TileComputer computer );
public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer );
public Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
public abstract Object getPrintoutGUI( InventoryPlayer inventory );
public abstract Object getPocketComputerGUI( InventoryPlayer inventory );
public abstract Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
public File getWorldDir( World world );
public void handlePacket( ComputerCraftPacket packet, EntityPlayer player );

View File

@ -240,6 +240,10 @@ public void consumeDrop( Entity entity, ItemStack drop )
placed = true;
turtlePlayer.loadInventory( stackCopy );
}
else if( hitEntity.processInitialInteract( turtlePlayer, stackCopy, EnumHand.MAIN_HAND ) )
{
placed = true;
}
else if( hitEntity instanceof EntityLivingBase )
{
placed = item.itemInteractionForEntity( stackCopy, turtlePlayer, (EntityLivingBase)hitEntity, EnumHand.MAIN_HAND );