Divided up Config/Settings and stuff into different classes.

This commit is contained in:
AlgorithmX2 2013-12-29 23:55:02 -06:00
parent cc43396066
commit 3b4be73957
6 changed files with 352 additions and 49 deletions

View file

@ -1,17 +1,43 @@
package appeng.parts.automation;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.parts.IPartCollsionHelper;
import appeng.api.parts.IPartRenderHelper;
import appeng.client.texture.CableBusTextures;
import appeng.parts.PartBasicState;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
public class PartExportBus extends PartBasicState
public class PartExportBus extends PartSharedItemBus implements IGridTickable
{
public PartExportBus(ItemStack is) {
super( PartExportBus.class, is );
settings.registerSetting( Settings.REDSTONE_OUTPUT, RedstoneMode.IGNORE );
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{
if ( Platform.isClient() )
return true;
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_BUS );
return true;
}
return false;
}
@Override
@ -71,4 +97,18 @@ public class PartExportBus extends PartBasicState
bch.addBox( 6, 6, 11, 10, 10, 12 );
}
@Override
protected boolean isSleeping()
{
// TODO Auto-generated method stub
return getHandler() == null;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
// TODO Auto-generated method stub
return TickRateModulation.SLOWER;
}
}

View file

@ -1,11 +1,15 @@
package appeng.parts.automation;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
@ -16,17 +20,34 @@ import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.texture.CableBusTextures;
import appeng.core.sync.GuiBridge;
import appeng.me.GridAccessException;
import appeng.parts.PartBasicState;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination;
public class PartImportBus extends PartBasicState implements IGridTickable, IInventoryDestination
public class PartImportBus extends PartSharedItemBus implements IGridTickable, IInventoryDestination
{
public PartImportBus(ItemStack is) {
super( PartImportBus.class, is );
settings.registerSetting( Settings.REDSTONE_INPUT, RedstoneMode.IGNORE );
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{
if ( Platform.isClient() )
return true;
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_BUS );
return true;
}
return false;
}
IMEInventory<IAEItemStack> destination = null;
@ -46,49 +67,6 @@ public class PartImportBus extends PartBasicState implements IGridTickable, IInv
return this;
}
boolean cached = false;
int adaptorHash = 0;
InventoryAdaptor adaptor;
InventoryAdaptor getHandler()
{
if ( cached )
return adaptor;
cached = true;
TileEntity self = getHost().getTile();
TileEntity target = self.worldObj.getBlockTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
int newAdaptorHash = Platform.generateTileHash( target );
if ( adaptorHash == newAdaptorHash )
return adaptor;
adaptorHash = newAdaptorHash;
adaptor = InventoryAdaptor.getAdaptor( target, side.getOpposite() );
cached = true;
return adaptor;
}
@Override
public void onNeighborChanged()
{
cached = false;
if ( adaptor == null && getHandler() != null )
{
try
{
proxy.getTick().wakeDevice( proxy.getNode() );
}
catch (GridAccessException e)
{
// :P
}
}
}
@Override
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
{
@ -184,4 +162,10 @@ public class PartImportBus extends PartBasicState implements IGridTickable, IInv
return worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
@Override
protected boolean isSleeping()
{
return getHandler() == null;
}
}

View file

@ -0,0 +1,95 @@
package appeng.parts.automation;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickingRequest;
import appeng.me.GridAccessException;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable
{
public PartSharedItemBus(Class c, ItemStack is) {
super( c, is );
}
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
{
super.writeToNBT( extra );
config.writeToNBT( extra, "config" );
}
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
{
super.readFromNBT( extra );
config.readFromNBT( extra, "config" );
}
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
boolean cached = false;
int adaptorHash = 0;
InventoryAdaptor adaptor;
InventoryAdaptor getHandler()
{
if ( cached )
return adaptor;
cached = true;
TileEntity self = getHost().getTile();
TileEntity target = self.worldObj.getBlockTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
int newAdaptorHash = Platform.generateTileHash( target );
if ( adaptorHash == newAdaptorHash )
return adaptor;
adaptorHash = newAdaptorHash;
adaptor = InventoryAdaptor.getAdaptor( target, side.getOpposite() );
cached = true;
return adaptor;
}
@Override
public void onNeighborChanged()
{
cached = false;
if ( !isSleeping() )
{
try
{
proxy.getTick().wakeDevice( proxy.getNode() );
}
catch (GridAccessException e)
{
// :P
}
}
}
@Override
public IInventory getInventoryByName(String name)
{
if ( name.equals( "config" ) )
return config;
return super.getInventoryByName( name );
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
return new TickingRequest( 5, 60, isSleeping(), false );
}
abstract protected boolean isSleeping();
}

View file

@ -0,0 +1,72 @@
package appeng.parts.automation;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.api.implementations.ISegmentedInventory;
import appeng.api.util.IConfigManager;
import appeng.parts.PartBasicState;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
public class PartUpgradeable extends PartBasicState implements ISegmentedInventory, IAEAppEngInventory, IConfigManagerHost
{
IConfigManager settings = new ConfigManager( this );
private UpgradeInventory upgrades = new UpgradeInventory( this, 4 );
@Override
public int getInstalledUpgrades(Upgrades u)
{
return upgrades.getInstalledUpgrades( u );
}
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
{
super.writeToNBT( extra );
settings.writeToNBT( extra );
upgrades.writeToNBT( extra, "upgrades" );
}
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
{
super.readFromNBT( extra );
settings.readFromNBT( extra );
upgrades.readFromNBT( extra, "upgrades" );
}
public PartUpgradeable(Class c, ItemStack is) {
super( c, is );
upgrades.setMaxStackSize( 1 );
}
@Override
public IConfigManager getConfigManager()
{
return null;
}
@Override
public IInventory getInventoryByName(String name)
{
if ( name.equals( "upgrades" ) )
return upgrades;
return null;
}
@Override
public void updateSetting(Enum settingName, Enum newValue)
{
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
}
}

View file

@ -0,0 +1,113 @@
package appeng.parts.automation;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeModule;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
public class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
{
private int FuzzyUpgrades = 0;
private int SpeedUpgrades = 0;
private int RedstoneUpgrades = 0;
private int CapacityUpgrades = 0;
IAEAppEngInventory parent;
public UpgradeInventory(IAEAppEngInventory _te, int s) {
super( null, s );
te = this;
parent = _te;
}
@Override
protected boolean eventsEnabled()
{
return true;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
if ( itemstack == null )
return false;
Item it = itemstack.getItem();
if ( it instanceof IUpgradeModule )
{
Upgrades u = ((IUpgradeModule) it).getType( itemstack );
if ( u != null )
{
return getInstalledUpgrades( u ) < u.maxInstalled;
}
}
return false;
}
private void updateUpgradeInfo()
{
CapacityUpgrades = RedstoneUpgrades = SpeedUpgrades = FuzzyUpgrades = 0;
for (ItemStack is : this)
{
if ( is == null || is.getItem() == null || !(is.getItem() instanceof IUpgradeModule) )
continue;
Upgrades myUpgrade = ((IUpgradeModule) is.getItem()).getType( is );
switch (myUpgrade)
{
case CAPACITY:
CapacityUpgrades++;
break;
case FUZZY:
FuzzyUpgrades++;
break;
case REDSTONE:
RedstoneUpgrades++;
break;
case SPEED:
SpeedUpgrades++;
break;
default:
break;
}
}
CapacityUpgrades = Math.min( CapacityUpgrades, Upgrades.CAPACITY.maxInstalled );
FuzzyUpgrades = Math.min( FuzzyUpgrades, Upgrades.FUZZY.maxInstalled );
RedstoneUpgrades = Math.min( RedstoneUpgrades, Upgrades.REDSTONE.maxInstalled );
SpeedUpgrades = Math.min( SpeedUpgrades, Upgrades.SPEED.maxInstalled );
}
public int getInstalledUpgrades(Upgrades u)
{
switch (u)
{
case CAPACITY:
return CapacityUpgrades;
case FUZZY:
return FuzzyUpgrades;
case REDSTONE:
return RedstoneUpgrades;
case SPEED:
return SpeedUpgrades;
default:
return 0;
}
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
updateUpgradeInfo();
if ( parent != null && Platform.isServer() )
parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
}

View file

@ -132,7 +132,6 @@ public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventor
return true;
}
@Override
public abstract IInventory getInternalInventory();
@Override