diff --git a/block/AEBaseItemBlock.java b/block/AEBaseItemBlock.java index 352144c57..2d0294316 100644 --- a/block/AEBaseItemBlock.java +++ b/block/AEBaseItemBlock.java @@ -12,6 +12,7 @@ import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.ForgeDirection; import appeng.api.util.IOrientable; import appeng.api.util.IOrientableBlock; +import appeng.block.networking.BlockWireless; import appeng.client.render.ItemRenderer; import appeng.me.helpers.IGridProxyable; import appeng.tile.AEBaseTile; @@ -47,36 +48,47 @@ public class AEBaseItemBlock extends ItemBlock if ( blockType.hasBlockTileEntity() ) { - up = ForgeDirection.UP; - - byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3); - - switch (rotation) + if ( blockType instanceof BlockWireless ) { - default: - case 0: - forward = ForgeDirection.SOUTH; - break; - case 1: - forward = ForgeDirection.WEST; - break; - case 2: - forward = ForgeDirection.NORTH; - break; - case 3: - forward = ForgeDirection.EAST; - break; + forward = ForgeDirection.getOrientation( side ); + if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN ) + up = ForgeDirection.SOUTH; + else + up = ForgeDirection.UP; } + else + { + up = ForgeDirection.UP; - if ( player.rotationPitch > 65 ) - { - up = forward.getOpposite(); - forward = ForgeDirection.UP; - } - else if ( player.rotationPitch < -65 ) - { - up = forward.getOpposite(); - forward = ForgeDirection.DOWN; + byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3); + + switch (rotation) + { + default: + case 0: + forward = ForgeDirection.SOUTH; + break; + case 1: + forward = ForgeDirection.WEST; + break; + case 2: + forward = ForgeDirection.NORTH; + break; + case 3: + forward = ForgeDirection.EAST; + break; + } + + if ( player.rotationPitch > 65 ) + { + up = forward.getOpposite(); + forward = ForgeDirection.UP; + } + else if ( player.rotationPitch < -65 ) + { + up = forward.getOpposite(); + forward = ForgeDirection.DOWN; + } } } diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index 41a1e9969..8c329467d 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -123,7 +123,8 @@ public class GuiMEMonitorable extends AEBaseMEGui { if ( s instanceof AppEngSlot ) { - ((AppEngSlot) s).yDisplayPosition = ((AppEngSlot) s).defY + ySize - 78 - 4; + if ( ((AppEngSlot) s).xDisplayPosition < 197 ) + ((AppEngSlot) s).yDisplayPosition = ((AppEngSlot) s).defY + ySize - 78 - 4; } } } @@ -163,13 +164,16 @@ public class GuiMEMonitorable extends AEBaseMEGui @Override public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + int x_width = 197; + bindTexture( getBackground() ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, 18 ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 ); + this.drawTexturedModalRect( offsetX + x_width, offsetY, x_width, 0, 46, 128 ); for (int x = 0; x < rows; x++) - this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, xSize, 18 ); + this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 ); - this.drawTexturedModalRect( offsetX, offsetY + 16 + rows * 18, 0, 106, xSize, 98 + reservedSpace ); + this.drawTexturedModalRect( offsetX, offsetY + 16 + rows * 18, 0, 106, x_width, 98 + reservedSpace ); searchField.drawTextBox(); } diff --git a/client/gui/implementations/GuiSecurity.java b/client/gui/implementations/GuiSecurity.java index d2c24df14..1f1a84d44 100644 --- a/client/gui/implementations/GuiSecurity.java +++ b/client/gui/implementations/GuiSecurity.java @@ -17,6 +17,7 @@ public class GuiSecurity extends GuiMEMonitorable public GuiSecurity(InventoryPlayer inventoryPlayer, IStorageMonitorable te) { super( inventoryPlayer, te, new ContainerSecurity( inventoryPlayer, te ) ); reservedSpace = 32; + xSize += 50; } GuiToggleButton inject, extract, craft, build, security; diff --git a/container/implementations/ContainerMEPortableCell.java b/container/implementations/ContainerMEPortableCell.java index 7ffd118c8..f741792ed 100644 --- a/container/implementations/ContainerMEPortableCell.java +++ b/container/implementations/ContainerMEPortableCell.java @@ -11,6 +11,7 @@ import appeng.util.Platform; public class ContainerMEPortableCell extends ContainerMEMonitorable { + double powerMultiplier = 0.5; IPortableCell civ; public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell montiorable) { @@ -49,7 +50,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable ticks++; if ( ticks > 10 ) { - civ.extractAEPower( 0.5 * (double) ticks, Actionable.MODULATE, PowerMultiplier.CONFIG ); + civ.extractAEPower( powerMultiplier * (double) ticks, Actionable.MODULATE, PowerMultiplier.CONFIG ); ticks = 0; } super.detectAndSendChanges(); diff --git a/container/implementations/ContainerSecurity.java b/container/implementations/ContainerSecurity.java index 52a4f5480..1434426d1 100644 --- a/container/implementations/ContainerSecurity.java +++ b/container/implementations/ContainerSecurity.java @@ -1,31 +1,62 @@ package appeng.container.implementations; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; +import appeng.api.features.IWirelessTermHandler; import appeng.api.implementations.items.IBiometricCard; import appeng.api.storage.IStorageMonitorable; -import appeng.container.slot.SlotNormal; +import appeng.container.slot.SlotOutput; +import appeng.container.slot.SlotRestrictedInput; +import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.IAEAppEngInventory; +import appeng.tile.inventory.InvOperation; import appeng.tile.misc.TileSecurity; import appeng.util.Platform; -public class ContainerSecurity extends ContainerMEMonitorable +public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppEngInventory { - SlotNormal configSlot; + SlotRestrictedInput configSlot; + + AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory( this, 2 ); + + SlotRestrictedInput wirelessIn; + SlotOutput wirelessOut; + + TileSecurity securityBox; public ContainerSecurity(InventoryPlayer ip, IStorageMonitorable montiorable) { super( ip, montiorable, false ); - addSlotToContainer( configSlot = new SlotNormal( ((TileSecurity) montiorable).configSlot, 0, 37, -32 ) ); + securityBox = (TileSecurity) montiorable; + + addSlotToContainer( configSlot = new SlotRestrictedInput( PlaceableItemType.BIOMETRIC_CARD, securityBox.configSlot, 0, 37, -32 ) ); + + addSlotToContainer( wirelessIn = new SlotRestrictedInput( PlaceableItemType.WIRELESS_TERMINAL, wirelessEncoder, 0, 212, 10 ) ); + addSlotToContainer( wirelessOut = new SlotOutput( wirelessEncoder, 1, 212, 68, -1 ) ); bindPlayerInventory( ip, 0, 0 ); } public int security = 0; + @Override + public void onContainerClosed(EntityPlayer player) + { + if ( wirelessIn.getHasStack() ) + player.dropPlayerItem( wirelessIn.getStack() ); + + if ( wirelessOut.getHasStack() ) + player.dropPlayerItem( wirelessOut.getStack() ); + } + public void toggleSetting(String value, EntityPlayer player) { try @@ -89,4 +120,39 @@ public class ContainerSecurity extends ContainerMEMonitorable super.detectAndSendChanges(); } + @Override + public void saveChanges() + { + // :P + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) + { + if ( !wirelessOut.getHasStack() ) + { + if ( wirelessIn.getHasStack() ) + { + ItemStack term = wirelessIn.getStack().copy(); + IWirelessTermHandler h = AEApi.instance().registries().wireless().getWirelessTerminalHandler( term ); + + if ( h != null ) + { + h.setEncryptionKey( term, "" + securityBox.securityKey, "" ); + + wirelessIn.putStack( null ); + wirelessOut.putStack( term ); + + // update the two slots in question... + for (int i = 0; i < this.crafters.size(); ++i) + { + ICrafting icrafting = (ICrafting) this.crafters.get( i ); + ((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() ); + ((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() ); + } + } + + } + } + } } diff --git a/container/slot/SlotRestrictedInput.java b/container/slot/SlotRestrictedInput.java index 623c45b11..9a68661f8 100644 --- a/container/slot/SlotRestrictedInput.java +++ b/container/slot/SlotRestrictedInput.java @@ -9,6 +9,7 @@ import appeng.api.AEApi; import appeng.api.IAppEngApi; import appeng.api.crafting.ICraftingPatternMAC; import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.implementations.items.IBiometricCard; import appeng.api.implementations.items.ISpatialStorageCell; import appeng.api.implementations.items.IStorageComponent; import appeng.api.implementations.items.IUpgradeModule; @@ -23,7 +24,8 @@ public class SlotRestrictedInput extends AppEngSlot { STORAGE_CELLS(15), ORE(1 * 16 + 15), STORAGE_COMPONENT(3 * 16 + 15), WIRELESS_TERMINAL(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUPUT( 7 * 16 + 15), ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15), RANGE_BOOSTER( - 6 * 16 + 15), QE_SINGULARTIY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15), FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15), WORKBENCH_CELL(15); + 6 * 16 + 15), QE_SINGULARTIY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15), FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15), WORKBENCH_CELL(15), BIOMETRIC_CARD( + 14 * 16 + 15); public final int icon; @@ -141,6 +143,8 @@ public class SlotRestrictedInput extends AppEngSlot return true; case WIRELESS_TERMINAL: return AEApi.instance().registries().wireless().isWirelessTerminal( i ); + case BIOMETRIC_CARD: + return i.getItem() instanceof IBiometricCard; case UPGRADES: return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType( i ) != null; default: diff --git a/core/Registration.java b/core/Registration.java index 69a8fb27e..7d117c500 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -14,6 +14,7 @@ import appeng.api.definitions.Blocks; import appeng.api.definitions.Items; import appeng.api.definitions.Materials; import appeng.api.definitions.Parts; +import appeng.api.features.IWirelessTermHandler; import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.pathing.IPathingGrid; import appeng.api.networking.security.ISecurityGrid; @@ -38,6 +39,7 @@ import appeng.block.networking.BlockCreativeEnergyCell; import appeng.block.networking.BlockDenseEnergyCell; import appeng.block.networking.BlockEnergyAcceptor; import appeng.block.networking.BlockEnergyCell; +import appeng.block.networking.BlockWireless; import appeng.block.qnb.BlockQuantumLinkChamber; import appeng.block.qnb.BlockQuantumRing; import appeng.block.solids.BlockFluix; @@ -89,6 +91,7 @@ import appeng.items.tools.powered.ToolChargedStaff; import appeng.items.tools.powered.ToolEntropyManipulator; import appeng.items.tools.powered.ToolMassCannon; import appeng.items.tools.powered.ToolPortableCell; +import appeng.items.tools.powered.ToolWirelessTerminal; import appeng.items.tools.quartz.ToolQuartzAxe; import appeng.items.tools.quartz.ToolQuartzCuttingKnife; import appeng.items.tools.quartz.ToolQuartzHoe; @@ -220,7 +223,7 @@ public class Registration blocks.blockGrindStone = addFeature( BlockGrinder.class ); blocks.blockCrankHandle = addFeature( BlockCrank.class ); // blocks.blockInscriber = addFeature( BlockInscriber.class ); - // blocks.blockWireless = addFeature( BlockWireless.class ); + blocks.blockWireless = addFeature( BlockWireless.class ); blocks.blockTinyTNT = addFeature( BlockTinyTNT.class ); // blocks.blockQuartzCrystalizer = addFeature( BlockQuartzCrystalizer.class ); @@ -286,7 +289,7 @@ public class Registration items.itemMemoryCard = addFeature( ToolMemoryCard.class ); items.itemChargedStaff = addFeature( ToolChargedStaff.class ); items.itemEntropyManipulator = addFeature( ToolEntropyManipulator.class ); - // items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class ); + items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class ); items.itemNetworkTool = addFeature( ToolNetworkTool.class ); items.itemPortableCell = addFeature( ToolPortableCell.class ); items.itemBiometricCard = addFeature( ToolBiometricCard.class ); @@ -477,6 +480,8 @@ public class Registration Upgrades.INVERTER.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 ); Upgrades.SPEED.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 4 ); + AEApi.instance().registries().wireless().registerWirelessHandler( (IWirelessTermHandler) AEApi.instance().items().itemWirelessTerminal.item() ); + if ( Configuration.instance.isFeatureEnabled( AEFeature.ChestLoot ) ) { ChestGenHooks d = ChestGenHooks.getInfo( ChestGenHooks.MINESHAFT_CORRIDOR ); diff --git a/core/WorldSettings.java b/core/WorldSettings.java index ca64cc682..bac599e02 100644 --- a/core/WorldSettings.java +++ b/core/WorldSettings.java @@ -168,7 +168,7 @@ public class WorldSettings extends Configuration public int getPlayerID(String username) { ConfigCategory playerList = this.getCategory( "players" ); - if ( playerList == null ) + if ( playerList == null || username == null || username.length() == 0 ) return -1; Property prop = playerList.get( username ); diff --git a/core/features/registries/WirelessRegistry.java b/core/features/registries/WirelessRegistry.java index 82d59e621..431a99640 100644 --- a/core/features/registries/WirelessRegistry.java +++ b/core/features/registries/WirelessRegistry.java @@ -23,7 +23,8 @@ public class WirelessRegistry implements IWirelessTermRegistery @Override public void registerWirelessHandler(IWirelessTermHandler handler) { - handlers.add( handler ); + if ( handler != null ) + handlers.add( handler ); } @Override diff --git a/items/tools/powered/ToolWirelessTerminal.java b/items/tools/powered/ToolWirelessTerminal.java index fbe8dcd89..399c27c02 100644 --- a/items/tools/powered/ToolWirelessTerminal.java +++ b/items/tools/powered/ToolWirelessTerminal.java @@ -9,12 +9,14 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import appeng.api.AEApi; +import appeng.api.features.IWirelessTermHandler; import appeng.core.features.AEFeature; import appeng.core.localization.GuiText; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.Platform; +import cpw.mods.fml.common.network.Player; -public class ToolWirelessTerminal extends AEBasePoweredItem +public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler { String name; @@ -35,12 +37,14 @@ public class ToolWirelessTerminal extends AEBasePoweredItem @Override public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b) { + super.addInformation( i, p, l, b ); + if ( i.hasTagCompound() ) { NBTTagCompound tag = Platform.openNbtData( i ); if ( tag != null ) { - String encKey = tag.getString( "encKey" ); + String encKey = tag.getString( "encryptionKey" ); if ( encKey == null || encKey == "" ) l.add( GuiText.Unlinked.getLocal() ); @@ -52,4 +56,37 @@ public class ToolWirelessTerminal extends AEBasePoweredItem l.add( StatCollector.translateToLocal( "AppEng.GuiITooltip.Unlinked" ) ); } + @Override + public boolean canHandle(ItemStack is) + { + return AEApi.instance().items().itemWirelessTerminal.sameAs( is ); + } + + @Override + public boolean usePower(Player player, float amount, ItemStack is) + { + return this.extractAEPower( is, amount ) >= amount - 0.5; + } + + @Override + public boolean hasPower(Player player, ItemStack is) + { + return getAECurrentPower( is ) > 0.5; + } + + @Override + public String getEncryptionKey(ItemStack item) + { + NBTTagCompound tag = Platform.openNbtData( item ); + return tag.getString( "encryptionKey" ); + } + + @Override + public void setEncryptionKey(ItemStack item, String encKey, String name) + { + NBTTagCompound tag = Platform.openNbtData( item ); + tag.setString( "encryptionKey", encKey ); + tag.setString( "name", name ); + } + } diff --git a/tile/misc/TileSecurity.java b/tile/misc/TileSecurity.java index 3a863b411..5704a846c 100644 --- a/tile/misc/TileSecurity.java +++ b/tile/misc/TileSecurity.java @@ -13,8 +13,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.common.MinecraftForge; import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; +import appeng.api.events.LocatableEventAnnounce; +import appeng.api.events.LocatableEventAnnounce.LocatableEvent; +import appeng.api.features.ILocatable; import appeng.api.features.IPlayerRegistry; import appeng.api.implementations.items.IBiometricCard; import appeng.api.networking.GridFlags; @@ -41,7 +45,7 @@ import appeng.tile.inventory.InvOperation; import appeng.util.Platform; import appeng.util.item.AEItemStack; -public class TileSecurity extends AENetworkTile implements IStorageMonitorable, IAEAppEngInventory +public class TileSecurity extends AENetworkTile implements IStorageMonitorable, IAEAppEngInventory, ILocatable { private static int diffrence = 0; @@ -64,6 +68,9 @@ public class TileSecurity extends AENetworkTile implements IStorageMonitorable, @Override public void getDrops(World w, int x, int y, int z, ArrayList drops) { + if ( !configSlot.isEmpty() ) + drops.add( configSlot.getStackInSlot( 0 ) ); + for (IAEItemStack ais : inventory.storedItems) drops.add( ais.getItemStack() ); } @@ -78,13 +85,17 @@ public class TileSecurity extends AENetworkTile implements IStorageMonitorable, { super.onReady(); if ( Platform.isServer() ) + { isActive = true; + MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Register ) ); + } } @Override public void onChunkUnload() { super.onChunkUnload(); + MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) ); isActive = false; } @@ -92,6 +103,7 @@ public class TileSecurity extends AENetworkTile implements IStorageMonitorable, public void invalidate() { super.invalidate(); + MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) ); isActive = false; } @@ -252,4 +264,10 @@ public class TileSecurity extends AENetworkTile implements IStorageMonitorable, return null; } + @Override + public long getLocatableSerial() + { + return securityKey; + } + } diff --git a/tile/networking/TileWireless.java b/tile/networking/TileWireless.java index 8a5068a6e..4815dbe60 100644 --- a/tile/networking/TileWireless.java +++ b/tile/networking/TileWireless.java @@ -3,6 +3,7 @@ package appeng.tile.networking; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.EnumSet; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -34,9 +35,17 @@ public class TileWireless extends AENetworkInvTile public TileWireless() { gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); + gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); addNewHandler( new TileWirelessHandler() ); } + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + gridProxy.setValidSides( EnumSet.of( getForward().getOpposite() ) ); + } + @MENetworkEventSubscribe public void chanRender(MENetworkChannelsChanged c) {