1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-02-04 13:19:13 +00:00

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.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property; import net.minecraftforge.common.config.Property;
@ -366,14 +367,14 @@ public class ComputerCraft
player.openGui( instance, ComputerCraft.turtleGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); 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() public static File getBaseDir()

View File

@ -34,11 +34,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; 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.ResourceLocation;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderHandEvent;
@ -176,7 +176,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
"advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", "advanced_pocket_computer_on_modem_on", "advanced_pocket_computer_blinking_modem_on", "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.disk), ComputerCraft.Items.disk);
mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.diskExpanded), ComputerCraft.Items.diskExpanded); mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.diskExpanded), ComputerCraft.Items.diskExpanded);
@ -312,9 +312,9 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} }
@Override @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 ) if( container.getStack() != null && container.getStack().getItem() instanceof ItemPrintout )
{ {
return new GuiPrintout( container ); return new GuiPrintout( container );
@ -323,9 +323,9 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} }
@Override @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 ) if( container.getStack() != null && container.getStack().getItem() instanceof ItemPocketComputer )
{ {
return new GuiPocketComputer( container ); return new GuiPocketComputer( container );

View File

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

View File

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

View File

@ -20,11 +20,11 @@ import net.minecraft.world.World;
import java.util.List; import java.util.List;
public class ItemPrintout extends Item public class ItemPrintout extends Item
{ {
public static final int LINES_PER_PAGE = 21; public static final int LINES_PER_PAGE = 21;
public static final int LINE_MAX_LENGTH = 25; public static final int LINE_MAX_LENGTH = 25;
public static final int MAX_PAGES = 16; public static final int MAX_PAGES = 16;
public enum Type public enum Type
{ {
Single, Single,
@ -39,7 +39,7 @@ public class ItemPrintout extends Item
setUnlocalizedName( "computercraft:page" ); setUnlocalizedName( "computercraft:page" );
setCreativeTab( ComputerCraft.mainCreativeTab ); setCreativeTab( ComputerCraft.mainCreativeTab );
} }
@Override @Override
public void getSubItems( Item itemID, CreativeTabs tabs, List list ) public void getSubItems( Item itemID, CreativeTabs tabs, List list )
{ {
@ -47,7 +47,7 @@ public class ItemPrintout extends Item
list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) );
list.add( createBookFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); list.add( createBookFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) );
} }
@Override @Override
public void addInformation( ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean flag ) public void addInformation( ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean flag )
{ {
@ -57,7 +57,7 @@ public class ItemPrintout extends Item
list.add( title ); list.add( title );
} }
} }
@Override @Override
public String getUnlocalizedName( ItemStack stack ) public String getUnlocalizedName( ItemStack stack )
{ {
@ -79,18 +79,17 @@ public class ItemPrintout extends Item
} }
} }
} }
@Override @Override
public ActionResult<ItemStack> onItemRightClick( ItemStack stack, World world, EntityPlayer player, EnumHand hand ) public ActionResult<ItemStack> onItemRightClick( ItemStack stack, World world, EntityPlayer player, EnumHand hand )
{ {
if( !world.isRemote ) if( !world.isRemote )
{ {
ComputerCraft.openPrintoutGUI( player ); ComputerCraft.openPrintoutGUI( player, hand );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
} }
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 ) private static ItemStack createFromTitleAndText( Type type, String title, String[] text, String[] colours )
{ {
// Calculate damage // Calculate damage
@ -150,12 +149,12 @@ public class ItemPrintout extends Item
// Return stack // Return stack
return stack; return stack;
} }
public static ItemStack createSingleFromTitleAndText( String title, String[] text, String[] colours ) public static ItemStack createSingleFromTitleAndText( String title, String[] text, String[] colours )
{ {
return createFromTitleAndText( Type.Single, title, text, colours ); return createFromTitleAndText( Type.Single, title, text, colours );
} }
public static ItemStack createMultipleFromTitleAndText( String title, String[] text, String[] colours ) public static ItemStack createMultipleFromTitleAndText( String title, String[] text, String[] colours )
{ {
return createFromTitleAndText( Type.Multiple, title, text, colours ); return createFromTitleAndText( Type.Multiple, title, text, colours );
@ -196,7 +195,7 @@ public class ItemPrintout extends Item
} }
return null; return null;
} }
public static int getPageCount( ItemStack stack ) public static int getPageCount( ItemStack stack )
{ {
NBTTagCompound nbt = stack.getTagCompound(); NBTTagCompound nbt = stack.getTagCompound();
@ -206,7 +205,7 @@ public class ItemPrintout extends Item
} }
return 1; return 1;
} }
public static String[] getText( ItemStack stack ) public static String[] getText( ItemStack stack )
{ {
NBTTagCompound nbt = stack.getTagCompound(); NBTTagCompound nbt = stack.getTagCompound();
@ -224,8 +223,8 @@ public class ItemPrintout extends Item
} }
} }
return lines; return lines;
} }
public static String[] getColours( ItemStack stack ) public static String[] getColours( ItemStack stack )
{ {
NBTTagCompound nbt = stack.getTagCompound(); NBTTagCompound nbt = stack.getTagCompound();

View File

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

View File

@ -63,6 +63,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener; import net.minecraft.util.IThreadListener;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -86,7 +87,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public ComputerCraftProxyCommon() public ComputerCraftProxyCommon()
{ {
} }
// IComputerCraftProxy implementation // IComputerCraftProxy implementation
@Override @Override
@ -94,17 +95,17 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
{ {
registerItems(); registerItems();
} }
@Override @Override
public void init() public void init()
{ {
registerTileEntities(); registerTileEntities();
registerForgeHandlers(); registerForgeHandlers();
} }
@Override @Override
public abstract boolean isClient(); public abstract boolean isClient();
@Override @Override
public abstract boolean getGlobalCursorBlink(); public abstract boolean getGlobalCursorBlink();
@ -118,12 +119,12 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
@Override @Override
public abstract Object getFixedWidthFontRenderer(); public abstract Object getFixedWidthFontRenderer();
@Override @Override
public String getRecordInfo( ItemStack recordStack ) public String getRecordInfo( ItemStack recordStack )
{ {
Item item = recordStack.getItem(); Item item = recordStack.getItem();
if( item instanceof ItemRecord ) if (item instanceof ItemRecord)
{ {
ItemRecord record = (ItemRecord) item; ItemRecord record = (ItemRecord) item;
String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" ); String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" );
@ -131,13 +132,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
} }
return null; return null;
} }
@Override @Override
public abstract void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos ); public abstract void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos );
@Override @Override
public abstract Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive ); public abstract Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );
@Override @Override
public abstract Object getComputerGUI( TileComputer computer ); public abstract Object getComputerGUI( TileComputer computer );
@ -148,24 +149,23 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public abstract Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle ); public abstract Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
@Override @Override
public abstract Object getPrintoutGUI( InventoryPlayer inventory ); public abstract Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
@Override @Override
public abstract Object getPocketComputerGUI( InventoryPlayer inventory ); public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
public abstract File getWorldDir( World world ); public abstract File getWorldDir( World world );
@Override @Override
public void handlePacket( final ComputerCraftPacket packet, final EntityPlayer player ) public void handlePacket( final ComputerCraftPacket packet, final EntityPlayer player )
{ {
IThreadListener listener = player.getServer(); IThreadListener listener = player.getServer();
if( listener != null ) if (listener != null)
{ {
if( listener.isCallingFromMinecraftThread() ) if (listener.isCallingFromMinecraftThread())
{ {
processPacket( packet, player ); processPacket( packet, player );
} } else
else
{ {
listener.addScheduledTask( new Runnable() listener.addScheduledTask( new Runnable()
{ {
@ -181,7 +181,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
private void processPacket( ComputerCraftPacket packet, EntityPlayer player ) private void processPacket( ComputerCraftPacket packet, EntityPlayer player )
{ {
switch( packet.m_packetType ) switch (packet.m_packetType)
{ {
/////////////////////////////////// ///////////////////////////////////
// Packets from Client to Server // // Packets from Client to Server //
@ -195,7 +195,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
{ {
int instance = packet.m_dataInt[0]; int instance = packet.m_dataInt[0];
ServerComputer computer = ComputerCraft.serverComputerRegistry.get( instance ); ServerComputer computer = ComputerCraft.serverComputerRegistry.get( instance );
if( computer != null ) if (computer != null)
{ {
computer.handlePacket( packet, player ); computer.handlePacket( packet, player );
} }
@ -209,13 +209,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
BlockPos pos = new BlockPos( x, y, z ); BlockPos pos = new BlockPos( x, y, z );
World world = player.getEntityWorld(); World world = player.getEntityWorld();
TileEntity tileEntity = world.getTileEntity( pos ); TileEntity tileEntity = world.getTileEntity( pos );
if( tileEntity != null && tileEntity instanceof TileGeneric ) if (tileEntity != null && tileEntity instanceof TileGeneric)
{ {
TileGeneric generic = (TileGeneric)tileEntity; TileGeneric generic = (TileGeneric) tileEntity;
Packet description = generic.getUpdatePacket(); Packet description = generic.getUpdatePacket();
if( description != null ) if (description != null)
{ {
((EntityPlayerMP)player).connection.sendPacket( description ); ((EntityPlayerMP) player).connection.sendPacket( description );
} }
} }
break; break;
@ -280,93 +280,93 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Computer // Computer
ItemStack computer = ComputerItemFactory.create( -1, null, ComputerFamily.Normal ); ItemStack computer = ComputerItemFactory.create( -1, null, ComputerFamily.Normal );
GameRegistry.addRecipe( computer, GameRegistry.addRecipe( computer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.REDSTONE, 'Y', Items.REDSTONE,
'Z', Blocks.GLASS_PANE 'Z', Blocks.GLASS_PANE
); );
// Advanced Computer // Advanced Computer
ItemStack advancedComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ); ItemStack advancedComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Advanced );
GameRegistry.addRecipe( advancedComputer, GameRegistry.addRecipe( advancedComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Items.GOLD_INGOT, 'X', Items.GOLD_INGOT,
'Y', Items.REDSTONE, 'Y', Items.REDSTONE,
'Z', Blocks.GLASS_PANE 'Z', Blocks.GLASS_PANE
); );
// Disk Drive // Disk Drive
ItemStack diskDrive = PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 ); ItemStack diskDrive = PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 );
GameRegistry.addRecipe( diskDrive, GameRegistry.addRecipe( diskDrive,
"XXX", "XYX", "XYX", "XXX", "XYX", "XYX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.REDSTONE 'Y', Items.REDSTONE
); );
// Wireless Modem // Wireless Modem
ItemStack wirelessModem = PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ); ItemStack wirelessModem = PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 );
GameRegistry.addRecipe( wirelessModem, GameRegistry.addRecipe( wirelessModem,
"XXX", "XYX", "XXX", "XXX", "XYX", "XXX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.ENDER_PEARL 'Y', Items.ENDER_PEARL
); );
// Monitor // Monitor
ItemStack monitor = PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ); ItemStack monitor = PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 );
GameRegistry.addRecipe( monitor, GameRegistry.addRecipe( monitor,
"XXX", "XYX", "XXX", "XXX", "XYX", "XXX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Blocks.GLASS_PANE 'Y', Blocks.GLASS_PANE
); );
// PrinterEmpty // PrinterEmpty
ItemStack printer = PeripheralItemFactory.create( PeripheralType.Printer, null, 1 ); ItemStack printer = PeripheralItemFactory.create( PeripheralType.Printer, null, 1 );
GameRegistry.addRecipe( printer, GameRegistry.addRecipe( printer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.REDSTONE, 'Y', Items.REDSTONE,
'Z', new ItemStack( Items.DYE, 1, 0 ) // 0 = Black 'Z', new ItemStack( Items.DYE, 1, 0 ) // 0 = Black
); );
// Advanced Monitor // Advanced Monitor
ItemStack advancedMonitors = PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 4 ); ItemStack advancedMonitors = PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 4 );
GameRegistry.addRecipe( advancedMonitors, GameRegistry.addRecipe( advancedMonitors,
"XXX", "XYX", "XXX", "XXX", "XYX", "XXX",
'X', Items.GOLD_INGOT, 'X', Items.GOLD_INGOT,
'Y', Blocks.GLASS_PANE 'Y', Blocks.GLASS_PANE
); );
// Networking Cable // Networking Cable
ItemStack cable = PeripheralItemFactory.create( PeripheralType.Cable, null, 6 ); ItemStack cable = PeripheralItemFactory.create( PeripheralType.Cable, null, 6 );
GameRegistry.addRecipe( cable, GameRegistry.addRecipe( cable,
" X ", "XYX", " X ", " X ", "XYX", " X ",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.REDSTONE 'Y', Items.REDSTONE
); );
// Wired Modem // Wired Modem
ItemStack wiredModem = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ); ItemStack wiredModem = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 );
GameRegistry.addRecipe( wiredModem, GameRegistry.addRecipe( wiredModem,
"XXX", "XYX", "XXX", "XXX", "XYX", "XXX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.REDSTONE 'Y', Items.REDSTONE
); );
// Computer // Computer
ItemStack commandComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Command ); ItemStack commandComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Command );
GameRegistry.addRecipe( commandComputer, GameRegistry.addRecipe( commandComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Blocks.COMMAND_BLOCK, 'Y', Blocks.COMMAND_BLOCK,
'Z', Blocks.GLASS_PANE 'Z', Blocks.GLASS_PANE
); );
// Advanced Modem // Advanced Modem
ItemStack advancedModem = PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 ); ItemStack advancedModem = PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 );
GameRegistry.addRecipe( advancedModem, GameRegistry.addRecipe( advancedModem,
"XXX", "XYX", "XXX", "XXX", "XYX", "XXX",
'X', Items.GOLD_INGOT, 'X', Items.GOLD_INGOT,
'Y', Items.ENDER_EYE 'Y', Items.ENDER_EYE
); );
// Disk // Disk
@ -376,24 +376,24 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
ItemStack paper = new ItemStack( Items.PAPER, 1 ); ItemStack paper = new ItemStack( Items.PAPER, 1 );
ItemStack redstone = new ItemStack( Items.REDSTONE, 1 ); ItemStack redstone = new ItemStack( Items.REDSTONE, 1 );
ItemStack basicDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); ItemStack basicDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() );
GameRegistry.addRecipe( new ImpostorShapelessRecipe( basicDisk, new Object[] { redstone, paper } ) ); GameRegistry.addRecipe( new ImpostorShapelessRecipe( basicDisk, new Object[]{redstone, paper} ) );
for( int colour=0; colour<16; ++colour ) for (int colour = 0; colour < 16; ++colour)
{ {
ItemStack disk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[ colour ].getHex() ); ItemStack disk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() );
ItemStack dye = new ItemStack( Items.DYE, 1, colour ); ItemStack dye = new ItemStack( Items.DYE, 1, colour );
for( int otherColour=0; otherColour<16; ++otherColour ) for (int otherColour = 0; otherColour < 16; ++otherColour)
{ {
if( colour != otherColour ) if (colour != otherColour)
{ {
ItemStack otherDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[ colour ].getHex() ); ItemStack otherDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() );
GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[] { GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[]{
otherDisk, dye otherDisk, dye
} ) ); } ) );
} }
} }
GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[] { GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[]{
redstone, paper, dye redstone, paper, dye
} ) ); } ) );
} }
@ -406,27 +406,27 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Impostor Printout recipes (to fool NEI) // Impostor Printout recipes (to fool NEI)
ItemStack string = new ItemStack( Items.STRING, 1, 0 ); ItemStack string = new ItemStack( Items.STRING, 1, 0 );
GameRegistry.addRecipe( new ImpostorShapelessRecipe( multiplePrintout, new Object[] { singlePrintout, singlePrintout, string } ) ); GameRegistry.addRecipe( new ImpostorShapelessRecipe( multiplePrintout, new Object[]{singlePrintout, singlePrintout, string} ) );
ItemStack leather = new ItemStack( Items.LEATHER, 1, 0 ); ItemStack leather = new ItemStack( Items.LEATHER, 1, 0 );
GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new Object[] { leather, singlePrintout, string } ) ); GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new Object[]{leather, singlePrintout, string} ) );
// Pocket Computer // Pocket Computer
ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, false ); ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, false );
GameRegistry.addRecipe( pocketComputer, GameRegistry.addRecipe( pocketComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Blocks.STONE, 'X', Blocks.STONE,
'Y', Items.GOLDEN_APPLE, 'Y', Items.GOLDEN_APPLE,
'Z', Blocks.GLASS_PANE 'Z', Blocks.GLASS_PANE
); );
// Advanced Pocket Computer // Advanced Pocket Computer
ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, false ); ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, false );
GameRegistry.addRecipe( advancedPocketComputer, GameRegistry.addRecipe( advancedPocketComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Items.GOLD_INGOT, 'X', Items.GOLD_INGOT,
'Y', Items.GOLDEN_APPLE, 'Y', Items.GOLDEN_APPLE,
'Z', Blocks.GLASS_PANE 'Z', Blocks.GLASS_PANE
); );
// Wireless Pocket Computer // Wireless Pocket Computer
@ -437,8 +437,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
ItemStack advancedWirelessPocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, true ); ItemStack advancedWirelessPocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, true );
// Impostor Pocket Computer recipes (to fool NEI) // Impostor Pocket Computer recipes (to fool NEI)
GameRegistry.addRecipe( new ImpostorRecipe( 1, 2, new ItemStack[] { wirelessModem, pocketComputer }, wirelessPocketComputer ) ); GameRegistry.addRecipe( new ImpostorRecipe( 1, 2, new ItemStack[]{wirelessModem, pocketComputer}, wirelessPocketComputer ) );
GameRegistry.addRecipe( new ImpostorRecipe( 1, 2, new ItemStack[] { wirelessModem, advancedPocketComputer }, advancedWirelessPocketComputer ) ); GameRegistry.addRecipe( new ImpostorRecipe( 1, 2, new ItemStack[]{wirelessModem, advancedPocketComputer}, advancedWirelessPocketComputer ) );
// Skulls (Easter Egg) // Skulls (Easter Egg)
// Dan // Dan
@ -455,7 +455,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
cloudyHead.setTagCompound( tag ); cloudyHead.setTagCompound( tag );
GameRegistry.addShapelessRecipe( cloudyHead, monitor, new ItemStack( Items.SKULL, 1, 1 ) ); GameRegistry.addShapelessRecipe( cloudyHead, monitor, new ItemStack( Items.SKULL, 1, 1 ) );
} }
private void registerTileEntities() private void registerTileEntities()
{ {
// Tile Entities // Tile Entities
@ -470,7 +470,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Register peripheral providers // Register peripheral providers
ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() ); ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() );
if( ComputerCraft.enableCommandBlock ) if (ComputerCraft.enableCommandBlock)
{ {
ComputerCraftAPI.registerPeripheralProvider( new CommandBlockPeripheralProvider() ); ComputerCraftAPI.registerPeripheralProvider( new CommandBlockPeripheralProvider() );
} }
@ -481,35 +481,35 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Register media providers // Register media providers
ComputerCraftAPI.registerMediaProvider( new DefaultMediaProvider() ); ComputerCraftAPI.registerMediaProvider( new DefaultMediaProvider() );
} }
private void registerForgeHandlers() private void registerForgeHandlers()
{ {
ForgeHandlers handlers = new ForgeHandlers(); ForgeHandlers handlers = new ForgeHandlers();
MinecraftForge.EVENT_BUS.register( handlers ); MinecraftForge.EVENT_BUS.register( handlers );
NetworkRegistry.INSTANCE.registerGuiHandler( ComputerCraft.instance, handlers ); NetworkRegistry.INSTANCE.registerGuiHandler( ComputerCraft.instance, handlers );
} }
public class ForgeHandlers implements public class ForgeHandlers implements
IGuiHandler IGuiHandler
{ {
private ForgeHandlers() private ForgeHandlers()
{ {
} }
// IGuiHandler implementation // IGuiHandler implementation
@Override @Override
public Object getServerGuiElement( int id, EntityPlayer player, World world, int x, int y, int z ) public Object getServerGuiElement( int id, EntityPlayer player, World world, int x, int y, int z )
{ {
BlockPos pos = new BlockPos( x, y, z ); BlockPos pos = new BlockPos( x, y, z );
switch( id ) switch (id)
{ {
case ComputerCraft.diskDriveGUIID: case ComputerCraft.diskDriveGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileDiskDrive ) if (tile != null && tile instanceof TileDiskDrive)
{ {
TileDiskDrive drive = (TileDiskDrive)tile; TileDiskDrive drive = (TileDiskDrive) tile;
return new ContainerDiskDrive( player.inventory, drive ); return new ContainerDiskDrive( player.inventory, drive );
} }
break; break;
@ -517,9 +517,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.computerGUIID: case ComputerCraft.computerGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileComputer ) if (tile != null && tile instanceof TileComputer)
{ {
TileComputer computer = (TileComputer)tile; TileComputer computer = (TileComputer) tile;
return new ContainerComputer( computer ); return new ContainerComputer( computer );
} }
break; break;
@ -527,9 +527,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.printerGUIID: case ComputerCraft.printerGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePrinter ) if (tile != null && tile instanceof TilePrinter)
{ {
TilePrinter printer = (TilePrinter)tile; TilePrinter printer = (TilePrinter) tile;
return new ContainerPrinter( player.inventory, printer ); return new ContainerPrinter( player.inventory, printer );
} }
break; break;
@ -537,20 +537,20 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.turtleGUIID: case ComputerCraft.turtleGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileTurtle ) if (tile != null && tile instanceof TileTurtle)
{ {
TileTurtle turtle = (TileTurtle)tile; TileTurtle turtle = (TileTurtle) tile;
return new ContainerTurtle( player.inventory, turtle.getAccess() ); return new ContainerTurtle( player.inventory, turtle.getAccess() );
} }
break; break;
} }
case ComputerCraft.printoutGUIID: case ComputerCraft.printoutGUIID:
{ {
return new ContainerHeldItem( player.inventory ); return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.MAIN_HAND );
} }
case ComputerCraft.pocketComputerGUIID: case ComputerCraft.pocketComputerGUIID:
{ {
return new ContainerHeldItem( player.inventory ); return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
} }
} }
return null; return null;
@ -560,14 +560,14 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public Object getClientGuiElement( int id, EntityPlayer player, World world, int x, int y, int z ) public Object getClientGuiElement( int id, EntityPlayer player, World world, int x, int y, int z )
{ {
BlockPos pos = new BlockPos( x, y, z ); BlockPos pos = new BlockPos( x, y, z );
switch( id ) switch (id)
{ {
case ComputerCraft.diskDriveGUIID: case ComputerCraft.diskDriveGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileDiskDrive ) if (tile != null && tile instanceof TileDiskDrive)
{ {
TileDiskDrive drive = (TileDiskDrive)tile; TileDiskDrive drive = (TileDiskDrive) tile;
return getDiskDriveGUI( player.inventory, drive ); return getDiskDriveGUI( player.inventory, drive );
} }
break; break;
@ -575,9 +575,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.computerGUIID: case ComputerCraft.computerGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileComputer ) if (tile != null && tile instanceof TileComputer)
{ {
TileComputer computer = (TileComputer)tile; TileComputer computer = (TileComputer) tile;
return getComputerGUI( computer ); return getComputerGUI( computer );
} }
break; break;
@ -585,9 +585,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.printerGUIID: case ComputerCraft.printerGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePrinter ) if (tile != null && tile instanceof TilePrinter)
{ {
TilePrinter printer = (TilePrinter)tile; TilePrinter printer = (TilePrinter) tile;
return getPrinterGUI( player.inventory, printer ); return getPrinterGUI( player.inventory, printer );
} }
break; break;
@ -595,20 +595,20 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.turtleGUIID: case ComputerCraft.turtleGUIID:
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileTurtle ) if (tile != null && tile instanceof TileTurtle)
{ {
TileTurtle turtle = (TileTurtle)tile; TileTurtle turtle = (TileTurtle) tile;
return getTurtleGUI( player.inventory, turtle ); return getTurtleGUI( player.inventory, turtle );
} }
break; break;
} }
case ComputerCraft.printoutGUIID: case ComputerCraft.printoutGUIID:
{ {
return getPrintoutGUI( player.inventory ); return getPrintoutGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
} }
case ComputerCraft.pocketComputerGUIID: case ComputerCraft.pocketComputerGUIID:
{ {
return getPocketComputerGUI( player.inventory ); return getPocketComputerGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
} }
} }
return null; return null;
@ -631,7 +631,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
@SubscribeEvent @SubscribeEvent
public void onClientTick( TickEvent.ClientTickEvent event ) public void onClientTick( TickEvent.ClientTickEvent event )
{ {
if( event.phase == TickEvent.Phase.START ) if (event.phase == TickEvent.Phase.START)
{ {
ComputerCraft.clientComputerRegistry.update(); ComputerCraft.clientComputerRegistry.update();
} }
@ -640,7 +640,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
@SubscribeEvent @SubscribeEvent
public void onServerTick( TickEvent.ServerTickEvent event ) public void onServerTick( TickEvent.ServerTickEvent event )
{ {
if( event.phase == TickEvent.Phase.START ) if (event.phase == TickEvent.Phase.START)
{ {
MainThread.executePendingTasks(); MainThread.executePendingTasks();
ComputerCraft.serverComputerRegistry.update(); ComputerCraft.serverComputerRegistry.update();

View File

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

View File

@ -240,6 +240,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
placed = true; placed = true;
turtlePlayer.loadInventory( stackCopy ); turtlePlayer.loadInventory( stackCopy );
} }
else if( hitEntity.processInitialInteract( turtlePlayer, stackCopy, EnumHand.MAIN_HAND ) )
{
placed = true;
}
else if( hitEntity instanceof EntityLivingBase ) else if( hitEntity instanceof EntityLivingBase )
{ {
placed = item.itemInteractionForEntity( stackCopy, turtlePlayer, (EntityLivingBase)hitEntity, EnumHand.MAIN_HAND ); placed = item.itemInteractionForEntity( stackCopy, turtlePlayer, (EntityLivingBase)hitEntity, EnumHand.MAIN_HAND );