Redstone Logic for Buses, and Part Image Button goodness

This commit is contained in:
AlgorithmX2 2014-01-01 23:51:41 -06:00
parent 0acbefbfaa
commit db4cf7aa5d
22 changed files with 367 additions and 73 deletions

View file

@ -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 );
}
}

View file

@ -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 );

View file

@ -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;
}

View file

@ -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<IAEItemStack> 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;
}
}
}

View file

@ -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

View file

@ -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 ) );

View file

@ -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 ) );

View file

@ -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++)

View file

@ -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 ) );

View file

@ -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 ) );

View file

@ -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(

View file

@ -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<IAEItemStack> items = new ItemList<IAEItemStack>();
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() )
{

View file

@ -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(

View file

@ -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 ) );

View file

@ -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 ) );

View file

@ -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

View file

@ -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 );
}

View file

@ -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<AEBaseTile> tiles = new LinkedList();
public List<Grid> networks = new LinkedList();
public LinkedList<Grid> 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 )

View file

@ -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();
}
}

View file

@ -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<IAEItemStack> 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<IAEItemStack> 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();
}
}

View file

@ -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();
}

View file

@ -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;
}
}