diff --git a/src/api/java/appeng/api/parts/IPart.java b/src/api/java/appeng/api/parts/IPart.java index ed496ae94..7e6f9819d 100644 --- a/src/api/java/appeng/api/parts/IPart.java +++ b/src/api/java/appeng/api/parts/IPart.java @@ -209,6 +209,7 @@ public interface IPart extends IBoxProvider, ICustomCableConnection * Called when you right click the part, very similar to Block.onActivateBlock * * @param player right clicking player + * @param hand hand used * @param pos position of block * * @return if your activate method performed something. @@ -219,12 +220,41 @@ public interface IPart extends IBoxProvider, ICustomCableConnection * Called when you right click the part, very similar to Block.onActivateBlock * * @param player shift right clicking player + * @param hand hand used * @param pos position of block * * @return if your activate method performed something, you should use false unless you really need it. */ boolean onShiftActivate( EntityPlayer player, EnumHand hand, Vec3d pos ); + /** + * Called when you left click the part, very similar to Block.onBlockClicked + * + * @param player left clicking player + * @param hand hand used + * @param pos position of block + * + * @return if your activate method performed something, you should use false unless you really need it. + */ + default boolean onClicked( EntityPlayer player, EnumHand hand, Vec3d pos ) + { + return false; + } + + /** + * Called when you shift-left click the part, very similar to Block.onBlockClicked + * + * @param player shift-left clicking player + * @param hand hand used + * @param pos position of block + * + * @return if your activate method performed something, you should use false unless you really need it. + */ + default boolean onShiftClicked( EntityPlayer player, EnumHand hand, Vec3d pos ) + { + return false; + } + /** * Add drops to the items being dropped into the world, if your item stores its contents when wrenched use the * wrenched boolean to control what data is saved vs dropped when it is broken. diff --git a/src/main/java/appeng/block/networking/BlockCableBus.java b/src/main/java/appeng/block/networking/BlockCableBus.java index ad0cfef9c..d537b82bc 100644 --- a/src/main/java/appeng/block/networking/BlockCableBus.java +++ b/src/main/java/appeng/block/networking/BlockCableBus.java @@ -49,6 +49,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -70,6 +71,8 @@ import appeng.client.render.cablebus.CableBusBakedModel; import appeng.client.render.cablebus.CableBusRenderState; import appeng.core.Api; import appeng.core.AppEng; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketClick; import appeng.helpers.AEGlassMaterial; import appeng.parts.ICableBusContainer; import appeng.parts.NullCableBusContainer; @@ -353,6 +356,31 @@ public class BlockCableBus extends AEBaseTileBlock return out == null ? NULL_CABLE_BUS : out; } + @Override + public void onBlockClicked( World worldIn, BlockPos pos, EntityPlayer playerIn ) + { + if( Platform.isClient() ) + { + final RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver; + if( rtr != null && rtr.typeOfHit == Type.BLOCK && pos.equals( rtr.getBlockPos() ) ) + { + final Vec3d hitVec = rtr.hitVec.subtract( new Vec3d( pos ) ); + + if( this.cb( worldIn, pos ).clicked( playerIn, EnumHand.MAIN_HAND, hitVec ) ) + { + NetworkHandler.instance() + .sendToServer( + new PacketClick( pos, rtr.sideHit, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, EnumHand.MAIN_HAND, true ) ); + } + } + } + } + + public void onBlockClickPacket( World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, Vec3d hitVec ) + { + this.cb( worldIn, pos ).clicked( playerIn, hand, hitVec ); + } + @Override public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ ) { diff --git a/src/main/java/appeng/core/sync/packets/PacketClick.java b/src/main/java/appeng/core/sync/packets/PacketClick.java index f305b4eb6..286f5cac8 100644 --- a/src/main/java/appeng/core/sync/packets/PacketClick.java +++ b/src/main/java/appeng/core/sync/packets/PacketClick.java @@ -22,17 +22,20 @@ package appeng.core.sync.packets; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import appeng.api.AEApi; import appeng.api.definitions.IComparableDefinition; import appeng.api.definitions.IItems; import appeng.api.implementations.items.IMemoryCard; import appeng.api.implementations.items.MemoryCardMessages; +import appeng.block.networking.BlockCableBus; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.items.tools.ToolNetworkTool; @@ -50,6 +53,7 @@ public class PacketClick extends AppEngPacket private final float hitY; private final float hitZ; private EnumHand hand; + private final boolean leftClick; // automatic. public PacketClick( final ByteBuf stream ) @@ -70,10 +74,16 @@ public class PacketClick extends AppEngPacket this.hitY = stream.readFloat(); this.hitZ = stream.readFloat(); this.hand = EnumHand.values()[stream.readByte()]; + this.leftClick = stream.readBoolean(); } // api public PacketClick( final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand ) + { + this( pos, side, hitX, hitY, hitZ, hand, false ); + } + + public PacketClick( final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand, boolean leftClick ) { final ByteBuf data = Unpooled.buffer(); @@ -94,6 +104,7 @@ public class PacketClick extends AppEngPacket data.writeFloat( this.hitY = hitY ); data.writeFloat( this.hitZ = hitZ ); data.writeByte( hand.ordinal() ); + data.writeBoolean( this.leftClick = leftClick ); this.configureWrite( data ); } @@ -105,27 +116,38 @@ public class PacketClick extends AppEngPacket final IItems items = AEApi.instance().definitions().items(); final IComparableDefinition maybeMemoryCard = items.memoryCard(); final IComparableDefinition maybeColorApplicator = items.colorApplicator(); - - if( !is.isEmpty() ) + final BlockPos pos = new BlockPos( this.x, this.y, this.z ); + if( this.leftClick ) { - if( is.getItem() instanceof ToolNetworkTool ) + final Block block = player.world.getBlockState( pos ).getBlock(); + if( block instanceof BlockCableBus ) { - final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); - tnt.serverSideToolLogic( is, player, this.hand, player.world, new BlockPos( this.x, this.y, this.z ), this.side, this.hitX, this.hitY, - this.hitZ ); + ( (BlockCableBus) block ).onBlockClickPacket( player.world, pos, player, this.hand, new Vec3d( this.hitX, this.hitY, this.hitZ ) ); } - - else if( maybeMemoryCard.isSameAs( is ) ) + } + else + { + if( !is.isEmpty() ) { - final IMemoryCard mem = (IMemoryCard) is.getItem(); - mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); - is.setTagCompound( null ); - } + if( is.getItem() instanceof ToolNetworkTool ) + { + final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); + tnt.serverSideToolLogic( is, player, this.hand, player.world, pos, this.side, this.hitX, this.hitY, + this.hitZ ); + } - else if( maybeColorApplicator.isSameAs( is ) ) - { - final ToolColorApplicator mem = (ToolColorApplicator) is.getItem(); - mem.cycleColors( is, mem.getColor( is ), 1 ); + else if( maybeMemoryCard.isSameAs( is ) ) + { + final IMemoryCard mem = (IMemoryCard) is.getItem(); + mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); + is.setTagCompound( null ); + } + + else if( maybeColorApplicator.isSameAs( is ) ) + { + final ToolColorApplicator mem = (ToolColorApplicator) is.getItem(); + mem.cycleColors( is, mem.getColor( is ), 1 ); + } } } } diff --git a/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java b/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java index 82ea87e00..3a9be31de 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java +++ b/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java @@ -185,18 +185,12 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane inv = this.getProxy().getStorage().getInventory( - AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + final IMEMonitor inv = this.getProxy() + .getStorage() + .getInventory( + AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); final IEnergyGrid energy = this.getProxy().getEnergy(); final ICraftingGrid cg = this.getProxy().getCrafting(); final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ); @@ -215,18 +217,11 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS ); - return true; } - - return false; + return true; } @Override diff --git a/src/main/java/appeng/parts/automation/PartFormationPlane.java b/src/main/java/appeng/parts/automation/PartFormationPlane.java index a8896f269..d48096176 100644 --- a/src/main/java/appeng/parts/automation/PartFormationPlane.java +++ b/src/main/java/appeng/parts/automation/PartFormationPlane.java @@ -196,18 +196,11 @@ public class PartFormationPlane extends PartAbstractFormationPlane @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE ); - return true; } - - return false; + return true; } @Override diff --git a/src/main/java/appeng/parts/automation/PartImportBus.java b/src/main/java/appeng/parts/automation/PartImportBus.java index d6663edab..09b039bcf 100644 --- a/src/main/java/appeng/parts/automation/PartImportBus.java +++ b/src/main/java/appeng/parts/automation/PartImportBus.java @@ -93,8 +93,10 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin try { - final IMEMonitor inv = this.getProxy().getStorage().getInventory( - AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + final IMEMonitor inv = this.getProxy() + .getStorage() + .getInventory( + AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); final IAEItemStack out = inv.injectItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( stack ), Actionable.SIMULATE, @@ -128,18 +130,11 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS ); - return true; } - - return false; + return true; } @Override @@ -173,8 +168,10 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin { this.itemsToSend = this.calculateItemsToSend(); - final IMEMonitor inv = this.getProxy().getStorage().getInventory( - AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + final IMEMonitor inv = this.getProxy() + .getStorage() + .getInventory( + AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); final IEnergyGrid energy = this.getProxy().getEnergy(); boolean Configured = false; diff --git a/src/main/java/appeng/parts/automation/PartLevelEmitter.java b/src/main/java/appeng/parts/automation/PartLevelEmitter.java index 495f9b04e..6ee2892e0 100644 --- a/src/main/java/appeng/parts/automation/PartLevelEmitter.java +++ b/src/main/java/appeng/parts/automation/PartLevelEmitter.java @@ -465,18 +465,11 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER ); - return true; } - - return false; + return true; } @Override diff --git a/src/main/java/appeng/parts/misc/PartInterface.java b/src/main/java/appeng/parts/misc/PartInterface.java index 42fe733a7..75b3c192a 100644 --- a/src/main/java/appeng/parts/misc/PartInterface.java +++ b/src/main/java/appeng/parts/misc/PartInterface.java @@ -174,16 +174,10 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto @Override public boolean onPartActivate( final EntityPlayer p, final EnumHand hand, final Vec3d pos ) { - if( p.isSneaking() ) - { - return false; - } - if( Platform.isServer() ) { Platform.openGUI( p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_INTERFACE ); } - return true; } @@ -311,7 +305,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto { return this.duality.getCapability( capabilityClass, this.getSide().getFacing() ); } - + @Override public ItemStack getItemStackRepresentation() { diff --git a/src/main/java/appeng/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java index 93b1406ac..f3719f12e 100644 --- a/src/main/java/appeng/parts/misc/PartStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartStorageBus.java @@ -256,8 +256,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC { if( this.getProxy().isActive() ) { - this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, - this.mySrc ); + this.getProxy() + .getStorage() + .postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, + this.mySrc ); } } catch( final GridAccessException e ) @@ -298,18 +300,11 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_STORAGEBUS ); - return true; } - - return false; + return true; } @Override @@ -625,7 +620,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC return MODELS_OFF; } } - + @Override public ItemStack getItemStackRepresentation() { diff --git a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java index 630cd7568..e93484e16 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java +++ b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java @@ -160,6 +160,11 @@ public abstract class PartP2PTunnel extends PartBasicSt @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { + if( Platform.isClient() ) + { + return true; + } + if( hand == EnumHand.OFF_HAND ) { return false; @@ -305,6 +310,11 @@ public abstract class PartP2PTunnel extends PartBasicSt final ItemStack is = player.inventory.getCurrentItem(); if( !is.isEmpty() && is.getItem() instanceof IMemoryCard ) { + if( Platform.isClient() ) + { + return true; + } + final IMemoryCard mc = (IMemoryCard) is.getItem(); final NBTTagCompound data = new NBTTagCompound(); diff --git a/src/main/java/appeng/parts/reporting/AbstractPartMonitor.java b/src/main/java/appeng/parts/reporting/AbstractPartMonitor.java index a7de0f4a5..86f962c37 100644 --- a/src/main/java/appeng/parts/reporting/AbstractPartMonitor.java +++ b/src/main/java/appeng/parts/reporting/AbstractPartMonitor.java @@ -27,7 +27,6 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.RayTraceResult; @@ -163,24 +162,46 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements return false; } - final TileEntity te = this.getTile(); - final ItemStack eq = player.getHeldItem( hand ); - - if( Platform.isWrench( player, eq, te.getPos() ) ) - { - this.isLocked = !this.isLocked; - player.sendMessage( ( this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked ).get() ); - this.getHost().markForUpdate(); - } - else if( !this.isLocked ) + if( !this.isLocked ) { + final ItemStack eq = player.getHeldItem( hand ); this.configuredItem = AEItemStack.fromItemStack( eq ); this.configureWatchers(); + this.getHost().markForSave(); this.getHost().markForUpdate(); } else { - this.extractItem( player ); + return super.onPartActivate( player, hand, pos ); + } + + return true; + } + + @Override + public boolean onPartShiftActivate( EntityPlayer player, EnumHand hand, Vec3d pos ) + { + if( Platform.isClient() ) + { + return true; + } + + if( !this.getProxy().isActive() ) + { + return false; + } + + if( !Platform.hasPermissions( this.getLocation(), player ) ) + { + return false; + } + + if( player.getHeldItem( hand ).isEmpty() ) + { + this.isLocked = !this.isLocked; + player.sendMessage( ( this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked ).get() ); + this.getHost().markForSave(); + this.getHost().markForUpdate(); } return true; @@ -213,11 +234,6 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements } } - protected void extractItem( final EntityPlayer player ) - { - - } - private void updateReportingValue( final IMEMonitor itemInventory ) { if( this.configuredItem != null ) @@ -271,7 +287,7 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements } @Override - public IAEStack getDisplayed() + public IAEItemStack getDisplayed() { return this.configuredItem; } diff --git a/src/main/java/appeng/parts/reporting/AbstractPartReporting.java b/src/main/java/appeng/parts/reporting/AbstractPartReporting.java index dcef800de..dfb4bbbcb 100644 --- a/src/main/java/appeng/parts/reporting/AbstractPartReporting.java +++ b/src/main/java/appeng/parts/reporting/AbstractPartReporting.java @@ -199,7 +199,7 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM { final TileEntity te = this.getTile(); - if( !player.isSneaking() && Platform.isWrench( player, player.inventory.getCurrentItem(), te.getPos() ) ) + if( Platform.isWrench( player, player.inventory.getCurrentItem(), te.getPos() ) ) { if( Platform.isServer() ) { diff --git a/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java b/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java index 7a209d8cf..be4a62408 100644 --- a/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java +++ b/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java @@ -115,19 +115,12 @@ public abstract class AbstractPartTerminal extends AbstractPartDisplay implement { if( !super.onPartActivate( player, hand, pos ) ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), this.getGui( player ) ); - - return true; } } - return false; + return true; } public GuiBridge getGui( final EntityPlayer player ) diff --git a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java index f858cc0d2..3695c6d44 100644 --- a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java +++ b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java @@ -28,6 +28,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; import appeng.api.AEApi; import appeng.api.networking.energy.IEnergySource; @@ -72,7 +74,7 @@ public class PartConversionMonitor extends AbstractPartMonitor } @Override - public boolean onPartShiftActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) + public boolean onPartActivate( EntityPlayer player, EnumHand hand, Vec3d pos ) { if( Platform.isClient() ) { @@ -89,62 +91,133 @@ public class PartConversionMonitor extends AbstractPartMonitor return false; } - boolean ModeB = false; - - ItemStack item = player.getHeldItem( hand ); - if( item.isEmpty() && this.getDisplayed() != null ) + final ItemStack eq = player.getHeldItem( hand ); + if( this.isLocked() ) { - ModeB = true; - item = ( (IAEItemStack) this.getDisplayed() ).createItemStack(); - } - - if( !item.isEmpty() ) - { - try + if( eq.isEmpty() ) { - if( !this.getProxy().isActive() ) - { - return false; - } - - final IEnergySource energy = this.getProxy().getEnergy(); - final IMEMonitor cell = this.getProxy().getStorage().getInventory( - AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); - final IAEItemStack input = AEItemStack.fromItemStack( item ); - - if( ModeB ) - { - for( int x = 0; x < player.inventory.getSizeInventory(); x++ ) - { - final ItemStack targetStack = player.inventory.getStackInSlot( x ); - if( input.equals( targetStack ) ) - { - final IAEItemStack insertItem = input.copy(); - insertItem.setStackSize( targetStack.getCount() ); - final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, insertItem, new PlayerSource( player, this ) ); - player.inventory.setInventorySlotContents( x, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() ); - } - } - } - else - { - final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) ); - player.inventory.setInventorySlotContents( player.inventory.currentItem, - failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() ); - } + this.insertItem( player, hand, true ); } - catch( final GridAccessException e ) + else if( Platform.isWrench( player, eq, this.getLocation().getPos() ) && ( this.getDisplayed() == null || !this.getDisplayed().equals( eq ) ) ) { - // :P + // wrench it + return super.onPartActivate( player, hand, pos ); + } + else + { + this.insertItem( player, hand, false ); } } + else if( this.getDisplayed() != null && this.getDisplayed().equals( eq ) ) + { + this.insertItem( player, hand, false ); + } + else + { + return super.onPartActivate( player, hand, pos ); + } + return true; } @Override - protected void extractItem( final EntityPlayer player ) + public boolean onClicked( EntityPlayer player, EnumHand hand, Vec3d pos ) { - final IAEItemStack input = (IAEItemStack) this.getDisplayed(); + if( Platform.isClient() ) + { + return true; + } + + if( !this.getProxy().isActive() ) + { + return false; + } + + if( !Platform.hasPermissions( this.getLocation(), player ) ) + { + return false; + } + + if( this.getDisplayed() != null ) + { + this.extractItem( player, this.getDisplayed().getDefinition().getMaxStackSize() ); + } + + return true; + } + + @Override + public boolean onShiftClicked( EntityPlayer player, EnumHand hand, Vec3d pos ) + { + if( Platform.isClient() ) + { + return true; + } + + if( !this.getProxy().isActive() ) + { + return false; + } + + if( !Platform.hasPermissions( this.getLocation(), player ) ) + { + return false; + } + + if( this.getDisplayed() != null ) + { + this.extractItem( player, 1 ); + } + + return true; + } + + private void insertItem( final EntityPlayer player, final EnumHand hand, final boolean allItems ) + { + try + { + final IEnergySource energy = this.getProxy().getEnergy(); + final IMEMonitor cell = this.getProxy() + .getStorage() + .getInventory( + AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + if( allItems ) + { + final IAEItemStack input = this.getDisplayed().copy(); + IItemHandler inv = new PlayerMainInvWrapper( player.inventory ); + + for( int x = 0; x < inv.getSlots(); x++ ) + { + final ItemStack targetStack = inv.getStackInSlot( x ); + if( input.equals( targetStack ) ) + { + final ItemStack canExtract = inv.extractItem( x, targetStack.getCount(), true ); + if( !canExtract.isEmpty() ) + { + input.setStackSize( canExtract.getCount() ); + final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) ); + inv.extractItem( x, failedToInsert == null ? canExtract.getCount() : canExtract.getCount() - (int) failedToInsert.getStackSize(), + false ); + } + } + } + } + else + { + final IAEItemStack input = AEItemStack.fromItemStack( player.getHeldItem( hand ) ); + final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) ); + player.setHeldItem( hand, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() ); + } + } + catch( final GridAccessException e ) + { + // :P + } + } + + private void extractItem( final EntityPlayer player, int count ) + { + final IAEItemStack input = this.getDisplayed(); if( input != null ) { try @@ -155,11 +228,12 @@ public class PartConversionMonitor extends AbstractPartMonitor } final IEnergySource energy = this.getProxy().getEnergy(); - final IMEMonitor cell = this.getProxy().getStorage().getInventory( - AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); + final IMEMonitor cell = this.getProxy() + .getStorage() + .getInventory( + AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); - final ItemStack is = input.createItemStack(); - input.setStackSize( is.getMaxStackSize() ); + input.setStackSize( count ); final IAEItemStack retrieved = Platform.poweredExtraction( energy, cell, input, new PlayerSource( player, this ) ); if( retrieved != null ) diff --git a/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java b/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java index b381005b7..e5ef4911f 100644 --- a/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java +++ b/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java @@ -55,20 +55,12 @@ public class PartInterfaceTerminal extends AbstractPartDisplay { if( !super.onPartActivate( player, hand, pos ) ) { - if( !player.isSneaking() ) + if( Platform.isServer() ) { - if( Platform.isClient() ) - { - return true; - } - Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_TERMINAL ); - - return true; } } - - return false; + return true; } @Override