From db4cf7aa5d81f69a489fc61c805fbb0f8f7bc51f Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 1 Jan 2014 23:51:41 -0600 Subject: [PATCH] Redstone Logic for Buses, and Part Image Button goodness --- client/gui/implementations/GuiBus.java | 54 +++++++++ client/gui/implementations/GuiInterface.java | 4 +- client/gui/widgets/GuiImgButton.java | 22 +++- container/AEBaseContainer.java | 17 ++- container/implementations/ContainerBus.java | 46 +++++++- container/implementations/ContainerChest.java | 2 +- .../implementations/ContainerCondenser.java | 2 +- container/implementations/ContainerDrive.java | 2 +- .../implementations/ContainerGrinder.java | 2 +- .../implementations/ContainerInterface.java | 6 +- .../ContainerLevelEmitter.java | 2 +- .../ContainerMEMonitorable.java | 3 +- .../ContainerNetworkStatus.java | 2 +- .../ContainerSpatialIOPort.java | 2 +- .../ContainerVibrationChamber.java | 2 +- .../entries/CreativeCellHandler.java | 6 +- core/sync/packets/PacketConfigButton.java | 6 +- helpers/TickHandler.java | 6 +- parts/automation/PartExportBus.java | 47 ++++++-- parts/automation/PartImportBus.java | 111 +++++++++++++++--- parts/automation/PartSharedItemBus.java | 44 +++++-- parts/automation/PartUpgradeable.java | 52 +++++++- 22 files changed, 367 insertions(+), 73 deletions(-) diff --git a/client/gui/implementations/GuiBus.java b/client/gui/implementations/GuiBus.java index 278cea76..d1b14aae 100644 --- a/client/gui/implementations/GuiBus.java +++ b/client/gui/implementations/GuiBus.java @@ -1,24 +1,72 @@ package appeng.client.gui.implementations; +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; +import appeng.api.config.FuzzyMode; +import appeng.api.config.RedstoneMode; +import appeng.api.config.Settings; +import appeng.api.config.Upgrades; import appeng.api.implementations.IBusCommon; import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiImgButton; import appeng.container.implementations.ContainerBus; import appeng.core.localization.GuiText; +import appeng.core.sync.packets.PacketConfigButton; import appeng.parts.automation.PartImportBus; +import cpw.mods.fml.common.network.PacketDispatcher; public class GuiBus extends AEBaseGui { + ContainerBus cvb; IBusCommon bc; + GuiImgButton redstoneMode; + GuiImgButton fuzzyMode; + public GuiBus(InventoryPlayer inventoryPlayer, IBusCommon te) { super( new ContainerBus( inventoryPlayer, te ) ); + cvb = (ContainerBus) inventorySlots; + bc = te; this.xSize = hasToolbox() ? 246 : 211; this.ySize = 184; } + @Override + public void initGui() + { + super.initGui(); + + redstoneMode = new GuiImgButton( 122 + guiLeft, 31 + guiTop, Settings.REDSTONE_OUTPUT, RedstoneMode.IGNORE ); + fuzzyMode = new GuiImgButton( 122 + guiLeft, 49 + guiTop, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + + buttonList.add( redstoneMode ); + buttonList.add( fuzzyMode ); + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + try + { + if ( btn == redstoneMode ) + PacketDispatcher.sendPacketToServer( (new PacketConfigButton( Settings.REDSTONE_OUTPUT )).getPacket() ); + + if ( btn == fuzzyMode ) + PacketDispatcher.sendPacketToServer( (new PacketConfigButton( Settings.FUZZY_MODE )).getPacket() ); + + } + catch (IOException e) + { + e.printStackTrace(); + } + } + private boolean hasToolbox() { return ((ContainerBus) inventorySlots).hasToolbox(); @@ -27,6 +75,9 @@ public class GuiBus extends AEBaseGui @Override public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + redstoneMode.setVisibility( bc.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 ); + fuzzyMode.setVisibility( bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 ); + bindTexture( "guis/bus.png" ); this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize - 34, ySize ); this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 86 ); @@ -39,6 +90,9 @@ public class GuiBus extends AEBaseGui { fontRenderer.drawString( (bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus).getLocal(), 8, 6, 4210752 ); fontRenderer.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + + redstoneMode.set( cvb.rsMode ); + fuzzyMode.set( cvb.fzMode ); } } diff --git a/client/gui/implementations/GuiInterface.java b/client/gui/implementations/GuiInterface.java index d72c654b..d34c0a82 100644 --- a/client/gui/implementations/GuiInterface.java +++ b/client/gui/implementations/GuiInterface.java @@ -26,8 +26,8 @@ public class GuiInterface extends AEBaseGui { fontRenderer.drawString( GuiText.Interface.getLocal(), 8, 6, 4210752 ); - fontRenderer.drawString( GuiText.Config.getLocal(), 8, 6 + 11 + 7, 4210752 ); - fontRenderer.drawString( GuiText.StoredItems.getLocal(), 8 + 18, 6 + 60 + 7, 4210752 ); + fontRenderer.drawString( GuiText.Config.getLocal(), 18, 6 + 11 + 7, 4210752 ); + fontRenderer.drawString( GuiText.StoredItems.getLocal(), 18, 6 + 60 + 7, 4210752 ); fontRenderer.drawString( GuiText.Patterns.getLocal(), 8, 6 + 73 + 7, 4210752 ); fontRenderer.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); diff --git a/client/gui/widgets/GuiImgButton.java b/client/gui/widgets/GuiImgButton.java index a260e488..e8dc44ea 100644 --- a/client/gui/widgets/GuiImgButton.java +++ b/client/gui/widgets/GuiImgButton.java @@ -82,6 +82,12 @@ public class GuiImgButton extends GuiButton implements ITooltip Appearances.put( new EnumPair( setting, val ), a ); } + public void setVisibility(boolean vis) + { + drawButton = vis; + enabled = vis; + } + public GuiImgButton(int x, int y, Enum idx, Enum val) { super( 0, 0, 16, "" ); buttonSetting = idx; @@ -110,10 +116,10 @@ public class GuiImgButton extends GuiButton implements ITooltip registerApp( 16 * 10 + 3, Settings.POWER_UNITS, PowerUnits.KJ, "AppEng.GuiITooltip.PowerUnits", "AppEng.GuiITooltip.UEUnits" ); registerApp( 16 * 10 + 4, Settings.POWER_UNITS, PowerUnits.WA, "AppEng.GuiITooltip.PowerUnits", "AppEng.GuiITooltip.WUnits" ); - registerApp( 3, Settings.REDSTONE_INPUT, RedstoneMode.IGNORE, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.AlwaysActive" ); - registerApp( 0, Settings.REDSTONE_INPUT, RedstoneMode.LOW_SIGNAL, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveWithoutSignal" ); - registerApp( 1, Settings.REDSTONE_INPUT, RedstoneMode.HIGH_SIGNAL, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveWithSignal" ); - registerApp( 2, Settings.REDSTONE_INPUT, RedstoneMode.SIGNAL_PULSE, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveOnPulse" ); + registerApp( 3, Settings.REDSTONE_OUTPUT, RedstoneMode.IGNORE, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.AlwaysActive" ); + registerApp( 0, Settings.REDSTONE_OUTPUT, RedstoneMode.LOW_SIGNAL, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveWithoutSignal" ); + registerApp( 1, Settings.REDSTONE_OUTPUT, RedstoneMode.HIGH_SIGNAL, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveWithSignal" ); + registerApp( 2, Settings.REDSTONE_OUTPUT, RedstoneMode.SIGNAL_PULSE, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveOnPulse" ); registerApp( 3, Settings.REDSTONE_INPUT, RedstoneMode.IGNORE, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.AlwaysActive" ); registerApp( 0, Settings.REDSTONE_INPUT, RedstoneMode.LOW_SIGNAL, "AppEng.GuiITooltip.RedstoneMode", "AppEng.GuiITooltip.ActiveWithoutSignal" ); @@ -230,7 +236,10 @@ public class GuiImgButton extends GuiButton implements ITooltip { if ( buttonSetting != null && currentValue != null ) { - return Appearances.get( new EnumPair( buttonSetting, currentValue ) ).index; + BtnAppearance app = Appearances.get( new EnumPair( buttonSetting, currentValue ) ); + if ( app == null ) + return 256 - 1; + return app.index; } return 256 - 1; } @@ -254,6 +263,9 @@ public class GuiImgButton extends GuiButton implements ITooltip if ( buttonSetting != null && currentValue != null ) { BtnAppearance ba = Appearances.get( new EnumPair( buttonSetting, currentValue ) ); + if ( ba == null ) + return "No Such Message"; + DisplayName = ba.DisplayName; DisplayValue = ba.DisplayValue; } diff --git a/container/AEBaseContainer.java b/container/AEBaseContainer.java index e272fbf3..8edf74f7 100644 --- a/container/AEBaseContainer.java +++ b/container/AEBaseContainer.java @@ -14,6 +14,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import appeng.api.AEApi; import appeng.api.networking.energy.IEnergySource; +import appeng.api.parts.IPart; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.data.IAEItemStack; import appeng.client.me.InternalSlotME; @@ -34,13 +35,24 @@ public abstract class AEBaseContainer extends Container final InventoryPlayer invPlayer; final TileEntity tileEntity; + final IPart part; protected IMEInventoryHandler cellInv; protected IEnergySource powerSrc; - public AEBaseContainer(InventoryPlayer ip, TileEntity te) { + public Object getTarget() + { + if ( tileEntity != null ) + return tileEntity; + if ( part != null ) + return part; + return null; + } + + public AEBaseContainer(InventoryPlayer ip, TileEntity myTile, IPart myPart) { invPlayer = ip; - tileEntity = te; + tileEntity = myTile; + part = myPart; } public boolean canDragIntoSlot(Slot s) @@ -495,4 +507,5 @@ public abstract class AEBaseContainer extends Container break; } } + } diff --git a/container/implementations/ContainerBus.java b/container/implementations/ContainerBus.java index c7d9efa0..f3274902 100644 --- a/container/implementations/ContainerBus.java +++ b/container/implementations/ContainerBus.java @@ -1,7 +1,11 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; +import appeng.api.config.FuzzyMode; +import appeng.api.config.RedstoneMode; +import appeng.api.config.Settings; import appeng.api.config.Upgrades; import appeng.api.implementations.IBusCommon; import appeng.container.AEBaseContainer; @@ -12,6 +16,9 @@ import appeng.container.slot.SlotFakeTypeOnly; import appeng.container.slot.SlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; import appeng.tile.inventory.AppEngInternalInventory; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost { @@ -20,7 +27,7 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost IInventory toolbox = new AppEngInternalInventory( null, 9 ); public ContainerBus(InventoryPlayer ip, IBusCommon te) { - super( ip, null ); + super( ip, null, te ); myte = te; IInventory upgrades = myte.getInventoryByName( "upgrades" ); @@ -55,9 +62,33 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost bindPlayerInventory( ip, 0, 184 - /* height of playerinventory */82 ); } + public RedstoneMode rsMode = RedstoneMode.IGNORE; + public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL; + @Override public void detectAndSendChanges() { + if ( Platform.isServer() ) + { + for (int i = 0; i < this.crafters.size(); ++i) + { + ICrafting icrafting = (ICrafting) this.crafters.get( i ); + + if ( this.rsMode != this.myte.getConfigManager().getSetting( Settings.REDSTONE_OUTPUT ) ) + { + icrafting.sendProgressBarUpdate( this, 0, (int) this.myte.getConfigManager().getSetting( Settings.REDSTONE_OUTPUT ).ordinal() ); + } + + if ( this.fzMode != this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) + { + icrafting.sendProgressBarUpdate( this, 1, (int) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ).ordinal() ); + } + } + + this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ); + this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_OUTPUT ); + } + for (Object o : inventorySlots) { if ( o instanceof OptionalSlotFake ) @@ -71,6 +102,19 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost super.detectAndSendChanges(); } + @Override + @SideOnly(Side.CLIENT) + public void updateProgressBar(int idx, int value) + { + + if ( idx == 0 ) + this.rsMode = RedstoneMode.values()[value]; + + if ( idx == 1 ) + this.fzMode = FuzzyMode.values()[value]; + + } + public boolean hasToolbox() { // TODO Auto-generated method stub diff --git a/container/implementations/ContainerChest.java b/container/implementations/ContainerChest.java index 366c004c..2469adf5 100644 --- a/container/implementations/ContainerChest.java +++ b/container/implementations/ContainerChest.java @@ -12,7 +12,7 @@ public class ContainerChest extends AEBaseContainer TileChest myte; public ContainerChest(InventoryPlayer ip, TileChest te) { - super( ip, te ); + super( ip, te, null ); myte = te; addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.STORAGE_CELLS, myte, 1, 80, 37 ) ); diff --git a/container/implementations/ContainerCondenser.java b/container/implementations/ContainerCondenser.java index 57733ae3..53c46f1b 100644 --- a/container/implementations/ContainerCondenser.java +++ b/container/implementations/ContainerCondenser.java @@ -20,7 +20,7 @@ public class ContainerCondenser extends AEBaseContainer TileCondenser myte; public ContainerCondenser(InventoryPlayer ip, TileCondenser te) { - super( ip, te ); + super( ip, te, null ); myte = te; addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.TRASH, te, 0, 51, 52 ) ); diff --git a/container/implementations/ContainerDrive.java b/container/implementations/ContainerDrive.java index 795391fa..75b954d0 100644 --- a/container/implementations/ContainerDrive.java +++ b/container/implementations/ContainerDrive.java @@ -12,7 +12,7 @@ public class ContainerDrive extends AEBaseContainer TileDrive myte; public ContainerDrive(InventoryPlayer ip, TileDrive te) { - super( ip, te ); + super( ip, te, null ); myte = te; for (int y = 0; y < 5; y++) diff --git a/container/implementations/ContainerGrinder.java b/container/implementations/ContainerGrinder.java index 8fc32e38..d367f585 100644 --- a/container/implementations/ContainerGrinder.java +++ b/container/implementations/ContainerGrinder.java @@ -14,7 +14,7 @@ public class ContainerGrinder extends AEBaseContainer TileGrinder myte; public ContainerGrinder(InventoryPlayer ip, TileGrinder te) { - super( ip, te ); + super( ip, te, null ); myte = te; addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.ORE, te, 0, 12, 17 ) ); diff --git a/container/implementations/ContainerInterface.java b/container/implementations/ContainerInterface.java index b8ee504a..ad11e644 100644 --- a/container/implementations/ContainerInterface.java +++ b/container/implementations/ContainerInterface.java @@ -14,14 +14,14 @@ public class ContainerInterface extends AEBaseContainer TileInterface myte; public ContainerInterface(InventoryPlayer ip, TileInterface te) { - super( ip, te ); + super( ip, te, null ); myte = te; for (int x = 0; x < 8; x++) - addSlotToContainer( new SlotFake( myte.getConfig(), x, 8 + 18 * x, 28 + 7 ) ); + addSlotToContainer( new SlotFake( myte.getConfig(), x, 17 + 18 * x, 35 ) ); for (int x = 0; x < 8; x++) - addSlotToContainer( new SlotNormal( myte, x, 26 + 18 * x, 46 + 7 ) ); + addSlotToContainer( new SlotNormal( myte, x, 17 + 18 * x, 35 + 18 ) ); for (int x = 0; x < 9; x++) addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.ENCODED_PATTERN, myte.getPatterns(), x, 8 + 18 * x, 90 + 7 ) ); diff --git a/container/implementations/ContainerLevelEmitter.java b/container/implementations/ContainerLevelEmitter.java index 14467ba5..bb575094 100644 --- a/container/implementations/ContainerLevelEmitter.java +++ b/container/implementations/ContainerLevelEmitter.java @@ -10,7 +10,7 @@ public class ContainerLevelEmitter extends AEBaseContainer PartLevelEmitter myte; public ContainerLevelEmitter(InventoryPlayer ip, PartLevelEmitter te) { - super( ip, te.getHost().getTile() ); + super( ip, te.getHost().getTile(), te ); myte = te; // addSlotToContainer( new SlotRestrictedInput( diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index 833e0cb8..2fa4f9a6 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -14,6 +14,7 @@ import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.parts.IPart; import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitorHandlerReciever; import appeng.api.storage.data.IAEItemStack; @@ -32,7 +33,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito final IItemList items = new ItemList(); public ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable) { - super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null ); + super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null ); if ( Platform.isServer() ) { diff --git a/container/implementations/ContainerNetworkStatus.java b/container/implementations/ContainerNetworkStatus.java index f051865a..d55a16d6 100644 --- a/container/implementations/ContainerNetworkStatus.java +++ b/container/implementations/ContainerNetworkStatus.java @@ -10,7 +10,7 @@ public class ContainerNetworkStatus extends AEBaseContainer TileEntity myte; public ContainerNetworkStatus(InventoryPlayer ip, TileEntity te) { - super( ip, (TileEntity) te ); + super( ip, te, null ); myte = te; // addSlotToContainer( new SlotRestrictedInput( diff --git a/container/implementations/ContainerSpatialIOPort.java b/container/implementations/ContainerSpatialIOPort.java index b84dbd41..3f777697 100644 --- a/container/implementations/ContainerSpatialIOPort.java +++ b/container/implementations/ContainerSpatialIOPort.java @@ -13,7 +13,7 @@ public class ContainerSpatialIOPort extends AEBaseContainer TileSpatialIOPort myte; public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort te) { - super( ip, te ); + super( ip, te, null ); myte = te; addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.SPATIAL_STORAGE_CELLS, te, 0, 71, 14 ) ); diff --git a/container/implementations/ContainerVibrationChamber.java b/container/implementations/ContainerVibrationChamber.java index cc9e2db3..b526adc0 100644 --- a/container/implementations/ContainerVibrationChamber.java +++ b/container/implementations/ContainerVibrationChamber.java @@ -17,7 +17,7 @@ public class ContainerVibrationChamber extends AEBaseContainer TileVibrationChamber myte; public ContainerVibrationChamber(InventoryPlayer ip, TileVibrationChamber te) { - super( ip, te ); + super( ip, te, null ); myte = te; addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.FUEL, te, 0, 80, 37 ) ); diff --git a/core/features/registries/entries/CreativeCellHandler.java b/core/features/registries/entries/CreativeCellHandler.java index 08f38746..677e2420 100644 --- a/core/features/registries/entries/CreativeCellHandler.java +++ b/core/features/registries/entries/CreativeCellHandler.java @@ -2,7 +2,6 @@ package appeng.core.features.registries.entries; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.Icon; import appeng.api.implementations.IChestOrDrive; import appeng.api.storage.ICellHandler; @@ -10,8 +9,11 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.StorageChannel; import appeng.client.texture.ExtraTextures; +import appeng.core.sync.GuiBridge; import appeng.items.storage.ItemCreativeStorageCell; import appeng.me.storage.CreativeCellInventory; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; public class CreativeCellHandler implements ICellHandler { @@ -39,7 +41,7 @@ public class CreativeCellHandler implements ICellHandler @Override public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan) { - player.sendChatToPlayer( ChatMessageComponent.createFromText( "Not ready yet..." ) ); + Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME ); } @Override diff --git a/core/sync/packets/PacketConfigButton.java b/core/sync/packets/PacketConfigButton.java index 3142e2f8..88d488d2 100644 --- a/core/sync/packets/PacketConfigButton.java +++ b/core/sync/packets/PacketConfigButton.java @@ -7,7 +7,6 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetworkManager; -import net.minecraft.tileentity.TileEntity; import appeng.api.config.Settings; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigureableObject; @@ -31,10 +30,9 @@ public class PacketConfigButton extends AppEngPacket { EntityPlayerMP sender = (EntityPlayerMP) player; AEBaseContainer aebc = (AEBaseContainer) sender.openContainer; - TileEntity bt = aebc.getTileEntity(); - if ( bt instanceof IConfigureableObject ) + if ( aebc.getTarget() instanceof IConfigureableObject ) { - IConfigManager cm = ((IConfigureableObject) bt).getConfigManager(); + IConfigManager cm = ((IConfigureableObject) aebc.getTarget()).getConfigManager(); Enum newState = Platform.nextEnum( cm.getSetting( option ) ); cm.putSetting( option, newState ); } diff --git a/helpers/TickHandler.java b/helpers/TickHandler.java index 8e0eb9c6..fad41010 100644 --- a/helpers/TickHandler.java +++ b/helpers/TickHandler.java @@ -2,7 +2,6 @@ package appeng.helpers; import java.util.EnumSet; import java.util.LinkedList; -import java.util.List; import java.util.Queue; import net.minecraftforge.event.ForgeSubscribe; @@ -22,7 +21,7 @@ public class TickHandler implements ITickHandler public Queue tiles = new LinkedList(); - public List networks = new LinkedList(); + public LinkedList networks = new LinkedList(); public void clear() { @@ -76,8 +75,9 @@ public class TickHandler implements ITickHandler { if ( Platform.isServer() ) { - for (Grid g : getRepo().networks) + while (!getRepo().networks.isEmpty()) { + Grid g = getRepo().networks.poll(); for (IGridNode n : g.getNodes()) { if ( n.getWorld() == ev.world ) diff --git a/parts/automation/PartExportBus.java b/parts/automation/PartExportBus.java index a9f3d057..1c59a9b4 100644 --- a/parts/automation/PartExportBus.java +++ b/parts/automation/PartExportBus.java @@ -8,6 +8,7 @@ import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.RedstoneMode; import appeng.api.config.Settings; +import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.ticking.IGridTickable; @@ -105,16 +106,30 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable } @Override - protected boolean isSleeping() - { - // TODO Auto-generated method stub - return getHandler() == null; - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + TickRateModulation doBusWork() { int itemToSend = 1; + + switch (getInstalledUpgrades( Upgrades.SPEED )) + { + default: + case 0: + itemToSend = 1; + break; + case 1: + itemToSend = 8; + break; + case 2: + itemToSend = 32; + break; + case 3: + itemToSend = 64; + break; + case 4: + itemToSend = 96; + break; + } + boolean didSomething = false; try @@ -170,4 +185,20 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER; } + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + return doBusWork(); + } + + public RedstoneMode getRSMode() + { + return (RedstoneMode) settings.getSetting( Settings.REDSTONE_OUTPUT ); + } + + @Override + protected boolean isSleeping() + { + return getHandler() == null || super.isSleeping(); + } } diff --git a/parts/automation/PartImportBus.java b/parts/automation/PartImportBus.java index 44fe4dbe..a1a72d7d 100644 --- a/parts/automation/PartImportBus.java +++ b/parts/automation/PartImportBus.java @@ -10,6 +10,7 @@ import appeng.api.config.FuzzyMode; import appeng.api.config.PowerMultiplier; import appeng.api.config.RedstoneMode; import appeng.api.config.Settings; +import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; @@ -31,7 +32,7 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I public PartImportBus(ItemStack is) { super( PartImportBus.class, is ); - settings.registerSetting( Settings.REDSTONE_INPUT, RedstoneMode.IGNORE ); + settings.registerSetting( Settings.REDSTONE_OUTPUT, RedstoneMode.IGNORE ); settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); } @@ -130,32 +131,63 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I return new TickingRequest( 5, 40, getHandler() == null, false ); } - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + private int itemToSend; // used in tickingRequest + private boolean worked; // used in tickingRequest + + TickRateModulation doBusWork() { - boolean worked = false; + worked = false; InventoryAdaptor myAdaptor = getHandler(); if ( myAdaptor != null ) { try { - int howMany = 1; - howMany = Math.min( howMany, (int) (0.01 + proxy.getEnergy().extractAEPower( howMany, Actionable.SIMULATE, PowerMultiplier.CONFIG )) ); - - ItemStack newItems = myAdaptor.removeItems( howMany, null, configDest( proxy.getStorage().getItemInventory() ) ); - if ( newItems != null ) + switch (getInstalledUpgrades( Upgrades.SPEED )) { - if ( lastItemChecked == null || !lastItemChecked.isSameType( newItems ) ) - lastItemChecked = AEApi.instance().storage().createItemStack( newItems ); - else - lastItemChecked.setStackSize( newItems.stackSize ); + default: + case 0: + itemToSend = 1; + break; + case 1: + itemToSend = 8; + break; + case 2: + itemToSend = 32; + break; + case 3: + itemToSend = 64; + break; + case 4: + itemToSend = 96; + break; + } - IAEItemStack failed = destination.injectItems( lastItemChecked, Actionable.MODULATE ); - if ( failed != null ) - myAdaptor.addItems( failed.getItemStack() ); - else - worked = true; + itemToSend = Math.min( itemToSend, (int) (0.01 + proxy.getEnergy().extractAEPower( itemToSend, Actionable.SIMULATE, PowerMultiplier.CONFIG )) ); + IMEMonitor inv = proxy.getStorage().getItemInventory(); + + boolean Configured = false; + for (int x = 0; x < availableSlots(); x++) + { + IAEItemStack ais = config.getAEStackInSlot( x ); + if ( ais != null && itemToSend > 0 ) + { + Configured = true; + while (itemToSend > 0) + { + if ( importStuff( myAdaptor, ais, inv ) ) + break; + } + } + } + + if ( !Configured ) + { + while (itemToSend > 0) + { + if ( importStuff( myAdaptor, null, inv ) ) + break; + } } } catch (GridAccessException e) @@ -169,10 +201,51 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I return worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER; } + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + return doBusWork(); + } + + private boolean importStuff(InventoryAdaptor myAdaptor, IAEItemStack whatToImport, IMEMonitor inv) + { + if ( itemToSend > 64 ) + itemToSend = 64; + + ItemStack newItems = myAdaptor.removeItems( itemToSend, whatToImport == null ? null : whatToImport.getItemStack(), configDest( inv ) ); + if ( newItems != null ) + { + itemToSend -= newItems.stackSize; + + if ( lastItemChecked == null || !lastItemChecked.isSameType( newItems ) ) + lastItemChecked = AEApi.instance().storage().createItemStack( newItems ); + else + lastItemChecked.setStackSize( newItems.stackSize ); + + IAEItemStack failed = destination.injectItems( lastItemChecked, Actionable.MODULATE ); + if ( failed != null ) + { + myAdaptor.addItems( failed.getItemStack() ); + return true; + } + else + worked = true; + } + else + return true; + + return false; + } + + public RedstoneMode getRSMode() + { + return (RedstoneMode) settings.getSetting( Settings.REDSTONE_OUTPUT ); + } + @Override protected boolean isSleeping() { - return getHandler() == null; + return getHandler() == null || super.isSleeping(); } } diff --git a/parts/automation/PartSharedItemBus.java b/parts/automation/PartSharedItemBus.java index a6792159..890e02ce 100644 --- a/parts/automation/PartSharedItemBus.java +++ b/parts/automation/PartSharedItemBus.java @@ -3,9 +3,11 @@ package appeng.parts.automation; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import appeng.api.config.RedstoneMode; import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; import appeng.me.GridAccessException; import appeng.tile.inventory.AppEngInternalAEInventory; @@ -19,6 +21,12 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid super( c, is ); } + @Override + public void upgradesChanged() + { + updateState(); + } + protected int availableSlots() { return Math.min( 1 + getInstalledUpgrades( Upgrades.CAPACITY ) * 4, config.getSizeInventory() ); @@ -61,23 +69,37 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid cached = true; return adaptor; - } + boolean lastRedstone = false; + + abstract TickRateModulation doBusWork(); + @Override public void onNeighborChanged() { - cached = false; - if ( !isSleeping() ) + updateState(); + if ( lastRedstone != host.hasRedstone( side ) ) { - try - { + lastRedstone = !lastRedstone; + if ( lastRedstone && getRSMode() == RedstoneMode.SIGNAL_PULSE ) + doBusWork(); + } + } + + private void updateState() + { + cached = false; + try + { + if ( !isSleeping() ) proxy.getTick().wakeDevice( proxy.getNode() ); - } - catch (GridAccessException e) - { - // :P - } + else + proxy.getTick().sleepDevice( proxy.getNode() ); + } + catch (GridAccessException e) + { + // :P } } @@ -96,6 +118,4 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid return new TickingRequest( 5, 60, isSleeping(), false ); } - abstract protected boolean isSleeping(); - } diff --git a/parts/automation/PartUpgradeable.java b/parts/automation/PartUpgradeable.java index 16d4bfb9..92c1fbae 100644 --- a/parts/automation/PartUpgradeable.java +++ b/parts/automation/PartUpgradeable.java @@ -2,6 +2,7 @@ package appeng.parts.automation; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import appeng.api.config.RedstoneMode; import appeng.api.config.Upgrades; import appeng.api.implementations.ISegmentedInventory; import appeng.api.util.IConfigManager; @@ -45,7 +46,7 @@ public class PartUpgradeable extends PartBasicState implements ISegmentedInvento @Override public IConfigManager getConfigManager() { - return null; + return settings; } @Override @@ -63,10 +64,55 @@ public class PartUpgradeable extends PartBasicState implements ISegmentedInvento } - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) + public void upgradesChanged() { } + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) + { + if ( inv == upgrades ) + { + upgradesChanged(); + } + } + + public RedstoneMode getRSMode() + { + return null; + } + + protected boolean isSleeping() + { + if ( getInstalledUpgrades( Upgrades.REDSTONE ) > 0 ) + { + switch (getRSMode()) + { + case IGNORE: + return false; + + case HIGH_SIGNAL: + if ( host.hasRedstone( side ) ) + return false; + + break; + + case LOW_SIGNAL: + if ( !host.hasRedstone( side ) ) + return false; + + break; + + case SIGNAL_PULSE: + default: + break; + + } + + return true; + } + + return false; + } }