Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.CopyMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.storage.ICellWorkbenchItem;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
|
||||
public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, IAEAppEngInventory, IConfigurableObject, IConfigManagerHost
|
||||
{
|
||||
|
||||
AppEngInternalInventory cell = new AppEngInternalInventory( this, 1 );
|
||||
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 63 );
|
||||
ConfigManager cm = new ConfigManager( this );
|
||||
|
||||
IInventory cacheUpgrades = null;
|
||||
IInventory cacheConfig = null;
|
||||
|
||||
public IInventory getCellUpgradeInventory()
|
||||
{
|
||||
if ( cacheUpgrades == null )
|
||||
{
|
||||
ICellWorkbenchItem cwbi = getCell();
|
||||
if ( cwbi == null )
|
||||
return null;
|
||||
|
||||
ItemStack is = cell.getStackInSlot( 0 );
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
IInventory inv = cwbi.getUpgradesInventory( is );
|
||||
if ( inv == null )
|
||||
return null;
|
||||
|
||||
return cacheUpgrades = inv;
|
||||
}
|
||||
return cacheUpgrades;
|
||||
}
|
||||
|
||||
public IInventory getCellConfigInventory()
|
||||
{
|
||||
if ( cacheConfig == null )
|
||||
{
|
||||
ICellWorkbenchItem cwbi = getCell();
|
||||
if ( cwbi == null )
|
||||
return null;
|
||||
|
||||
ItemStack is = cell.getStackInSlot( 0 );
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
IInventory inv = cwbi.getConfigInventory( is );
|
||||
if ( inv == null )
|
||||
return null;
|
||||
|
||||
return cacheConfig = inv;
|
||||
}
|
||||
return cacheConfig;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCellWorkbench(NBTTagCompound data)
|
||||
{
|
||||
cell.writeToNBT( data, "cell" );
|
||||
config.writeToNBT( data, "config" );
|
||||
cm.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCellWorkbench(NBTTagCompound data)
|
||||
{
|
||||
cell.readFromNBT( data, "cell" );
|
||||
config.readFromNBT( data, "config" );
|
||||
cm.readFromNBT( data );
|
||||
}
|
||||
|
||||
public TileCellWorkbench() {
|
||||
cm.registerSetting( Settings.COPY_MODE, CopyMode.CLEAR_ON_REMOVE );
|
||||
cell.enableClientEvents = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "config" ) )
|
||||
return config;
|
||||
|
||||
if ( name.equals( "cell" ) )
|
||||
return cell;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean locked = false;
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
if ( inv == cell && locked == false )
|
||||
{
|
||||
locked = true;
|
||||
|
||||
cacheUpgrades = null;
|
||||
cacheConfig = null;
|
||||
|
||||
IInventory c = getCellConfigInventory();
|
||||
if ( c != null )
|
||||
{
|
||||
boolean cellHasConfig = false;
|
||||
for (int x = 0; x < c.getSizeInventory(); x++)
|
||||
{
|
||||
if ( c.getStackInSlot( x ) != null )
|
||||
{
|
||||
cellHasConfig = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( cellHasConfig )
|
||||
{
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
config.setInventorySlotContents( x, c.getStackInSlot( x ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
c.setInventorySlotContents( x, config.getStackInSlot( x ) );
|
||||
|
||||
c.markDirty();
|
||||
}
|
||||
}
|
||||
else if ( cm.getSetting( Settings.COPY_MODE ) == CopyMode.CLEAR_ON_REMOVE )
|
||||
{
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
config.setInventorySlotContents( x, null );
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
locked = false;
|
||||
}
|
||||
else if ( inv == config && locked == false )
|
||||
{
|
||||
IInventory c = getCellConfigInventory();
|
||||
if ( c != null )
|
||||
{
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
c.setInventorySlotContents( x, config.getStackInSlot( x ) );
|
||||
|
||||
c.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
{
|
||||
super.getDrops( w, x, y, z, drops );
|
||||
|
||||
if ( cell.getStackInSlot( 0 ) != null )
|
||||
drops.add( cell.getStackInSlot( 0 ) );
|
||||
}
|
||||
|
||||
public ICellWorkbenchItem getCell()
|
||||
{
|
||||
if ( cell.getStackInSlot( 0 ) == null )
|
||||
return null;
|
||||
|
||||
if ( cell.getStackInSlot( 0 ).getItem() instanceof ICellWorkbenchItem )
|
||||
return ((ICellWorkbenchItem) cell.getStackInSlot( 0 ).getItem());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
// nothing here..
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
{
|
||||
|
||||
final int sides[] = new int[] { 0 };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
|
||||
int tickTickTimer = 0;
|
||||
|
||||
int lastUpdate = 0;
|
||||
boolean requiresUpdate = false;
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileCharger(ByteBuf data) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
IAEItemStack item = AEItemStack.loadItemStackFromPacket( data );
|
||||
ItemStack is = item.getItemStack();
|
||||
inv.setInventorySlotContents( 0, is );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
inv.setInventorySlotContents( 0, null );
|
||||
}
|
||||
return false; // TESR doesn't need updates!
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileCharger(ByteBuf data) throws IOException
|
||||
{
|
||||
AEItemStack is = AEItemStack.create( getStackInSlot( 0 ) );
|
||||
if ( is != null )
|
||||
is.writeToPacket( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.TICK)
|
||||
public void Tick_TileCharger()
|
||||
{
|
||||
if ( lastUpdate > 60 && requiresUpdate )
|
||||
{
|
||||
requiresUpdate = false;
|
||||
markForUpdate();
|
||||
lastUpdate = 0;
|
||||
}
|
||||
lastUpdate++;
|
||||
|
||||
tickTickTimer++;
|
||||
if ( tickTickTimer < 20 )
|
||||
return;
|
||||
tickTickTimer = 0;
|
||||
|
||||
ItemStack myItem = getStackInSlot( 0 );
|
||||
|
||||
// charge from the network!
|
||||
if ( internalCurrentPower < 1499 )
|
||||
{
|
||||
try
|
||||
{
|
||||
injectExternalPower( PowerUnits.AE,
|
||||
gridProxy.getEnergy().extractAEPower( Math.min( 150.0, 1500.0 - internalCurrentPower ), Actionable.MODULATE, PowerMultiplier.ONE ) );
|
||||
tickTickTimer = 20; // keep ticking...
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// continue!
|
||||
}
|
||||
}
|
||||
|
||||
if ( myItem == null )
|
||||
return;
|
||||
|
||||
if ( internalCurrentPower > 149 && Platform.isChargeable( myItem ) )
|
||||
{
|
||||
IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
|
||||
if ( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) )
|
||||
{
|
||||
double oldPower = internalCurrentPower;
|
||||
|
||||
double adjustment = ps.injectAEPower( myItem, extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ) );
|
||||
internalCurrentPower += adjustment;
|
||||
if ( oldPower > internalCurrentPower )
|
||||
requiresUpdate = true;
|
||||
tickTickTimer = 20; // keep ticking...
|
||||
}
|
||||
}
|
||||
else if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
|
||||
{
|
||||
if ( Platform.getRandomFloat() > 0.8f ) // simulate wait
|
||||
{
|
||||
extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TileCharger() {
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
gridProxy.setFlags();
|
||||
internalMaxPower = 1500;
|
||||
gridProxy.setIdlePowerUsage( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
gridProxy.setValidSides( EnumSet.of( getUp(), getUp().getOpposite() ) );
|
||||
setPowerSides( EnumSet.of( getUp(), getUp().getOpposite() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTurn()
|
||||
{
|
||||
return internalCurrentPower < internalMaxPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTurn()
|
||||
{
|
||||
injectExternalPower( PowerUnits.AE, 150 );
|
||||
|
||||
ItemStack myItem = getStackInSlot( 0 );
|
||||
if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
|
||||
{
|
||||
extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCrankAttach(ForgeDirection directionToCrank)
|
||||
{
|
||||
return getUp().equals( directionToCrank ) || getUp().getOpposite().equals( directionToCrank );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return Platform.isChargeable( itemstack ) || AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
if ( Platform.isChargeable( itemstack ) )
|
||||
{
|
||||
IAEItemPowerStorage ips = (IAEItemPowerStorage) itemstack.getItem();
|
||||
if ( ips.getAECurrentPower( itemstack ) >= ips.getAEMaxPower( itemstack ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( itemstack );
|
||||
}
|
||||
|
||||
public void activate(EntityPlayer player)
|
||||
{
|
||||
if ( !Platform.hasPermissions( new DimensionalCoord( this ), player ) )
|
||||
return;
|
||||
|
||||
ItemStack myItem = getStackInSlot( 0 );
|
||||
if ( myItem == null )
|
||||
{
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
if ( AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( held ) || Platform.isChargeable( held ) )
|
||||
{
|
||||
held = player.inventory.decrStackSize( player.inventory.currentItem, 1 );
|
||||
setInventorySlotContents( 0, held );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ItemStack> drops = new ArrayList();
|
||||
drops.add( myItem );
|
||||
setInventorySlotContents( 0, null );
|
||||
Platform.spawnDrops( worldObj, xCoord + getForward().offsetX, yCoord + getForward().offsetY, zCoord + getForward().offsetZ, drops );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.CondenserOutput;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.implementations.items.IStorageComponent;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileCondenser extends AEBaseInvTile implements IAEAppEngInventory, IFluidHandler, IConfigManagerHost, IConfigurableObject
|
||||
{
|
||||
|
||||
int sides[] = new int[] { 0, 1 };
|
||||
static private FluidTankInfo[] empty = new FluidTankInfo[] { new FluidTankInfo( null, 10 ) };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 3 );
|
||||
ConfigManager cm = new ConfigManager( this );
|
||||
|
||||
public double storedPower = 0;
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCondenser(NBTTagCompound data)
|
||||
{
|
||||
cm.writeToNBT( data );
|
||||
data.setDouble( "storedPower", storedPower );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCondenser(NBTTagCompound data)
|
||||
{
|
||||
cm.readFromNBT( data );
|
||||
storedPower = data.getDouble( "storedPower" );
|
||||
}
|
||||
|
||||
public TileCondenser() {
|
||||
cm.registerSetting( Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH );
|
||||
}
|
||||
|
||||
public double getStorage()
|
||||
{
|
||||
ItemStack is = inv.getStackInSlot( 2 );
|
||||
if ( is != null )
|
||||
{
|
||||
if ( is.getItem() instanceof IStorageComponent )
|
||||
{
|
||||
IStorageComponent sc = (IStorageComponent) is.getItem();
|
||||
if ( sc.isStorageComponent( is ) )
|
||||
return sc.getBytes( is ) * 8;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addPower(double rawPower)
|
||||
{
|
||||
storedPower += rawPower;
|
||||
storedPower = Math.max( 0.0, Math.min( getStorage(), storedPower ) );
|
||||
|
||||
double requiredPower = getRequiredPower();
|
||||
ItemStack output = getOutput();
|
||||
while (requiredPower <= storedPower && output != null && requiredPower > 0)
|
||||
{
|
||||
if ( canAddOutput( output ) )
|
||||
{
|
||||
storedPower -= requiredPower;
|
||||
addOutput( output );
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean canAddOutput(ItemStack output)
|
||||
{
|
||||
ItemStack outputStack = getStackInSlot( 1 );
|
||||
return outputStack == null || (Platform.isSameItem( outputStack, output ) && outputStack.stackSize < outputStack.getMaxStackSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* make sure you validate with canAddOutput prior to this.
|
||||
*
|
||||
* @param output
|
||||
*/
|
||||
private void addOutput(ItemStack output)
|
||||
{
|
||||
ItemStack outputStack = getStackInSlot( 1 );
|
||||
if ( outputStack == null )
|
||||
setInventorySlotContents( 1, output.copy() );
|
||||
else
|
||||
{
|
||||
outputStack.stackSize++;
|
||||
setInventorySlotContents( 1, outputStack );
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getOutput()
|
||||
{
|
||||
switch ((CondenserOutput) cm.getSetting( Settings.CONDENSER_OUTPUT ))
|
||||
{
|
||||
case MATTER_BALLS:
|
||||
return AEApi.instance().materials().materialMatterBall.stack( 1 );
|
||||
case SINGULARITY:
|
||||
return AEApi.instance().materials().materialSingularity.stack( 1 );
|
||||
case TRASH:
|
||||
default:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getRequiredPower()
|
||||
{
|
||||
return ((CondenserOutput) cm.getSetting( Settings.CONDENSER_OUTPUT )).requiredPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( i == 0 )
|
||||
{
|
||||
if ( itemstack != null )
|
||||
addPower( itemstack.stackSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
inv.setInventorySlotContents( 1, itemstack );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return i == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
if ( slot == 0 )
|
||||
{
|
||||
ItemStack is = inv.getStackInSlot( 0 );
|
||||
if ( is != null )
|
||||
{
|
||||
addPower( is.stackSize );
|
||||
inv.setInventorySlotContents( 0, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if ( doFill )
|
||||
addPower( (resource == null ? 0.0 : (double) resource.amount) / 500.0 );
|
||||
|
||||
return resource == null ? 0 : resource.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
return empty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
addPower( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,400 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.recipes.handlers.Inscribe;
|
||||
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperInventoryRange;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileInscriber extends AENetworkPowerTile implements IGridTickable
|
||||
{
|
||||
|
||||
final int top[] = new int[] { 0 };
|
||||
final int bottom[] = new int[] { 1 };
|
||||
final int sides[] = new int[] { 2, 3 };
|
||||
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 );
|
||||
|
||||
public final int maxProcessingTime = 100;
|
||||
public int processingTime = 0;
|
||||
|
||||
// cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine.
|
||||
public boolean smash;
|
||||
public int finalStep;
|
||||
|
||||
public long clientStart;
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileInscriber(NBTTagCompound data)
|
||||
{
|
||||
inv.writeToNBT( data, "inscriberInv" );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileInscriber(NBTTagCompound data)
|
||||
{
|
||||
inv.readFromNBT( data, "inscriberInv" );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileInscriber(ByteBuf data) throws IOException
|
||||
{
|
||||
int slot = data.readByte();
|
||||
|
||||
boolean oldSmash = smash;
|
||||
boolean newSmash = (slot & 64) == 64;
|
||||
|
||||
if ( oldSmash != newSmash && newSmash )
|
||||
{
|
||||
smash = true;
|
||||
clientStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
for (int num = 0; num < inv.getSizeInventory(); num++)
|
||||
{
|
||||
if ( (slot & (1 << num)) > 0 )
|
||||
inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
|
||||
else
|
||||
inv.setInventorySlotContents( num, null );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileInscriber(ByteBuf data) throws IOException
|
||||
{
|
||||
int slot = smash ? 64 : 0;
|
||||
|
||||
for (int num = 0; num < inv.getSizeInventory(); num++)
|
||||
{
|
||||
if ( inv.getStackInSlot( num ) != null )
|
||||
slot = slot | (1 << num);
|
||||
}
|
||||
|
||||
data.writeByte( slot );
|
||||
for (int num = 0; num < inv.getSizeInventory(); num++)
|
||||
{
|
||||
if ( (slot & (1 << num)) > 0 )
|
||||
{
|
||||
AEItemStack st = AEItemStack.create( inv.getStackInSlot( num ) );
|
||||
st.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public TileInscriber() {
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
internalMaxPower = 1500;
|
||||
gridProxy.setIdlePowerUsage( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) );
|
||||
setPowerSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection d)
|
||||
{
|
||||
if ( d == ForgeDirection.UP )
|
||||
return top;
|
||||
|
||||
if ( d == ForgeDirection.DOWN )
|
||||
return bottom;
|
||||
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( smash )
|
||||
return false;
|
||||
|
||||
if ( i == 0 || i == 1 )
|
||||
{
|
||||
if ( AEApi.instance().materials().materialNamePress.sameAsStack( itemstack ) )
|
||||
return true;
|
||||
|
||||
for (ItemStack s : Inscribe.plates)
|
||||
if ( Platform.isSameItemPrecise( s, itemstack ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( i == 2 )
|
||||
{
|
||||
return true;
|
||||
// for (ItemStack s : Inscribe.inputs)
|
||||
// if ( Platform.isSameItemPrecise( s, itemstack ) )
|
||||
// return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
if ( smash )
|
||||
return false;
|
||||
|
||||
return i == 0 || i == 1 || i == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( mc != InvOperation.markDirty )
|
||||
{
|
||||
if ( slot != 3 )
|
||||
processingTime = 0;
|
||||
|
||||
if ( !smash )
|
||||
markForUpdate();
|
||||
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public InscriberRecipe getTask()
|
||||
{
|
||||
ItemStack PlateA = getStackInSlot( 0 );
|
||||
ItemStack PlateB = getStackInSlot( 1 );
|
||||
ItemStack renamedItem = getStackInSlot( 2 );
|
||||
|
||||
if ( PlateA != null && PlateA.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
if ( PlateB != null && PlateB.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
if ( renamedItem != null && renamedItem.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
boolean isNameA = AEApi.instance().materials().materialNamePress.sameAsStack( PlateA );
|
||||
boolean isNameB = AEApi.instance().materials().materialNamePress.sameAsStack( PlateB );
|
||||
|
||||
if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) )
|
||||
{
|
||||
if ( renamedItem != null )
|
||||
{
|
||||
String name = "";
|
||||
|
||||
if ( PlateA != null )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( PlateA );
|
||||
name += tag.getString( "InscribeName" );
|
||||
}
|
||||
|
||||
if ( PlateB != null )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( PlateB );
|
||||
if ( name.length() > 0 )
|
||||
name += " ";
|
||||
name += tag.getString( "InscribeName" );
|
||||
}
|
||||
|
||||
ItemStack startingItem = renamedItem.copy();
|
||||
renamedItem = renamedItem.copy();
|
||||
NBTTagCompound tag = Platform.openNbtData( renamedItem );
|
||||
|
||||
NBTTagCompound display = tag.getCompoundTag( "display" );
|
||||
tag.setTag( "display", display );
|
||||
|
||||
if ( name.length() > 0 )
|
||||
display.setString( "Name", name );
|
||||
else
|
||||
display.removeTag( "Name" );
|
||||
|
||||
return new InscriberRecipe( new ItemStack[] { startingItem }, PlateA, PlateB, renamedItem, false );
|
||||
}
|
||||
}
|
||||
|
||||
for (InscriberRecipe i : Inscribe.recipes)
|
||||
{
|
||||
|
||||
boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and...
|
||||
(PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB ));
|
||||
|
||||
boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and...
|
||||
(PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB ));
|
||||
|
||||
if ( matchA || matchB )
|
||||
{
|
||||
for (ItemStack option : i.imprintable)
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( option, getStackInSlot( 2 ) ) )
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasWork()
|
||||
{
|
||||
if ( getTask() != null )
|
||||
return true;
|
||||
|
||||
processingTime = 0;
|
||||
return false || smash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !hasWork(), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( smash )
|
||||
{
|
||||
finalStep++;
|
||||
if ( finalStep == 8 )
|
||||
{
|
||||
|
||||
InscriberRecipe out = getTask();
|
||||
if ( out != null )
|
||||
{
|
||||
ItemStack is = out.output.copy();
|
||||
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN );
|
||||
|
||||
if ( ad.addItems( is ) == null )
|
||||
{
|
||||
processingTime = 0;
|
||||
if ( out.usePlates )
|
||||
{
|
||||
setInventorySlotContents( 0, null );
|
||||
setInventorySlotContents( 1, null );
|
||||
}
|
||||
setInventorySlotContents( 2, null );
|
||||
}
|
||||
}
|
||||
|
||||
markDirty();
|
||||
|
||||
}
|
||||
else if ( finalStep == 16 )
|
||||
{
|
||||
finalStep = 0;
|
||||
smash = false;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IEnergyGrid eg;
|
||||
try
|
||||
{
|
||||
eg = gridProxy.getEnergy();
|
||||
IEnergySource src = this;
|
||||
|
||||
double powerReq = extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
|
||||
if ( powerReq <= 9.99 )
|
||||
{
|
||||
src = eg;
|
||||
powerReq = eg.extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
}
|
||||
|
||||
if ( powerReq > 9.99 )
|
||||
{
|
||||
src.extractAEPower( 10, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
|
||||
if ( processingTime == 0 )
|
||||
processingTime++;
|
||||
else
|
||||
processingTime += TicksSinceLastCall;
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
if ( processingTime > maxProcessingTime )
|
||||
{
|
||||
processingTime = maxProcessingTime;
|
||||
InscriberRecipe out = getTask();
|
||||
if ( out != null )
|
||||
{
|
||||
ItemStack is = out.output.copy();
|
||||
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN );
|
||||
if ( ad.simulateAdd( is ) == null )
|
||||
{
|
||||
smash = true;
|
||||
finalStep = 0;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable,
|
||||
IInventoryDestination, IInterfaceHost, IConfigurableObject, IPriorityHost
|
||||
{
|
||||
|
||||
ForgeDirection pointAt = ForgeDirection.UNKNOWN;
|
||||
DualityInterface duality = new DualityInterface( gridProxy, this );
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(MENetworkChannelsChanged c)
|
||||
{
|
||||
duality.notifyNeightbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(MENetworkPowerStatusChange c)
|
||||
{
|
||||
duality.notifyNeightbors();
|
||||
}
|
||||
|
||||
public void setSide(ForgeDirection axis)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return;
|
||||
|
||||
if ( pointAt == axis.getOpposite() )
|
||||
pointAt = axis;
|
||||
else if ( pointAt == axis || pointAt == axis.getOpposite() )
|
||||
pointAt = ForgeDirection.UNKNOWN;
|
||||
else if ( pointAt == ForgeDirection.UNKNOWN )
|
||||
pointAt = axis.getOpposite();
|
||||
else
|
||||
pointAt = Platform.rotateAround( pointAt, axis );
|
||||
|
||||
if ( ForgeDirection.UNKNOWN == pointAt )
|
||||
setOrientation( pointAt, pointAt );
|
||||
else
|
||||
setOrientation( pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP, pointAt.getOpposite() );
|
||||
|
||||
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) );
|
||||
markForUpdate();
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
{
|
||||
duality.addDrops( drops );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
duality.gridChanged();
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileInterface(NBTTagCompound data)
|
||||
{
|
||||
data.setInteger( "pointAt", pointAt.ordinal() );
|
||||
duality.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileInterface(NBTTagCompound data)
|
||||
{
|
||||
int val = data.getInteger( "pointAt" );
|
||||
|
||||
if ( val >= 0 && val < ForgeDirection.values().length )
|
||||
pointAt = ForgeDirection.values()[val];
|
||||
else
|
||||
pointAt = ForgeDirection.UNKNOWN;
|
||||
|
||||
duality.readFromNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) );
|
||||
super.onReady();
|
||||
duality.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return duality.getCableConnectionType( dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return duality.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
return duality.canInsert( stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return duality.getItemInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return duality.getFluidInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
return duality.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return duality.getTickingRequest( node );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return duality.tickingRequest( node, TicksSinceLastCall );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return duality.getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
duality.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
duality.onChangeInventory( inv, slot, mc, removed, added );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
{
|
||||
return duality.getAccessibleSlotsFromSide( side.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality()
|
||||
{
|
||||
return duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
|
||||
{
|
||||
return duality.getMonitorable( side, src, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table)
|
||||
{
|
||||
return duality.pushPattern( patternDetails, table );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(ICraftingProviderHelper craftingTracker)
|
||||
{
|
||||
duality.provideCrafting( craftingTracker );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getTargets()
|
||||
{
|
||||
if ( pointAt == null || pointAt == ForgeDirection.UNKNOWN )
|
||||
return EnumSet.complementOf( EnumSet.of( ForgeDirection.UNKNOWN ) );
|
||||
return EnumSet.of( pointAt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return duality.isBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return duality.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return duality.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode)
|
||||
{
|
||||
return duality.injectCraftedItems( link, items, mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link)
|
||||
{
|
||||
duality.jobStateChange( link );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int newValue)
|
||||
{
|
||||
duality.setPriority( newValue );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileLightDetector extends AEBaseTile
|
||||
{
|
||||
|
||||
int lastCheck = 30;
|
||||
int lastLight = 0;
|
||||
|
||||
public boolean isReady()
|
||||
{
|
||||
return lastLight > 0;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.TICK)
|
||||
public void Tick_TileLightDetector()
|
||||
{
|
||||
lastCheck++;
|
||||
if ( lastCheck > 30 )
|
||||
{
|
||||
lastCheck = 0;
|
||||
updateLight();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLight()
|
||||
{
|
||||
int val = worldObj.getBlockLightValue( xCoord, yCoord, zCoord );
|
||||
|
||||
if ( lastLight != val )
|
||||
{
|
||||
lastLight = val;
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.helpers.Splot;
|
||||
import appeng.items.misc.ItemPaintBall;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class TilePaint extends AEBaseTile
|
||||
{
|
||||
|
||||
static final int LIGHT_PER_DOT = 12;
|
||||
|
||||
int isLit = 0;
|
||||
ArrayList<Splot> dots = null;
|
||||
|
||||
void writeBuffer(ByteBuf out)
|
||||
{
|
||||
if ( dots == null )
|
||||
{
|
||||
out.writeByte( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeByte( dots.size() );
|
||||
|
||||
for (Splot s : dots)
|
||||
s.writeToStream( out );
|
||||
}
|
||||
|
||||
void readBuffer(ByteBuf in)
|
||||
{
|
||||
byte howMany = in.readByte();
|
||||
|
||||
if ( howMany == 0 )
|
||||
{
|
||||
isLit = 0;
|
||||
dots = null;
|
||||
return;
|
||||
}
|
||||
|
||||
dots = new ArrayList( howMany );
|
||||
for (int x = 0; x < howMany; x++)
|
||||
dots.add( new Splot( in ) );
|
||||
|
||||
isLit = 0;
|
||||
for (Splot s : dots)
|
||||
{
|
||||
if ( s.lumen )
|
||||
{
|
||||
isLit += LIGHT_PER_DOT;
|
||||
}
|
||||
}
|
||||
|
||||
maxLit();
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TilePaint(NBTTagCompound data)
|
||||
{
|
||||
ByteBuf myDat = Unpooled.buffer();
|
||||
writeBuffer( myDat );
|
||||
if ( myDat.hasArray() )
|
||||
data.setByteArray( "dots", myDat.array() );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TilePaint(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "dots" ) )
|
||||
readBuffer( Unpooled.copiedBuffer( data.getByteArray( "dots" ) ) );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TilePaint(ByteBuf data) throws IOException
|
||||
{
|
||||
writeBuffer( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TilePaint(ByteBuf data) throws IOException
|
||||
{
|
||||
readBuffer( data );
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange()
|
||||
{
|
||||
if ( dots == null )
|
||||
return;
|
||||
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if ( !isSideValid( side ) )
|
||||
removeSide( side );
|
||||
}
|
||||
|
||||
updateData();
|
||||
}
|
||||
|
||||
private void updateData()
|
||||
{
|
||||
isLit = 0;
|
||||
for (Splot s : dots)
|
||||
{
|
||||
if ( s.lumen )
|
||||
{
|
||||
isLit += LIGHT_PER_DOT;
|
||||
}
|
||||
}
|
||||
|
||||
maxLit();
|
||||
|
||||
if ( dots.isEmpty() )
|
||||
dots = null;
|
||||
|
||||
if ( dots == null )
|
||||
worldObj.setBlock( xCoord, yCoord, zCoord, Blocks.air );
|
||||
}
|
||||
|
||||
public void cleanSide(ForgeDirection side)
|
||||
{
|
||||
if ( dots == null )
|
||||
return;
|
||||
|
||||
removeSide( side );
|
||||
|
||||
updateData();
|
||||
}
|
||||
|
||||
public boolean isSideValid(ForgeDirection side)
|
||||
{
|
||||
Block blk = worldObj.getBlock( xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ );
|
||||
return blk.isSideSolid( worldObj, xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ, side.getOpposite() );
|
||||
}
|
||||
|
||||
private void removeSide(ForgeDirection side)
|
||||
{
|
||||
Iterator<Splot> i = dots.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
Splot s = i.next();
|
||||
if ( s.side == side )
|
||||
i.remove();
|
||||
}
|
||||
|
||||
markForUpdate();
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public int getLightLevel()
|
||||
{
|
||||
return isLit;
|
||||
}
|
||||
|
||||
public void addBlot(ItemStack type, ForgeDirection side, Vec3 hitVec)
|
||||
{
|
||||
Block blk = worldObj.getBlock( xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ );
|
||||
if ( blk.isSideSolid( worldObj, xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ, side.getOpposite() ) )
|
||||
{
|
||||
ItemPaintBall ipb = (ItemPaintBall) type.getItem();
|
||||
|
||||
AEColor col = ipb.getColor( type );
|
||||
boolean lit = ipb.isLumen( type );
|
||||
|
||||
if ( dots == null )
|
||||
dots = new ArrayList();
|
||||
|
||||
if ( dots.size() > 20 )
|
||||
dots.remove( 0 );
|
||||
|
||||
dots.add( new Splot( col, lit, side, hitVec ) );
|
||||
if ( lit )
|
||||
isLit += LIGHT_PER_DOT;
|
||||
|
||||
maxLit();
|
||||
markForUpdate();
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void maxLit()
|
||||
{
|
||||
if ( isLit > 14 )
|
||||
isLit = 14;
|
||||
|
||||
if ( worldObj != null )
|
||||
worldObj.updateLightByType( EnumSkyBlock.Block, xCoord, yCoord, zCoord );
|
||||
}
|
||||
|
||||
public Collection<Splot> getDots()
|
||||
{
|
||||
if ( dots == null )
|
||||
return ImmutableList.of();
|
||||
|
||||
return dots;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.tiles.ICrystalGrowthAccelerator;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState, ICrystalGrowthAccelerator
|
||||
{
|
||||
|
||||
public boolean hasPower = false;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPower(MENetworkPowerStatusChange ch)
|
||||
{
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileQuartzGrowthAccelerator(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean hadPower = hasPower;
|
||||
hasPower = data.readBoolean();
|
||||
return hasPower != hadPower;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileQuartzGrowthAccelerator(ByteBuf data) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
data.writeBoolean( gridProxy.getEnergy().isNetworkPowered() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
data.writeBoolean( false );
|
||||
}
|
||||
}
|
||||
|
||||
public TileQuartzGrowthAccelerator() {
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
gridProxy.setFlags();
|
||||
gridProxy.setIdlePowerUsage( 8 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
gridProxy.setValidSides( EnumSet.of( getUp(), getUp().getOpposite() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return gridProxy.getEnergy().isNetworkPowered();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return isPowered();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import appeng.helpers.PlayerSecurityWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
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.implementations.tiles.IColorableTile;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.events.MENetworkSecurityChange;
|
||||
import appeng.api.networking.security.ISecurityProvider;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.MEMonitorHandler;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.SecurityInventory;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile
|
||||
{
|
||||
|
||||
private static int difference = 0;
|
||||
private IConfigManager cm = new ConfigManager( this );
|
||||
|
||||
private SecurityInventory inventory = new SecurityInventory( this );
|
||||
private MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<IAEItemStack>( inventory );
|
||||
|
||||
private boolean isActive = false;
|
||||
|
||||
AEColor paintedColor = AEColor.Transparent;
|
||||
public long securityKey;
|
||||
|
||||
public AppEngInternalInventory configSlot = new AppEngInternalInventory( this, 1 );
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
{
|
||||
if ( !configSlot.isEmpty() )
|
||||
drops.add( configSlot.getStackInSlot( 0 ) );
|
||||
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
drops.add( ais.getItemStack() );
|
||||
}
|
||||
|
||||
IMEInventoryHandler<IAEItemStack> getSecurityInventory()
|
||||
{
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
super.invalidate();
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) );
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileSecurity(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean wasActive = isActive;
|
||||
isActive = data.readBoolean();
|
||||
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
return oldPaintedColor != paintedColor || wasActive != isActive;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileSecurity(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( gridProxy.isActive() );
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileSecurity(NBTTagCompound data)
|
||||
{
|
||||
cm.writeToNBT( data );
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
|
||||
data.setLong( "securityKey", securityKey );
|
||||
configSlot.writeToNBT( data, "config" );
|
||||
|
||||
NBTTagCompound storedItems = new NBTTagCompound();
|
||||
|
||||
int offset = 0;
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
NBTTagCompound it = new NBTTagCompound();
|
||||
ais.getItemStack().writeToNBT( it );
|
||||
storedItems.setTag( "" + (offset++), it );
|
||||
}
|
||||
|
||||
data.setTag( "storedItems", storedItems );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileSecurity(NBTTagCompound data)
|
||||
{
|
||||
cm.readFromNBT( data );
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
|
||||
securityKey = data.getLong( "securityKey" );
|
||||
configSlot.readFromNBT( data, "config" );
|
||||
|
||||
NBTTagCompound storedItems = data.getCompoundTag( "storedItems" );
|
||||
for (Object key : storedItems.func_150296_c())
|
||||
{
|
||||
NBTBase obj = storedItems.getTag( (String) key );
|
||||
if ( obj instanceof NBTTagCompound )
|
||||
{
|
||||
inventory.storedItems.add( AEItemStack.create( ItemStack.loadItemStackFromNBT( (NBTTagCompound) obj ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inventoryChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
saveChanges();
|
||||
gridProxy.getGrid().postEvent( new MENetworkSecurityChange() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public void readPermissions(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms)
|
||||
{
|
||||
IPlayerRegistry pr = AEApi.instance().registries().players();
|
||||
|
||||
// read permissions
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
Item i = is.getItem();
|
||||
if ( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
bc.registerPermissions( new PlayerSecurityWrapper( playerPerms ), pr, is );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure thea admin is Boss.
|
||||
playerPerms.put( gridProxy.getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootUpdate(MENetworkChannelsChanged changed)
|
||||
{
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerUpdate(MENetworkPowerStatusChange changed)
|
||||
{
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
public boolean isSecurityEnabled()
|
||||
{
|
||||
return isActive && gridProxy.isActive();
|
||||
}
|
||||
|
||||
public TileSecurity() {
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
gridProxy.setIdlePowerUsage( 2.0 );
|
||||
difference++;
|
||||
|
||||
securityKey = System.currentTimeMillis() * 10 + difference;
|
||||
if ( difference > 10 )
|
||||
difference = 0;
|
||||
|
||||
cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
public int getOwner()
|
||||
{
|
||||
return gridProxy.getNode().getPlayerID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return securityMonitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLocatableSerial()
|
||||
{
|
||||
return securityKey;
|
||||
}
|
||||
|
||||
public boolean isPowered()
|
||||
{
|
||||
return gridProxy.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSecurityKey()
|
||||
{
|
||||
return securityKey;
|
||||
}
|
||||
|
||||
public AEColor getColor()
|
||||
{
|
||||
return paintedColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who)
|
||||
{
|
||||
if ( paintedColor == newPaintedColor )
|
||||
return false;
|
||||
|
||||
paintedColor = newPaintedColor;
|
||||
markDirty();
|
||||
markForUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
public class TileSkyCompass extends AEBaseTile
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package appeng.tile.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable
|
||||
{
|
||||
|
||||
final double powerPerTick = 5;
|
||||
|
||||
final int sides[] = new int[] { 0 };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
|
||||
|
||||
public int burnSpeed = 100;
|
||||
public double burnTime = 0;
|
||||
public double maxBurnTime = 0;
|
||||
|
||||
// client side..
|
||||
public boolean isOn;
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileVibrationChamber(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean wasOn = isOn;
|
||||
isOn = data.readBoolean();
|
||||
return wasOn != isOn; // TESR doesn't need updates!
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileVibrationChamber(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( burnTime > 0 );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileVibrationChamber(NBTTagCompound data)
|
||||
{
|
||||
data.setDouble( "burnTime", burnTime );
|
||||
data.setDouble( "maxBurnTime", maxBurnTime );
|
||||
data.setInteger( "burnSpeed", burnSpeed );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileVibrationChamber(NBTTagCompound data)
|
||||
{
|
||||
burnTime = data.getDouble( "burnTime" );
|
||||
maxBurnTime = data.getDouble( "maxBurnTime" );
|
||||
burnSpeed = data.getInteger( "burnSpeed" );
|
||||
}
|
||||
|
||||
public TileVibrationChamber() {
|
||||
gridProxy.setIdlePowerUsage( 0 );
|
||||
gridProxy.setFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
if ( burnTime <= 0 )
|
||||
{
|
||||
if ( canEatFuel() )
|
||||
{
|
||||
try
|
||||
{
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// wake up!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return TileEntityFurnace.getItemBurnTime( itemstack ) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
if ( burnTime <= 0 )
|
||||
eatFuel();
|
||||
|
||||
return new TickingRequest( TickRates.VibrationChamber.min, TickRates.VibrationChamber.max, burnTime <= 0, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( burnTime <= 0 )
|
||||
{
|
||||
eatFuel();
|
||||
|
||||
if ( burnTime > 0 )
|
||||
return TickRateModulation.URGENT;
|
||||
|
||||
burnSpeed = 100;
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) );
|
||||
double dialiation = burnSpeed / 100.0;
|
||||
|
||||
double timePassed = (double) TicksSinceLastCall * dialiation;
|
||||
burnTime -= timePassed;
|
||||
if ( burnTime < 0 )
|
||||
{
|
||||
timePassed += burnTime;
|
||||
burnTime = 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid grid = gridProxy.getEnergy();
|
||||
double newPower = timePassed * powerPerTick;
|
||||
double overFlow = grid.injectPower( newPower, Actionable.SIMULATE );
|
||||
|
||||
// burn the over flow.
|
||||
grid.injectPower( Math.max( 0.0, newPower - overFlow ), Actionable.MODULATE );
|
||||
|
||||
if ( overFlow > 0 )
|
||||
burnSpeed -= TicksSinceLastCall;
|
||||
else
|
||||
burnSpeed += TicksSinceLastCall;
|
||||
|
||||
burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) );
|
||||
return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
burnSpeed -= TicksSinceLastCall;
|
||||
burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) );
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canEatFuel()
|
||||
{
|
||||
ItemStack is = getStackInSlot( 0 );
|
||||
if ( is != null )
|
||||
{
|
||||
int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
|
||||
if ( newBurnTime > 0 && is.stackSize > 0 )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void eatFuel()
|
||||
{
|
||||
ItemStack is = getStackInSlot( 0 );
|
||||
if ( is != null )
|
||||
{
|
||||
int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
|
||||
if ( newBurnTime > 0 && is.stackSize > 0 )
|
||||
{
|
||||
burnTime += newBurnTime;
|
||||
maxBurnTime = burnTime;
|
||||
is.stackSize--;
|
||||
if ( is.stackSize <= 0 )
|
||||
{
|
||||
ItemStack container = null;
|
||||
|
||||
if ( is.getItem().hasContainerItem( is ) )
|
||||
container = is.getItem().getContainerItem( is );
|
||||
|
||||
setInventorySlotContents( 0, container );
|
||||
}
|
||||
else
|
||||
setInventorySlotContents( 0, is );
|
||||
}
|
||||
}
|
||||
|
||||
if ( burnTime > 0 )
|
||||
{
|
||||
try
|
||||
{
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// gah!
|
||||
}
|
||||
}
|
||||
|
||||
if ( (!isOn && burnTime > 0) || (isOn && burnTime <= 0) )
|
||||
{
|
||||
isOn = burnTime > 0;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user