reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
@@ -19,12 +19,6 @@
package appeng.tile.misc;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
@@ -40,166 +34,142 @@ import appeng.me.helpers.BaseActionSource;
import appeng.me.storage.ITickingMonitor;
import appeng.util.item.AEItemStack;
import appeng.util.item.ItemList;
import net.minecraft.item.ItemStack;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
class CondenserItemInventory implements IMEMonitor<IAEItemStack>, ITickingMonitor
{
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
private final TileCondenser target;
private boolean hasChanged = true;
private final ItemList cachedList = new ItemList();
private IActionSource actionSource = new BaseActionSource();
private ItemList changeSet = new ItemList();
class CondenserItemInventory implements IMEMonitor<IAEItemStack>, ITickingMonitor {
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
private final TileCondenser target;
private boolean hasChanged = true;
private final ItemList cachedList = new ItemList();
private IActionSource actionSource = new BaseActionSource();
private ItemList changeSet = new ItemList();
CondenserItemInventory( final TileCondenser te )
{
this.target = te;
}
CondenserItemInventory(final TileCondenser te) {
this.target = te;
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
{
if( mode == Actionable.MODULATE && input != null )
{
this.target.addPower( input.getStackSize() );
}
return null;
}
@Override
public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final IActionSource src) {
if (mode == Actionable.MODULATE && input != null) {
this.target.addPower(input.getStackSize());
}
return null;
}
@Override
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
{
AEItemStack ret = null;
ItemStack slotItem = this.target.getOutputSlot().getStackInSlot( 0 );
if( !slotItem.isEmpty() && request.isSameType( slotItem ) )
{
int count = (int) Math.min( request.getStackSize(), Integer.MAX_VALUE );
ret = AEItemStack.fromItemStack( this.target.getOutputSlot().extractItem( 0, count, mode == Actionable.SIMULATE ) );
}
return ret;
}
@Override
public IAEItemStack extractItems(final IAEItemStack request, final Actionable mode, final IActionSource src) {
AEItemStack ret = null;
ItemStack slotItem = this.target.getOutputSlot().getStackInSlot(0);
if (!slotItem.isEmpty() && request.isSameType(slotItem)) {
int count = (int) Math.min(request.getStackSize(), Integer.MAX_VALUE);
ret = AEItemStack.fromItemStack(this.target.getOutputSlot().extractItem(0, count, mode == Actionable.SIMULATE));
}
return ret;
}
@Override
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
{
if( !this.target.getOutputSlot().getStackInSlot( 0 ).isEmpty() )
{
out.add( AEItemStack.fromItemStack( this.target.getOutputSlot().getStackInSlot( 0 ) ) );
}
return out;
}
@Override
public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out) {
if (!this.target.getOutputSlot().getStackInSlot(0).isEmpty()) {
out.add(AEItemStack.fromItemStack(this.target.getOutputSlot().getStackInSlot(0)));
}
return out;
}
@Override
public IItemList<IAEItemStack> getStorageList()
{
if( this.hasChanged )
{
this.hasChanged = false;
this.cachedList.resetStatus();
return this.getAvailableItems( this.cachedList );
}
return this.cachedList;
}
@Override
public IItemList<IAEItemStack> getStorageList() {
if (this.hasChanged) {
this.hasChanged = false;
this.cachedList.resetStatus();
return this.getAvailableItems(this.cachedList);
}
return this.cachedList;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public AccessRestriction getAccess()
{
return AccessRestriction.READ_WRITE;
}
@Override
public AccessRestriction getAccess() {
return AccessRestriction.READ_WRITE;
}
@Override
public boolean isPrioritized( final IAEItemStack input )
{
return false;
}
@Override
public boolean isPrioritized(final IAEItemStack input) {
return false;
}
@Override
public boolean canAccept( final IAEItemStack input )
{
return true;
}
@Override
public boolean canAccept(final IAEItemStack input) {
return true;
}
@Override
public int getPriority()
{
return 0;
}
@Override
public int getPriority() {
return 0;
}
@Override
public int getSlot()
{
return 0;
}
@Override
public int getSlot() {
return 0;
}
@Override
public boolean validForPass( final int i )
{
return i == 2;
}
@Override
public boolean validForPass(final int i) {
return i == 2;
}
@Override
public void addListener( final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken )
{
this.listeners.put( l, verificationToken );
}
@Override
public void addListener(final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken) {
this.listeners.put(l, verificationToken);
}
@Override
public void removeListener( final IMEMonitorHandlerReceiver<IAEItemStack> l )
{
this.listeners.remove( l );
}
@Override
public void removeListener(final IMEMonitorHandlerReceiver<IAEItemStack> l) {
this.listeners.remove(l);
}
public void updateOutput( ItemStack added, ItemStack removed )
{
this.hasChanged = true;
if( !added.isEmpty() )
{
this.changeSet.add( AEItemStack.fromItemStack( added ) );
}
if( !removed.isEmpty() )
{
this.changeSet.add( AEItemStack.fromItemStack( removed ).setStackSize( -removed.getCount() ) );
}
}
public void updateOutput(ItemStack added, ItemStack removed) {
this.hasChanged = true;
if (!added.isEmpty()) {
this.changeSet.add(AEItemStack.fromItemStack(added));
}
if (!removed.isEmpty()) {
this.changeSet.add(AEItemStack.fromItemStack(removed).setStackSize(-removed.getCount()));
}
}
@Override
public TickRateModulation onTick()
{
final ItemList currentChanges = this.changeSet;
@Override
public TickRateModulation onTick() {
final ItemList currentChanges = this.changeSet;
if( currentChanges.isEmpty() )
{
return TickRateModulation.IDLE;
}
if (currentChanges.isEmpty()) {
return TickRateModulation.IDLE;
}
this.changeSet = new ItemList();
final Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
while( i.hasNext() )
{
final Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
if( key.isValid( l.getValue() ) )
{
key.postChange( this, currentChanges, this.actionSource );
}
else
{
i.remove();
}
}
this.changeSet = new ItemList();
final Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
while (i.hasNext()) {
final Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
if (key.isValid(l.getValue())) {
key.postChange(this, currentChanges, this.actionSource);
} else {
i.remove();
}
}
return TickRateModulation.URGENT;
}
return TickRateModulation.URGENT;
}
@Override
public void setActionSource( IActionSource actionSource )
{
this.actionSource = actionSource;
}
@Override
public void setActionSource(IActionSource actionSource) {
this.actionSource = actionSource;
}
}
@@ -29,102 +29,85 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
class CondenserVoidInventory<T extends IAEStack<T>> implements IMEMonitor<T>
{
class CondenserVoidInventory<T extends IAEStack<T>> implements IMEMonitor<T> {
private final TileCondenser target;
private final IStorageChannel<T> channel;
private final TileCondenser target;
private final IStorageChannel<T> channel;
CondenserVoidInventory( final TileCondenser te, final IStorageChannel<T> channel )
{
this.target = te;
this.channel = channel;
}
CondenserVoidInventory(final TileCondenser te, final IStorageChannel<T> channel) {
this.target = te;
this.channel = channel;
}
@Override
public T injectItems( final T input, final Actionable mode, final IActionSource src )
{
if( mode == Actionable.SIMULATE )
{
return null;
}
@Override
public T injectItems(final T input, final Actionable mode, final IActionSource src) {
if (mode == Actionable.SIMULATE) {
return null;
}
if( input != null )
{
this.target.addPower( input.getStackSize() / (double) this.channel.transferFactor() );
}
return null;
}
if (input != null) {
this.target.addPower(input.getStackSize() / (double) this.channel.transferFactor());
}
return null;
}
@Override
public T extractItems( final T request, final Actionable mode, final IActionSource src )
{
return null;
}
@Override
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
return null;
}
@Override
public IItemList<T> getAvailableItems( final IItemList<T> out )
{
return out;
}
@Override
public IItemList<T> getAvailableItems(final IItemList<T> out) {
return out;
}
@Override
public IItemList<T> getStorageList()
{
return this.channel.createList();
}
@Override
public IItemList<T> getStorageList() {
return this.channel.createList();
}
@Override
public IStorageChannel<T> getChannel()
{
return this.channel;
}
@Override
public IStorageChannel<T> getChannel() {
return this.channel;
}
@Override
public AccessRestriction getAccess()
{
return AccessRestriction.WRITE;
}
@Override
public AccessRestriction getAccess() {
return AccessRestriction.WRITE;
}
@Override
public boolean isPrioritized( final T input )
{
return false;
}
@Override
public boolean isPrioritized(final T input) {
return false;
}
@Override
public boolean canAccept( final T input )
{
return true;
}
@Override
public boolean canAccept(final T input) {
return true;
}
@Override
public int getPriority()
{
return 0;
}
@Override
public int getPriority() {
return 0;
}
@Override
public int getSlot()
{
return 0;
}
@Override
public int getSlot() {
return 0;
}
@Override
public boolean validForPass( final int i )
{
return i == 2;
}
@Override
public boolean validForPass(final int i) {
return i == 2;
}
@Override
public void addListener( IMEMonitorHandlerReceiver<T> l, Object verificationToken )
{
// Not implemented since the Condenser automatically voids everything, and there are no updates
}
@Override
public void addListener(IMEMonitorHandlerReceiver<T> l, Object verificationToken) {
// Not implemented since the Condenser automatically voids everything, and there are no updates
}
@Override
public void removeListener( IMEMonitorHandlerReceiver<T> l )
{
// Not implemented since we don't remember registered listeners anyway
}
@Override
public void removeListener(IMEMonitorHandlerReceiver<T> l) {
// Not implemented since we don't remember registered listeners anyway
}
}
@@ -19,14 +19,6 @@
package appeng.tile.misc;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.CopyMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
@@ -41,216 +33,183 @@ import appeng.util.IConfigManagerHost;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, IAEAppEngInventory, IConfigManagerHost
{
public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, IAEAppEngInventory, IConfigManagerHost {
private final AppEngInternalInventory cell = new AppEngInternalInventory( this, 1 );
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 63 );
private final ConfigManager manager = new ConfigManager( this );
private final AppEngInternalInventory cell = new AppEngInternalInventory(this, 1);
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 63);
private final ConfigManager manager = new ConfigManager(this);
private IItemHandler cacheUpgrades = null;
private IItemHandler cacheConfig = null;
private boolean locked = false;
private IItemHandler cacheUpgrades = null;
private IItemHandler cacheConfig = null;
private boolean locked = false;
public TileCellWorkbench()
{
this.manager.registerSetting( Settings.COPY_MODE, CopyMode.CLEAR_ON_REMOVE );
this.cell.setEnableClientEvents( true );
}
public TileCellWorkbench() {
this.manager.registerSetting(Settings.COPY_MODE, CopyMode.CLEAR_ON_REMOVE);
this.cell.setEnableClientEvents(true);
}
public IItemHandler getCellUpgradeInventory()
{
if( this.cacheUpgrades == null )
{
final ICellWorkbenchItem cell = this.getCell();
if( cell == null )
{
return null;
}
public IItemHandler getCellUpgradeInventory() {
if (this.cacheUpgrades == null) {
final ICellWorkbenchItem cell = this.getCell();
if (cell == null) {
return null;
}
final ItemStack is = this.cell.getStackInSlot( 0 );
if( is.isEmpty() )
{
return null;
}
final ItemStack is = this.cell.getStackInSlot(0);
if (is.isEmpty()) {
return null;
}
final IItemHandler inv = cell.getUpgradesInventory( is );
if( inv == null )
{
return null;
}
final IItemHandler inv = cell.getUpgradesInventory(is);
if (inv == null) {
return null;
}
return this.cacheUpgrades = inv;
}
return this.cacheUpgrades;
}
return this.cacheUpgrades = inv;
}
return this.cacheUpgrades;
}
public ICellWorkbenchItem getCell()
{
if( this.cell.getStackInSlot( 0 ).isEmpty() )
{
return null;
}
public ICellWorkbenchItem getCell() {
if (this.cell.getStackInSlot(0).isEmpty()) {
return null;
}
if( this.cell.getStackInSlot( 0 ).getItem() instanceof ICellWorkbenchItem )
{
return( (ICellWorkbenchItem) this.cell.getStackInSlot( 0 ).getItem() );
}
if (this.cell.getStackInSlot(0).getItem() instanceof ICellWorkbenchItem) {
return ((ICellWorkbenchItem) this.cell.getStackInSlot(0).getItem());
}
return null;
}
return null;
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.cell.writeToNBT( data, "cell" );
this.config.writeToNBT( data, "config" );
this.manager.writeToNBT( data );
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.cell.writeToNBT(data, "cell");
this.config.writeToNBT(data, "config");
this.manager.writeToNBT(data);
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.cell.readFromNBT( data, "cell" );
this.config.readFromNBT( data, "config" );
this.manager.readFromNBT( data );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.cell.readFromNBT(data, "cell");
this.config.readFromNBT(data, "config");
this.manager.readFromNBT(data);
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
return this.config;
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
if( name.equals( "cell" ) )
{
return this.cell;
}
if (name.equals("cell")) {
return this.cell;
}
return null;
}
return null;
}
@Override
public int getInstalledUpgrades( final Upgrades u )
{
return 0;
}
@Override
public int getInstalledUpgrades(final Upgrades u) {
return 0;
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.cell && !this.locked )
{
this.locked = true;
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.cell && !this.locked) {
this.locked = true;
this.cacheUpgrades = null;
this.cacheConfig = null;
this.cacheUpgrades = null;
this.cacheConfig = null;
final IItemHandler configInventory = this.getCellConfigInventory();
if( configInventory != null )
{
boolean cellHasConfig = false;
for( int x = 0; x < configInventory.getSlots(); x++ )
{
if( !configInventory.getStackInSlot( x ).isEmpty() )
{
cellHasConfig = true;
break;
}
}
final IItemHandler configInventory = this.getCellConfigInventory();
if (configInventory != null) {
boolean cellHasConfig = false;
for (int x = 0; x < configInventory.getSlots(); x++) {
if (!configInventory.getStackInSlot(x).isEmpty()) {
cellHasConfig = true;
break;
}
}
if( cellHasConfig )
{
for( int x = 0; x < this.config.getSlots(); x++ )
{
this.config.setStackInSlot( x, configInventory.getStackInSlot( x ) );
}
}
else
{
ItemHandlerUtil.copy( this.config, configInventory, false );
}
}
else if( this.manager.getSetting( Settings.COPY_MODE ) == CopyMode.CLEAR_ON_REMOVE )
{
for( int x = 0; x < this.config.getSlots(); x++ )
{
this.config.setStackInSlot( x, ItemStack.EMPTY );
}
if (cellHasConfig) {
for (int x = 0; x < this.config.getSlots(); x++) {
this.config.setStackInSlot(x, configInventory.getStackInSlot(x));
}
} else {
ItemHandlerUtil.copy(this.config, configInventory, false);
}
} else if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.CLEAR_ON_REMOVE) {
for (int x = 0; x < this.config.getSlots(); x++) {
this.config.setStackInSlot(x, ItemStack.EMPTY);
}
this.saveChanges();
}
this.saveChanges();
}
this.locked = false;
}
else if( inv == this.config && !this.locked )
{
this.locked = true;
final IItemHandler c = this.getCellConfigInventory();
if( c != null )
{
ItemHandlerUtil.copy( this.config, c, false );
// copy items back. The ConfigInventory may changed the items on insert
ItemHandlerUtil.copy( c, this.config, false );
}
this.locked = false;
}
}
this.locked = false;
} else if (inv == this.config && !this.locked) {
this.locked = true;
final IItemHandler c = this.getCellConfigInventory();
if (c != null) {
ItemHandlerUtil.copy(this.config, c, false);
// copy items back. The ConfigInventory may changed the items on insert
ItemHandlerUtil.copy(c, this.config, false);
}
this.locked = false;
}
}
private IItemHandler getCellConfigInventory()
{
if( this.cacheConfig == null )
{
final ICellWorkbenchItem cell = this.getCell();
if( cell == null )
{
return null;
}
private IItemHandler getCellConfigInventory() {
if (this.cacheConfig == null) {
final ICellWorkbenchItem cell = this.getCell();
if (cell == null) {
return null;
}
final ItemStack is = this.cell.getStackInSlot( 0 );
if( is.isEmpty() )
{
return null;
}
final ItemStack is = this.cell.getStackInSlot(0);
if (is.isEmpty()) {
return null;
}
final IItemHandler inv = cell.getConfigInventory( is );
if( inv == null )
{
return null;
}
final IItemHandler inv = cell.getConfigInventory(is);
if (inv == null) {
return null;
}
this.cacheConfig = inv;
}
return this.cacheConfig;
}
this.cacheConfig = inv;
}
return this.cacheConfig;
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
super.getDrops( w, pos, drops );
@Override
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
super.getDrops(w, pos, drops);
if( this.cell.getStackInSlot( 0 ) != null )
{
drops.add( this.cell.getStackInSlot( 0 ) );
}
}
if (this.cell.getStackInSlot(0) != null) {
drops.add(this.cell.getStackInSlot(0));
}
}
@Override
public IConfigManager getConfigManager()
{
return this.manager;
}
@Override
public IConfigManager getConfigManager() {
return this.manager;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
// nothing here..
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
// nothing here..
}
}
+187 -243
View File
@@ -19,27 +19,10 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.util.item.OreHelper;
import appeng.util.item.OreReference;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.PowerUnits;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.implementations.tiles.ICrankable;
@@ -51,6 +34,8 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.settings.TickRates;
import appeng.me.GridAccessException;
import appeng.tile.grid.AENetworkPowerTile;
@@ -59,273 +44,232 @@ import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
public class TileCharger extends AENetworkPowerTile implements ICrankable, IGridTickable
{
private static final int POWER_MAXIMUM_AMOUNT = 1600;
private static final int POWER_THRESHOLD = POWER_MAXIMUM_AMOUNT - 1;
private static final int POWER_PER_CRANK_TURN = 160;
public class TileCharger extends AENetworkPowerTile implements ICrankable, IGridTickable {
private static final int POWER_MAXIMUM_AMOUNT = 1600;
private static final int POWER_THRESHOLD = POWER_MAXIMUM_AMOUNT - 1;
private static final int POWER_PER_CRANK_TURN = 160;
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1, 1, new ChargerInvFilter() );
private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 1, 1, new ChargerInvFilter());
public TileCharger()
{
this.getProxy().setValidSides( EnumSet.noneOf( EnumFacing.class ) );
this.getProxy().setFlags();
this.setInternalMaxPower( POWER_MAXIMUM_AMOUNT );
this.getProxy().setIdlePowerUsage( 0 );
}
public TileCharger() {
this.getProxy().setValidSides(EnumSet.noneOf(EnumFacing.class));
this.getProxy().setFlags();
this.setInternalMaxPower(POWER_MAXIMUM_AMOUNT);
this.getProxy().setIdlePowerUsage(0);
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.COVERED;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.COVERED;
}
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
try
{
final IAEItemStack item = AEItemStack.fromPacket( data );
final ItemStack is = item.createItemStack();
this.inv.setStackInSlot( 0, is );
}
catch( final Throwable t )
{
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
}
return c; // TESR doesn't need updates!
}
@Override
protected boolean readFromStream(final ByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
try {
final IAEItemStack item = AEItemStack.fromPacket(data);
final ItemStack is = item.createItemStack();
this.inv.setStackInSlot(0, is);
} catch (final Throwable t) {
this.inv.setStackInSlot(0, ItemStack.EMPTY);
}
return c; // TESR doesn't need updates!
}
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
final AEItemStack is = AEItemStack.fromItemStack( this.inv.getStackInSlot( 0 ) );
if( is != null )
{
is.writeToPacket( data );
}
}
@Override
protected void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
final AEItemStack is = AEItemStack.fromItemStack(this.inv.getStackInSlot(0));
if (is != null) {
is.writeToPacket(data);
}
}
@Override
public void setOrientation( final EnumFacing inForward, final EnumFacing inUp )
{
super.setOrientation( inForward, inUp );
this.getProxy().setValidSides( EnumSet.of( this.getUp(), this.getUp().getOpposite() ) );
this.setPowerSides( EnumSet.of( this.getUp(), this.getUp().getOpposite() ) );
}
@Override
public void setOrientation(final EnumFacing inForward, final EnumFacing inUp) {
super.setOrientation(inForward, inUp);
this.getProxy().setValidSides(EnumSet.of(this.getUp(), this.getUp().getOpposite()));
this.setPowerSides(EnumSet.of(this.getUp(), this.getUp().getOpposite()));
}
@Override
public boolean requiresTESR()
{
return true;
}
@Override
public boolean requiresTESR() {
return true;
}
@Override
public boolean canTurn()
{
return this.getInternalCurrentPower() < this.getInternalMaxPower();
}
@Override
public boolean canTurn() {
return this.getInternalCurrentPower() < this.getInternalMaxPower();
}
@Override
public void applyTurn()
{
this.injectExternalPower( PowerUnits.AE, POWER_PER_CRANK_TURN, Actionable.MODULATE );
@Override
public void applyTurn() {
this.injectExternalPower(PowerUnits.AE, POWER_PER_CRANK_TURN, Actionable.MODULATE);
final ItemStack myItem = this.inv.getStackInSlot( 0 );
if( this.getInternalCurrentPower() > POWER_THRESHOLD )
{
final IMaterials materials = AEApi.instance().definitions().materials();
final ItemStack myItem = this.inv.getStackInSlot(0);
if (this.getInternalCurrentPower() > POWER_THRESHOLD) {
final IMaterials materials = AEApi.instance().definitions().materials();
if( materials.certusQuartzCrystal().isSameAs( myItem ) )
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );
if (materials.certusQuartzCrystal().isSameAs(myItem)) {
this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG);
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
}
}
}
materials.certusQuartzCrystalCharged().maybeStack(myItem.getCount()).ifPresent(charged -> this.inv.setStackInSlot(0, charged));
}
}
}
@Override
public boolean canCrankAttach( final EnumFacing directionToCrank )
{
return this.getUp() == directionToCrank || this.getUp().getOpposite() == directionToCrank;
}
@Override
public boolean canCrankAttach(final EnumFacing directionToCrank) {
return this.getUp() == directionToCrank || this.getUp().getOpposite() == directionToCrank;
}
@Override
public IItemHandler getInternalInventory()
{
return this.inv;
}
@Override
public IItemHandler getInternalInventory() {
return this.inv;
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
try
{
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// :P
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added) {
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
this.markForUpdate();
}
this.markForUpdate();
}
public void activate( final EntityPlayer player )
{
if( !Platform.hasPermissions( new DimensionalCoord( this ), player ) )
{
return;
}
public void activate(final EntityPlayer player) {
if (!Platform.hasPermissions(new DimensionalCoord(this), player)) {
return;
}
final ItemStack myItem = this.inv.getStackInSlot( 0 );
if( myItem.isEmpty() )
{
ItemStack held = player.inventory.getCurrentItem();
if( !held.isEmpty() )
{
if( AEConfig.instance().isFeatureEnabled( AEFeature.CERTUS ) )
{
final IMaterials materials = AEApi.instance().definitions().materials();
if( AEItemStack.fromItemStack( held ).sameOre( AEItemStack.fromItemStack( materials.certusQuartzCrystal().maybeStack( 1 ).orElse( ItemStack.EMPTY ) ) ) || Platform.isChargeable( held ) )
{
held = player.inventory.decrStackSize( player.inventory.currentItem, 1 );
this.inv.setStackInSlot( 0, held );
}
}
}
}
else
{
final List<ItemStack> drops = new ArrayList<>();
drops.add( myItem );
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
Platform.spawnDrops( this.world, this.pos.offset( this.getForward() ), drops );
}
}
final ItemStack myItem = this.inv.getStackInSlot(0);
if (myItem.isEmpty()) {
ItemStack held = player.inventory.getCurrentItem();
if (!held.isEmpty()) {
if (AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS)) {
final IMaterials materials = AEApi.instance().definitions().materials();
if (AEItemStack.fromItemStack(held).sameOre(AEItemStack.fromItemStack(materials.certusQuartzCrystal().maybeStack(1).orElse(ItemStack.EMPTY))) || Platform.isChargeable(held)) {
held = player.inventory.decrStackSize(player.inventory.currentItem, 1);
this.inv.setStackInSlot(0, held);
}
}
}
} else {
final List<ItemStack> drops = new ArrayList<>();
drops.add(myItem);
this.inv.setStackInSlot(0, ItemStack.EMPTY);
Platform.spawnDrops(this.world, this.pos.offset(this.getForward()), drops);
}
}
@Override
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.Charger.getMin(), TickRates.Charger.getMin(), false, true );
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.Charger.getMin(), TickRates.Charger.getMin(), false, true);
}
@Override
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
{
return this.doWork() ? TickRateModulation.FASTER : TickRateModulation.SLEEP;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
return this.doWork() ? TickRateModulation.FASTER : TickRateModulation.SLEEP;
}
private boolean doWork()
{
final ItemStack myItem = this.inv.getStackInSlot( 0 );
boolean changed = false;
private boolean doWork() {
final ItemStack myItem = this.inv.getStackInSlot(0);
boolean changed = false;
if( !myItem.isEmpty() )
{
final IMaterials materials = AEApi.instance().definitions().materials();
if (!myItem.isEmpty()) {
final IMaterials materials = AEApi.instance().definitions().materials();
if( Platform.isChargeable( myItem ) )
{
final IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
if (Platform.isChargeable(myItem)) {
final IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
if( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) )
{
final double chargeRate = AEApi.instance().registries().charger().getChargeRate( myItem.getItem() );
if (ps.getAEMaxPower(myItem) > ps.getAECurrentPower(myItem)) {
final double chargeRate = AEApi.instance().registries().charger().getChargeRate(myItem.getItem());
double extractedAmount = this.extractAEPower( chargeRate, Actionable.MODULATE, PowerMultiplier.CONFIG );
double extractedAmount = this.extractAEPower(chargeRate, Actionable.MODULATE, PowerMultiplier.CONFIG);
final double missingChargeRate = chargeRate - extractedAmount;
final double missingAEPower = ps.getAEMaxPower( myItem ) - ps.getAECurrentPower( myItem );
final double toExtract = Math.min( missingChargeRate, missingAEPower );
final double missingChargeRate = chargeRate - extractedAmount;
final double missingAEPower = ps.getAEMaxPower(myItem) - ps.getAECurrentPower(myItem);
final double toExtract = Math.min(missingChargeRate, missingAEPower);
try
{
extractedAmount += this.getProxy().getEnergy().extractAEPower( toExtract, Actionable.MODULATE, PowerMultiplier.ONE );
}
catch( GridAccessException e1 )
{
// Ignore.
}
try {
extractedAmount += this.getProxy().getEnergy().extractAEPower(toExtract, Actionable.MODULATE, PowerMultiplier.ONE);
} catch (GridAccessException e1) {
// Ignore.
}
if( extractedAmount > 0 )
{
final double adjustment = ps.injectAEPower( myItem, extractedAmount, Actionable.MODULATE );
if (extractedAmount > 0) {
final double adjustment = ps.injectAEPower(myItem, extractedAmount, Actionable.MODULATE);
this.setInternalCurrentPower( this.getInternalCurrentPower() + adjustment );
this.setInternalCurrentPower(this.getInternalCurrentPower() + adjustment);
changed = true;
}
}
}
else if( this.getInternalCurrentPower() > POWER_THRESHOLD && ( materials.certusQuartzCrystal().isSameAs( myItem ) || AEItemStack.fromItemStack( myItem ).sameOre( AEItemStack.fromItemStack( materials.certusQuartzCrystal().maybeStack( 1 ).orElse( ItemStack.EMPTY ) ) ) ) )
{
if( Platform.getRandomFloat() > 0.8f ) // simulate wait
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );
changed = true;
}
}
} else if (this.getInternalCurrentPower() > POWER_THRESHOLD && (materials.certusQuartzCrystal().isSameAs(myItem) || AEItemStack.fromItemStack(myItem).sameOre(AEItemStack.fromItemStack(materials.certusQuartzCrystal().maybeStack(1).orElse(ItemStack.EMPTY))))) {
if (Platform.getRandomFloat() > 0.8f) // simulate wait
{
this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG);
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
materials.certusQuartzCrystalCharged().maybeStack(myItem.getCount()).ifPresent(charged -> this.inv.setStackInSlot(0, charged));
changed = true;
}
}
}
changed = true;
}
}
}
// charge from the network!
if( this.getInternalCurrentPower() < POWER_THRESHOLD )
{
try
{
final double toExtract = Math.min( 800.0, this.getInternalMaxPower() - this.getInternalCurrentPower() );
final double extracted = this.getProxy().getEnergy().extractAEPower( toExtract, Actionable.MODULATE, PowerMultiplier.ONE );
// charge from the network!
if (this.getInternalCurrentPower() < POWER_THRESHOLD) {
try {
final double toExtract = Math.min(800.0, this.getInternalMaxPower() - this.getInternalCurrentPower());
final double extracted = this.getProxy().getEnergy().extractAEPower(toExtract, Actionable.MODULATE, PowerMultiplier.ONE);
this.injectExternalPower( PowerUnits.AE, extracted, Actionable.MODULATE );
}
catch( final GridAccessException e )
{
// continue!
}
this.injectExternalPower(PowerUnits.AE, extracted, Actionable.MODULATE);
} catch (final GridAccessException e) {
// continue!
}
changed = true;
}
changed = true;
}
if( changed )
{
this.markForUpdate();
}
if (changed) {
this.markForUpdate();
}
return true;
}
return true;
}
private class ChargerInvFilter implements IAEItemFilter
{
@Override
public boolean allowInsert( IItemHandler inv, final int i, final ItemStack itemstack )
{
return AEItemStack.fromItemStack( itemstack ).sameOre( AEItemStack.fromItemStack( AEApi.instance().definitions().materials().certusQuartzCrystal().maybeStack( 1 ).orElse( ItemStack.EMPTY ) ) ) || Platform.isChargeable( itemstack );
}
private class ChargerInvFilter implements IAEItemFilter {
@Override
public boolean allowInsert(IItemHandler inv, final int i, final ItemStack itemstack) {
return AEItemStack.fromItemStack(itemstack).sameOre(AEItemStack.fromItemStack(AEApi.instance().definitions().materials().certusQuartzCrystal().maybeStack(1).orElse(ItemStack.EMPTY))) || Platform.isChargeable(itemstack);
}
@Override
public boolean allowExtract( IItemHandler inv, final int slotIndex, int amount )
{
ItemStack extractedItem = inv.getStackInSlot( slotIndex );
@Override
public boolean allowExtract(IItemHandler inv, final int slotIndex, int amount) {
ItemStack extractedItem = inv.getStackInSlot(slotIndex);
if( Platform.isChargeable( extractedItem ) )
{
final IAEItemPowerStorage ips = (IAEItemPowerStorage) extractedItem.getItem();
if( ips.getAECurrentPower( extractedItem ) >= ips.getAEMaxPower( extractedItem ) )
{
return true;
}
}
if (Platform.isChargeable(extractedItem)) {
final IAEItemPowerStorage ips = (IAEItemPowerStorage) extractedItem.getItem();
if (ips.getAECurrentPower(extractedItem) >= ips.getAEMaxPower(extractedItem)) {
return true;
}
}
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( extractedItem );
}
}
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs(extractedItem);
}
}
}
+239 -302
View File
@@ -19,21 +19,6 @@
package appeng.tile.misc;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
@@ -59,337 +44,289 @@ import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperChainedItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.filter.AEItemFilters;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, IConfigurableObject
{
public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, IConfigurableObject {
public static final int BYTE_MULTIPLIER = 8;
public static final int BYTE_MULTIPLIER = 8;
private final ConfigManager cm = new ConfigManager( this );
private final ConfigManager cm = new ConfigManager(this);
private final AppEngInternalInventory outputSlot = new AppEngInternalInventory( this, 1 );
private final AppEngInternalInventory storageSlot = new AppEngInternalInventory( this, 1 );
private final IItemHandler inputSlot = new CondenseItemHandler();
private final IFluidHandler fluidHandler = new FluidHandler();
private final MEHandler meHandler = new MEHandler();
private final AppEngInternalInventory outputSlot = new AppEngInternalInventory(this, 1);
private final AppEngInternalInventory storageSlot = new AppEngInternalInventory(this, 1);
private final IItemHandler inputSlot = new CondenseItemHandler();
private final IFluidHandler fluidHandler = new FluidHandler();
private final MEHandler meHandler = new MEHandler();
private final IItemHandler externalInv = new WrapperChainedItemHandler( this.inputSlot, new WrapperFilteredItemHandler( this.outputSlot, AEItemFilters.EXTRACT_ONLY ) );
private final IItemHandler combinedInv = new WrapperChainedItemHandler( this.inputSlot, this.outputSlot, this.storageSlot );
private final IItemHandler externalInv = new WrapperChainedItemHandler(this.inputSlot, new WrapperFilteredItemHandler(this.outputSlot, AEItemFilters.EXTRACT_ONLY));
private final IItemHandler combinedInv = new WrapperChainedItemHandler(this.inputSlot, this.outputSlot, this.storageSlot);
private double storedPower = 0;
private double storedPower = 0;
public TileCondenser()
{
this.cm.registerSetting( Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH );
}
public TileCondenser() {
this.cm.registerSetting(Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH);
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.cm.writeToNBT( data );
data.setDouble( "storedPower", this.getStoredPower() );
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.cm.writeToNBT(data);
data.setDouble("storedPower", this.getStoredPower());
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.cm.readFromNBT( data );
this.setStoredPower( data.getDouble( "storedPower" ) );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.cm.readFromNBT(data);
this.setStoredPower(data.getDouble("storedPower"));
}
public double getStorage()
{
final ItemStack is = this.storageSlot.getStackInSlot( 0 );
if( !is.isEmpty() )
{
if( is.getItem() instanceof IStorageComponent )
{
final IStorageComponent sc = (IStorageComponent) is.getItem();
if( sc.isStorageComponent( is ) )
{
return sc.getBytes( is ) * BYTE_MULTIPLIER;
}
}
}
return 0;
}
public double getStorage() {
final ItemStack is = this.storageSlot.getStackInSlot(0);
if (!is.isEmpty()) {
if (is.getItem() instanceof IStorageComponent) {
final IStorageComponent sc = (IStorageComponent) is.getItem();
if (sc.isStorageComponent(is)) {
return sc.getBytes(is) * BYTE_MULTIPLIER;
}
}
}
return 0;
}
public void addPower( final double rawPower )
{
this.setStoredPower( this.getStoredPower() + rawPower );
this.setStoredPower( Math.max( 0.0, Math.min( this.getStorage(), this.getStoredPower() ) ) );
public void addPower(final double rawPower) {
this.setStoredPower(this.getStoredPower() + rawPower);
this.setStoredPower(Math.max(0.0, Math.min(this.getStorage(), this.getStoredPower())));
final double requiredPower = this.getRequiredPower();
final ItemStack output = this.getOutput();
while ( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 )
{
if( this.canAddOutput( output ) )
{
this.setStoredPower( this.getStoredPower() - requiredPower );
this.addOutput( output );
}
else
{
break;
}
}
}
final double requiredPower = this.getRequiredPower();
final ItemStack output = this.getOutput();
while (requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0) {
if (this.canAddOutput(output)) {
this.setStoredPower(this.getStoredPower() - requiredPower);
this.addOutput(output);
} else {
break;
}
}
}
private boolean canAddOutput( final ItemStack output )
{
return this.outputSlot.insertItem( 0, output, true ).isEmpty();
}
private boolean canAddOutput(final ItemStack output) {
return this.outputSlot.insertItem(0, output, true).isEmpty();
}
/**
* make sure you validate with canAddOutput prior to this.
*
* @param output to be added output
*/
private void addOutput( final ItemStack output )
{
this.outputSlot.insertItem( 0, output, false );
}
/**
* make sure you validate with canAddOutput prior to this.
*
* @param output to be added output
*/
private void addOutput(final ItemStack output) {
this.outputSlot.insertItem(0, output, false);
}
IItemHandler getOutputSlot()
{
return this.outputSlot;
}
IItemHandler getOutputSlot() {
return this.outputSlot;
}
private ItemStack getOutput()
{
final IMaterials materials = AEApi.instance().definitions().materials();
private ItemStack getOutput() {
final IMaterials materials = AEApi.instance().definitions().materials();
switch ( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) )
{
case MATTER_BALLS:
return materials.matterBall().maybeStack( 1 ).orElse( ItemStack.EMPTY );
switch ((CondenserOutput) this.cm.getSetting(Settings.CONDENSER_OUTPUT)) {
case MATTER_BALLS:
return materials.matterBall().maybeStack(1).orElse(ItemStack.EMPTY);
case SINGULARITY:
return materials.singularity().maybeStack( 1 ).orElse( ItemStack.EMPTY );
case SINGULARITY:
return materials.singularity().maybeStack(1).orElse(ItemStack.EMPTY);
case TRASH:
default:
return ItemStack.EMPTY;
}
}
case TRASH:
default:
return ItemStack.EMPTY;
}
}
public double getRequiredPower()
{
return ( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) ).requiredPower;
}
public double getRequiredPower() {
return ((CondenserOutput) this.cm.getSetting(Settings.CONDENSER_OUTPUT)).requiredPower;
}
@Override
public IItemHandler getInternalInventory()
{
return this.combinedInv;
}
@Override
public IItemHandler getInternalInventory() {
return this.combinedInv;
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( inv == this.outputSlot )
{
if( !removed.isEmpty() )
{
final double requiredPower = this.getRequiredPower();
final ItemStack output = this.getOutput();
while ( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 )
{
if( this.canAddOutput( output ) )
{
this.setStoredPower( this.getStoredPower() - requiredPower );
this.addOutput( output );
}
else
{
break;
}
removed.shrink( output.getCount() );
}
}
this.meHandler.outputChanged( added, removed );
}
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added) {
if (inv == this.outputSlot) {
if (!removed.isEmpty()) {
final double requiredPower = this.getRequiredPower();
final ItemStack output = this.getOutput();
while (requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0) {
if (this.canAddOutput(output)) {
this.setStoredPower(this.getStoredPower() - requiredPower);
this.addOutput(output);
} else {
break;
}
removed.shrink(output.getCount());
}
}
this.meHandler.outputChanged(added, removed);
}
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
this.addPower( 0 );
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
this.addPower(0);
}
@Override
public IConfigManager getConfigManager()
{
return this.cm;
}
@Override
public IConfigManager getConfigManager() {
return this.cm;
}
public double getStoredPower()
{
return this.storedPower;
}
public double getStoredPower() {
return this.storedPower;
}
private void setStoredPower( final double storedPower )
{
this.storedPower = storedPower;
}
private void setStoredPower(final double storedPower) {
this.storedPower = storedPower;
}
@Override
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
{
if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return true;
}
else if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR )
{
return true;
}
return super.hasCapability( capability, facing );
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
} else if (capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR) {
return true;
}
return super.hasCapability(capability, facing);
}
@SuppressWarnings( "unchecked" )
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return (T) this.externalInv;
}
else if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return (T) this.fluidHandler;
}
else if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR )
{
return (T) this.meHandler;
}
return super.getCapability( capability, facing );
}
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (T) this.externalInv;
} else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T) this.fluidHandler;
} else if (capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR) {
return (T) this.meHandler;
}
return super.getCapability(capability, facing);
}
private class CondenseItemHandler implements IItemHandler
{
private class CondenseItemHandler implements IItemHandler {
@Override
public int getSlots()
{
// We only expose the void slot
return 1;
}
@Override
public int getSlots() {
// We only expose the void slot
return 1;
}
@Override
public ItemStack getStackInSlot( int slot )
{
// The void slot never has any content
return ItemStack.EMPTY;
}
@Override
public ItemStack getStackInSlot(int slot) {
// The void slot never has any content
return ItemStack.EMPTY;
}
@Override
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
{
if( slot != 0 )
{
return stack;
}
if( !simulate && !stack.isEmpty() )
{
TileCondenser.this.addPower( stack.getCount() );
}
return ItemStack.EMPTY;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (slot != 0) {
return stack;
}
if (!simulate && !stack.isEmpty()) {
TileCondenser.this.addPower(stack.getCount());
}
return ItemStack.EMPTY;
}
@Override
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
return ItemStack.EMPTY;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
return ItemStack.EMPTY;
}
@Override
public int getSlotLimit( int slot )
{
return 64;
}
}
@Override
public int getSlotLimit(int slot) {
return 64;
}
}
private static final IFluidTankProperties[] EMPTY = {new FluidTankProperties( null, Fluid.BUCKET_VOLUME, true, false )};
private static final IFluidTankProperties[] EMPTY = {new FluidTankProperties(null, Fluid.BUCKET_VOLUME, true, false)};
/**
* A fluid handler that exposes a 1 bucket tank that can only be filled, and - when filled - will add power
* to this condenser.
*/
private class FluidHandler implements IFluidHandler
{
/**
* A fluid handler that exposes a 1 bucket tank that can only be filled, and - when filled - will add power
* to this condenser.
*/
private class FluidHandler implements IFluidHandler {
@Override
public IFluidTankProperties[] getTankProperties()
{
return EMPTY;
}
@Override
public IFluidTankProperties[] getTankProperties() {
return EMPTY;
}
@Override
public int fill( FluidStack resource, boolean doFill )
{
if( doFill )
{
final IStorageChannel<IAEFluidStack> chan = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
TileCondenser.this.addPower( ( resource == null ? 0.0 : (double) resource.amount ) / chan.transferFactor() );
}
@Override
public int fill(FluidStack resource, boolean doFill) {
if (doFill) {
final IStorageChannel<IAEFluidStack> chan = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
TileCondenser.this.addPower((resource == null ? 0.0 : (double) resource.amount) / chan.transferFactor());
}
return resource == null ? 0 : resource.amount;
}
return resource == null ? 0 : resource.amount;
}
@Nullable
@Override
public FluidStack drain( FluidStack resource, boolean doDrain )
{
return null;
}
@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
return null;
}
@Nullable
@Override
public FluidStack drain( int maxDrain, boolean doDrain )
{
return null;
}
}
@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
return null;
}
}
/**
* This is used to expose a fake ME subnetwork that is only composed of this condenser tile. The purpose of this is
* to enable the condenser to
* override the {@link appeng.api.storage.IMEInventoryHandler#validForPass(int)} method to make sure a condenser is
* only ever used if an item
* can't go anywhere else.
*/
private class MEHandler implements IStorageMonitorableAccessor, IStorageMonitorable
{
private final CondenserItemInventory itemInventory = new CondenserItemInventory( TileCondenser.this );
/**
* This is used to expose a fake ME subnetwork that is only composed of this condenser tile. The purpose of this is
* to enable the condenser to
* override the {@link appeng.api.storage.IMEInventoryHandler#validForPass(int)} method to make sure a condenser is
* only ever used if an item
* can't go anywhere else.
*/
private class MEHandler implements IStorageMonitorableAccessor, IStorageMonitorable {
private final CondenserItemInventory itemInventory = new CondenserItemInventory(TileCondenser.this);
void outputChanged( ItemStack added, ItemStack removed )
{
this.itemInventory.updateOutput( added, removed );
}
void outputChanged(ItemStack added, ItemStack removed) {
this.itemInventory.updateOutput(added, removed);
}
@Nullable
@Override
public IStorageMonitorable getInventory( IActionSource src )
{
return this;
}
@Nullable
@Override
public IStorageMonitorable getInventory(IActionSource src) {
return this;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
return (IMEMonitor<T>) this.itemInventory;
}
else
{
return new CondenserVoidInventory<>( TileCondenser.this, channel );
}
}
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
return (IMEMonitor<T>) this.itemInventory;
} else {
return new CondenserVoidInventory<>(TileCondenser.this, channel);
}
}
}
}
File diff suppressed because it is too large Load Diff
+216 -275
View File
@@ -19,26 +19,6 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
@@ -65,306 +45,267 @@ import appeng.tile.grid.AENetworkInvTile;
import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.InvOperation;
import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
public class TileInterface extends AENetworkInvTile implements IGridTickable, IInventoryDestination, IInterfaceHost, IPriorityHost
{
public class TileInterface extends AENetworkInvTile implements IGridTickable, IInventoryDestination, IInterfaceHost, IPriorityHost {
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
private final DualityInterface duality = new DualityInterface(this.getProxy(), this);
// Indicates that this interface has no specific direction set
private boolean omniDirectional = true;
// Indicates that this interface has no specific direction set
private boolean omniDirectional = true;
@MENetworkEventSubscribe
public void stateChange( final MENetworkChannelsChanged c )
{
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange( final MENetworkPowerStatusChange c )
{
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
this.duality.notifyNeighbors();
}
public void setSide( final EnumFacing facing )
{
if( Platform.isClient() )
{
return;
}
public void setSide(final EnumFacing facing) {
if (Platform.isClient()) {
return;
}
EnumFacing newForward = facing;
EnumFacing newForward = facing;
if( !this.omniDirectional && this.getForward() == facing.getOpposite() )
{
newForward = facing;
}
else if( !this.omniDirectional && ( this.getForward() == facing || this.getForward() == facing.getOpposite() ) )
{
this.omniDirectional = true;
}
else if( this.omniDirectional )
{
newForward = facing.getOpposite();
this.omniDirectional = false;
}
else
{
newForward = Platform.rotateAround( this.getForward(), facing );
}
if (!this.omniDirectional && this.getForward() == facing.getOpposite()) {
newForward = facing;
} else if (!this.omniDirectional && (this.getForward() == facing || this.getForward() == facing.getOpposite())) {
this.omniDirectional = true;
} else if (this.omniDirectional) {
newForward = facing.getOpposite();
this.omniDirectional = false;
} else {
newForward = Platform.rotateAround(this.getForward(), facing);
}
if( this.omniDirectional )
{
this.setOrientation( EnumFacing.NORTH, EnumFacing.UP );
}
else
{
EnumFacing newUp = EnumFacing.UP;
if( newForward == EnumFacing.UP || newForward == EnumFacing.DOWN )
{
newUp = EnumFacing.NORTH;
}
this.setOrientation( newForward, newUp );
}
if (this.omniDirectional) {
this.setOrientation(EnumFacing.NORTH, EnumFacing.UP);
} else {
EnumFacing newUp = EnumFacing.UP;
if (newForward == EnumFacing.UP || newForward == EnumFacing.DOWN) {
newUp = EnumFacing.NORTH;
}
this.setOrientation(newForward, newUp);
}
this.configureNodeSides();
this.markForUpdate();
this.saveChanges();
}
this.configureNodeSides();
this.markForUpdate();
this.saveChanges();
}
private void configureNodeSides()
{
if( this.omniDirectional )
{
this.getProxy().setValidSides( EnumSet.allOf( EnumFacing.class ) );
}
else
{
this.getProxy().setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
}
}
private void configureNodeSides() {
if (this.omniDirectional) {
this.getProxy().setValidSides(EnumSet.allOf(EnumFacing.class));
} else {
this.getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(this.getForward())));
}
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
this.duality.addDrops( drops );
}
@Override
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
this.duality.addDrops(drops);
}
@Override
public void gridChanged()
{
this.duality.gridChanged();
}
@Override
public void gridChanged() {
this.duality.gridChanged();
}
@Override
public void onReady()
{
this.configureNodeSides();
@Override
public void onReady() {
this.configureNodeSides();
super.onReady();
this.duality.initialize();
this.getProxy().setIdlePowerUsage( Math.pow( 4, ( this.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION ) ) ) );
}
super.onReady();
this.duality.initialize();
this.getProxy().setIdlePowerUsage(Math.pow(4, (this.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION))));
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setBoolean( "omniDirectional", this.omniDirectional );
this.duality.writeToNBT( data );
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
data.setBoolean("omniDirectional", this.omniDirectional);
this.duality.writeToNBT(data);
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.omniDirectional = data.getBoolean( "omniDirectional" );
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.omniDirectional = data.getBoolean("omniDirectional");
this.duality.readFromNBT( data );
}
this.duality.readFromNBT(data);
}
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
boolean oldOmniDirectional = this.omniDirectional;
this.omniDirectional = data.readBoolean();
return oldOmniDirectional != this.omniDirectional || c;
}
@Override
protected boolean readFromStream(final ByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
boolean oldOmniDirectional = this.omniDirectional;
this.omniDirectional = data.readBoolean();
return oldOmniDirectional != this.omniDirectional || c;
}
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
data.writeBoolean( this.omniDirectional );
}
@Override
protected void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
data.writeBoolean(this.omniDirectional);
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return this.duality.getCableConnectionType( dir );
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return this.duality.getCableConnectionType(dir);
}
@Override
public DimensionalCoord getLocation()
{
return this.duality.getLocation();
}
@Override
public DimensionalCoord getLocation() {
return this.duality.getLocation();
}
@Override
public boolean canInsert( final ItemStack stack )
{
return this.duality.canInsert( stack );
}
@Override
public boolean canInsert(final ItemStack stack) {
return this.duality.canInsert(stack);
}
@Override
public IItemHandler getInventoryByName( final String name )
{
return this.duality.getInventoryByName( name );
}
@Override
public IItemHandler getInventoryByName(final String name) {
return this.duality.getInventoryByName(name);
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return this.duality.getTickingRequest( node );
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return this.duality.getTickingRequest(node);
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.duality.tickingRequest( node, ticksSinceLastCall );
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.duality.tickingRequest(node, ticksSinceLastCall);
}
@Override
public IItemHandler getInternalInventory()
{
return this.duality.getInternalInventory();
}
@Override
public IItemHandler getInternalInventory() {
return this.duality.getInternalInventory();
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
this.duality.onChangeInventory( inv, slot, mc, removed, added );
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added) {
this.duality.onChangeInventory(inv, slot, mc, removed, added);
}
@Override
public DualityInterface getInterfaceDuality()
{
return this.duality;
}
@Override
public DualityInterface getInterfaceDuality() {
return this.duality;
}
@Override
public EnumSet<EnumFacing> getTargets()
{
if( this.omniDirectional )
{
return EnumSet.allOf( EnumFacing.class );
}
return EnumSet.of( this.getForward() );
}
@Override
public EnumSet<EnumFacing> getTargets() {
if (this.omniDirectional) {
return EnumSet.allOf(EnumFacing.class);
}
return EnumSet.of(this.getForward());
}
@Override
public TileEntity getTileEntity()
{
return this;
}
@Override
public TileEntity getTileEntity() {
return this;
}
@Override
public IConfigManager getConfigManager()
{
return this.duality.getConfigManager();
}
@Override
public IConfigManager getConfigManager() {
return this.duality.getConfigManager();
}
@Override
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
{
return this.duality.pushPattern( patternDetails, table );
}
@Override
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
return this.duality.pushPattern(patternDetails, table);
}
@Override
public boolean isBusy()
{
return this.duality.isBusy();
}
@Override
public boolean isBusy() {
return this.duality.isBusy();
}
@Override
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
{
this.duality.provideCrafting( craftingTracker );
}
@Override
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
this.duality.provideCrafting(craftingTracker);
}
@Override
public int getInstalledUpgrades( final Upgrades u )
{
return this.duality.getInstalledUpgrades( u );
}
@Override
public int getInstalledUpgrades(final Upgrades u) {
return this.duality.getInstalledUpgrades(u);
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs()
{
return this.duality.getRequestedJobs();
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return this.duality.getRequestedJobs();
}
@Override
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
{
return this.duality.injectCraftedItems( link, items, mode );
}
@Override
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
return this.duality.injectCraftedItems(link, items, mode);
}
@Override
public void jobStateChange( final ICraftingLink link )
{
this.duality.jobStateChange( link );
}
@Override
public void jobStateChange(final ICraftingLink link) {
this.duality.jobStateChange(link);
}
@Override
public int getPriority()
{
return this.duality.getPriority();
}
@Override
public int getPriority() {
return this.duality.getPriority();
}
@Override
public void setPriority( final int newValue )
{
this.duality.setPriority( newValue );
}
@Override
public void setPriority(final int newValue) {
this.duality.setPriority(newValue);
}
/**
* @return True if this interface is omni-directional.
*/
public boolean isOmniDirectional()
{
return this.omniDirectional;
}
/**
* @return True if this interface is omni-directional.
*/
public boolean isOmniDirectional() {
return this.omniDirectional;
}
@Override
public boolean hasCapability( Capability<?> capability, @Nullable EnumFacing facing )
{
return this.duality.hasCapability( capability, facing ) || super.hasCapability( capability, facing );
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
return this.duality.hasCapability(capability, facing) || super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
T result = this.duality.getCapability( capability, facing );
if( result != null )
{
return result;
}
return super.getCapability( capability, facing );
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
T result = this.duality.getCapability(capability, facing);
if (result != null) {
return result;
}
return super.getCapability(capability, facing);
}
@Override
public ItemStack getItemStackRepresentation()
{
return AEApi.instance().definitions().blocks().iface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().blocks().iface().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public GuiBridge getGuiBridge()
{
return GuiBridge.GUI_INTERFACE;
}
@Override
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_INTERFACE;
}
}
@@ -19,48 +19,40 @@
package appeng.tile.misc;
import net.minecraft.util.ITickable;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
import net.minecraft.util.ITickable;
public class TileLightDetector extends AEBaseTile implements ITickable
{
public class TileLightDetector extends AEBaseTile implements ITickable {
private int lastCheck = 30;
private int lastLight = 0;
private int lastCheck = 30;
private int lastLight = 0;
public boolean isReady()
{
return this.lastLight > 0;
}
public boolean isReady() {
return this.lastLight > 0;
}
@Override
public void update()
{
this.lastCheck++;
if( this.lastCheck > 30 )
{
this.lastCheck = 0;
this.updateLight();
}
}
@Override
public void update() {
this.lastCheck++;
if (this.lastCheck > 30) {
this.lastCheck = 0;
this.updateLight();
}
}
public void updateLight()
{
final int val = this.world.getLight( this.pos );
public void updateLight() {
final int val = this.world.getLight(this.pos);
if( this.lastLight != val )
{
this.lastLight = val;
Platform.notifyBlocksOfNeighbors( this.world, this.pos );
}
}
if (this.lastLight != val) {
this.lastLight = val;
Platform.notifyBlocksOfNeighbors(this.world, this.pos);
}
}
@Override
public boolean canBeRotated()
{
return false;
}
@Override
public boolean canBeRotated() {
return false;
}
}
+159 -207
View File
@@ -19,16 +19,12 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import appeng.api.util.AEColor;
import appeng.helpers.Splotch;
import appeng.items.misc.ItemPaintBall;
import appeng.tile.AEBaseTile;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -37,245 +33,201 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.EnumSkyBlock;
import appeng.api.util.AEColor;
import appeng.helpers.Splotch;
import appeng.items.misc.ItemPaintBall;
import appeng.tile.AEBaseTile;
import java.io.IOException;
import java.util.*;
public class TilePaint extends AEBaseTile
{
public class TilePaint extends AEBaseTile {
private static final int LIGHT_PER_DOT = 12;
private static final int LIGHT_PER_DOT = 12;
private int isLit = 0;
private List<Splotch> dots = null;
private int isLit = 0;
private List<Splotch> dots = null;
@Override
public boolean canBeRotated()
{
return false;
}
@Override
public boolean canBeRotated() {
return false;
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
final ByteBuf myDat = Unpooled.buffer();
this.writeBuffer( myDat );
if( myDat.hasArray() )
{
data.setByteArray( "dots", myDat.array() );
}
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
final ByteBuf myDat = Unpooled.buffer();
this.writeBuffer(myDat);
if (myDat.hasArray()) {
data.setByteArray("dots", myDat.array());
}
return data;
}
private void writeBuffer( final ByteBuf out )
{
if( this.dots == null )
{
out.writeByte( 0 );
return;
}
private void writeBuffer(final ByteBuf out) {
if (this.dots == null) {
out.writeByte(0);
return;
}
out.writeByte( this.dots.size() );
out.writeByte(this.dots.size());
for( final Splotch s : this.dots )
{
s.writeToStream( out );
}
}
for (final Splotch s : this.dots) {
s.writeToStream(out);
}
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
if( data.hasKey( "dots" ) )
{
this.readBuffer( Unpooled.copiedBuffer( data.getByteArray( "dots" ) ) );
}
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
if (data.hasKey("dots")) {
this.readBuffer(Unpooled.copiedBuffer(data.getByteArray("dots")));
}
}
private void readBuffer( final ByteBuf in )
{
final byte howMany = in.readByte();
private void readBuffer(final ByteBuf in) {
final byte howMany = in.readByte();
if( howMany == 0 )
{
this.isLit = 0;
this.dots = null;
return;
}
if (howMany == 0) {
this.isLit = 0;
this.dots = null;
return;
}
this.dots = new ArrayList( howMany );
for( int x = 0; x < howMany; x++ )
{
this.dots.add( new Splotch( in ) );
}
this.dots = new ArrayList(howMany);
for (int x = 0; x < howMany; x++) {
this.dots.add(new Splotch(in));
}
this.isLit = 0;
for( final Splotch s : this.dots )
{
if( s.isLumen() )
{
this.isLit += LIGHT_PER_DOT;
}
}
this.isLit = 0;
for (final Splotch s : this.dots) {
if (s.isLumen()) {
this.isLit += LIGHT_PER_DOT;
}
}
this.maxLit();
}
this.maxLit();
}
private void maxLit()
{
if( this.isLit > 14 )
{
this.isLit = 14;
}
private void maxLit() {
if (this.isLit > 14) {
this.isLit = 14;
}
if( this.world != null )
{
this.world.getLightFor( EnumSkyBlock.BLOCK, this.pos );
}
}
if (this.world != null) {
this.world.getLightFor(EnumSkyBlock.BLOCK, this.pos);
}
}
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
this.writeBuffer( data );
}
@Override
protected void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
this.writeBuffer(data);
}
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
super.readFromStream( data );
this.readBuffer( data );
return true;
}
@Override
protected boolean readFromStream(final ByteBuf data) throws IOException {
super.readFromStream(data);
this.readBuffer(data);
return true;
}
public void neighborChanged()
{
if( this.dots == null )
{
return;
}
public void neighborChanged() {
if (this.dots == null) {
return;
}
for( final EnumFacing side : EnumFacing.VALUES )
{
if( !this.isSideValid( side ) )
{
this.removeSide( side );
}
}
for (final EnumFacing side : EnumFacing.VALUES) {
if (!this.isSideValid(side)) {
this.removeSide(side);
}
}
this.updateData();
}
this.updateData();
}
public boolean isSideValid( final EnumFacing side )
{
final BlockPos p = this.pos.offset( side );
final IBlockState blk = this.world.getBlockState( p );
return blk.getBlock().isSideSolid( this.world.getBlockState( p ), this.world, p, side.getOpposite() );
}
public boolean isSideValid(final EnumFacing side) {
final BlockPos p = this.pos.offset(side);
final IBlockState blk = this.world.getBlockState(p);
return blk.getBlock().isSideSolid(this.world.getBlockState(p), this.world, p, side.getOpposite());
}
private void removeSide( final EnumFacing side )
{
final Iterator<Splotch> i = this.dots.iterator();
while( i.hasNext() )
{
final Splotch s = i.next();
if( s.getSide() == side )
{
i.remove();
}
}
private void removeSide(final EnumFacing side) {
final Iterator<Splotch> i = this.dots.iterator();
while (i.hasNext()) {
final Splotch s = i.next();
if (s.getSide() == side) {
i.remove();
}
}
this.markForUpdate();
this.saveChanges();
}
this.markForUpdate();
this.saveChanges();
}
private void updateData()
{
this.isLit = 0;
for( final Splotch s : this.dots )
{
if( s.isLumen() )
{
this.isLit += LIGHT_PER_DOT;
}
}
private void updateData() {
this.isLit = 0;
for (final Splotch s : this.dots) {
if (s.isLumen()) {
this.isLit += LIGHT_PER_DOT;
}
}
this.maxLit();
this.maxLit();
if( this.dots.isEmpty() )
{
this.dots = null;
}
if (this.dots.isEmpty()) {
this.dots = null;
}
if( this.dots == null )
{
this.world.setBlockToAir( this.pos );
}
}
if (this.dots == null) {
this.world.setBlockToAir(this.pos);
}
}
public void cleanSide( final EnumFacing side )
{
if( this.dots == null )
{
return;
}
public void cleanSide(final EnumFacing side) {
if (this.dots == null) {
return;
}
this.removeSide( side );
this.removeSide(side);
this.updateData();
}
this.updateData();
}
public int getLightLevel()
{
return this.isLit;
}
public int getLightLevel() {
return this.isLit;
}
public void addBlot( final ItemStack type, final EnumFacing side, final Vec3d hitVec )
{
final BlockPos p = this.pos.offset( side );
public void addBlot(final ItemStack type, final EnumFacing side, final Vec3d hitVec) {
final BlockPos p = this.pos.offset(side);
final IBlockState blk = this.world.getBlockState( p );
if( blk.getBlock().isSideSolid( this.world.getBlockState( p ), this.world, p, side.getOpposite() ) )
{
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
final IBlockState blk = this.world.getBlockState(p);
if (blk.getBlock().isSideSolid(this.world.getBlockState(p), this.world, p, side.getOpposite())) {
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
final AEColor col = ipb.getColor( type );
final boolean lit = ipb.isLumen( type );
final AEColor col = ipb.getColor(type);
final boolean lit = ItemPaintBall.isLumen(type);
if( this.dots == null )
{
this.dots = new ArrayList<>();
}
if (this.dots == null) {
this.dots = new ArrayList<>();
}
if( this.dots.size() > 20 )
{
this.dots.remove( 0 );
}
if (this.dots.size() > 20) {
this.dots.remove(0);
}
this.dots.add( new Splotch( col, lit, side, hitVec ) );
if( lit )
{
this.isLit += LIGHT_PER_DOT;
}
this.dots.add(new Splotch(col, lit, side, hitVec));
if (lit) {
this.isLit += LIGHT_PER_DOT;
}
this.maxLit();
this.markForUpdate();
this.saveChanges();
}
}
this.maxLit();
this.markForUpdate();
this.saveChanges();
}
}
public Collection<Splotch> getDots()
{
if( this.dots == null )
{
return Collections.emptyList();
}
public Collection<Splotch> getDots() {
if (this.dots == null) {
return Collections.emptyList();
}
return this.dots;
}
return this.dots;
}
}
@@ -19,13 +19,6 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.EnumSet;
import io.netty.buffer.ByteBuf;
import net.minecraft.util.EnumFacing;
import appeng.api.implementations.IPowerChannelState;
import appeng.api.implementations.tiles.ICrystalGrowthAccelerator;
import appeng.api.networking.events.MENetworkEventSubscribe;
@@ -35,88 +28,76 @@ import appeng.api.util.AEPartLocation;
import appeng.me.GridAccessException;
import appeng.tile.grid.AENetworkTile;
import appeng.util.Platform;
import io.netty.buffer.ByteBuf;
import net.minecraft.util.EnumFacing;
import java.io.IOException;
import java.util.EnumSet;
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState, ICrystalGrowthAccelerator
{
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState, ICrystalGrowthAccelerator {
private boolean hasPower = false;
private boolean hasPower = false;
public TileQuartzGrowthAccelerator()
{
this.getProxy().setValidSides( EnumSet.noneOf( EnumFacing.class ) );
this.getProxy().setFlags();
this.getProxy().setIdlePowerUsage( 8 );
}
public TileQuartzGrowthAccelerator() {
this.getProxy().setValidSides(EnumSet.noneOf(EnumFacing.class));
this.getProxy().setFlags();
this.getProxy().setIdlePowerUsage(8);
}
@MENetworkEventSubscribe
public void onPower( final MENetworkPowerStatusChange ch )
{
this.markForUpdate();
}
@MENetworkEventSubscribe
public void onPower(final MENetworkPowerStatusChange ch) {
this.markForUpdate();
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.COVERED;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.COVERED;
}
@Override
public boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
final boolean hadPower = this.isPowered();
this.setPowered( data.readBoolean() );
return this.isPowered() != hadPower || c;
}
@Override
public boolean readFromStream(final ByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
final boolean hadPower = this.isPowered();
this.setPowered(data.readBoolean());
return this.isPowered() != hadPower || c;
}
@Override
public void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
try
{
data.writeBoolean( this.getProxy().getEnergy().isNetworkPowered() );
}
catch( final GridAccessException e )
{
data.writeBoolean( false );
}
}
@Override
public void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
try {
data.writeBoolean(this.getProxy().getEnergy().isNetworkPowered());
} catch (final GridAccessException e) {
data.writeBoolean(false);
}
}
@Override
public void setOrientation( final EnumFacing inForward, final EnumFacing inUp )
{
super.setOrientation( inForward, inUp );
this.getProxy().setValidSides( EnumSet.of( this.getUp(), this.getUp().getOpposite() ) );
}
@Override
public void setOrientation(final EnumFacing inForward, final EnumFacing inUp) {
super.setOrientation(inForward, inUp);
this.getProxy().setValidSides(EnumSet.of(this.getUp(), this.getUp().getOpposite()));
}
@Override
public boolean isPowered()
{
if( Platform.isServer() )
{
try
{
return this.getProxy().getEnergy().isNetworkPowered();
}
catch( final GridAccessException e )
{
return false;
}
}
@Override
public boolean isPowered() {
if (Platform.isServer()) {
try {
return this.getProxy().getEnergy().isNetworkPowered();
} catch (final GridAccessException e) {
return false;
}
}
return this.hasPower;
}
return this.hasPower;
}
@Override
public boolean isActive()
{
return this.isPowered();
}
@Override
public boolean isActive() {
return this.isPowered();
}
private void setPowered( final boolean hasPower )
{
this.hasPower = hasPower;
}
private void setPowered(final boolean hasPower) {
this.hasPower = hasPower;
}
}
@@ -19,30 +19,8 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.items.IItemHandler;
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.config.*;
import appeng.api.events.LocatableEventAnnounce;
import appeng.api.events.LocatableEventAnnounce.LocatableEvent;
import appeng.api.features.ILocatable;
@@ -62,11 +40,7 @@ import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.api.util.*;
import appeng.helpers.PlayerSecurityWrapper;
import appeng.me.GridAccessException;
import appeng.me.helpers.MEMonitorHandler;
@@ -80,296 +54,267 @@ import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.items.IItemHandler;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
public class TileSecurityStation extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile
{
public class TileSecurityStation extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile {
private static int difference = 0;
private final AppEngInternalInventory configSlot = new AppEngInternalInventory( this, 1 );
private final IConfigManager cm = new ConfigManager( this );
private final SecurityStationInventory inventory = new SecurityStationInventory( this );
private final MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<>( this.inventory );
private long securityKey;
private AEColor paintedColor = AEColor.TRANSPARENT;
private boolean isActive = false;
private static int difference = 0;
private final AppEngInternalInventory configSlot = new AppEngInternalInventory(this, 1);
private final IConfigManager cm = new ConfigManager(this);
private final SecurityStationInventory inventory = new SecurityStationInventory(this);
private final MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<>(this.inventory);
private long securityKey;
private AEColor paintedColor = AEColor.TRANSPARENT;
private boolean isActive = false;
public TileSecurityStation()
{
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
this.getProxy().setIdlePowerUsage( 2.0 );
difference++;
public TileSecurityStation() {
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.getProxy().setIdlePowerUsage(2.0);
difference++;
this.securityKey = System.currentTimeMillis() * 10 + difference;
if( difference > 10 )
{
difference = 0;
}
this.securityKey = System.currentTimeMillis() * 10 + difference;
if (difference > 10) {
difference = 0;
}
this.cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
this.cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
this.cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
}
this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
}
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
if( !ItemHandlerUtil.isEmpty( this.getConfigSlot() ) )
{
drops.add( this.getConfigSlot().getStackInSlot( 0 ) );
}
@Override
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
if (!ItemHandlerUtil.isEmpty(this.getConfigSlot())) {
drops.add(this.getConfigSlot().getStackInSlot(0));
}
for( final IAEItemStack ais : this.inventory.getStoredItems() )
{
drops.add( ais.createItemStack() );
}
}
for (final IAEItemStack ais : this.inventory.getStoredItems()) {
drops.add(ais.createItemStack());
}
}
IMEInventoryHandler<IAEItemStack> getSecurityInventory()
{
return this.inventory;
}
IMEInventoryHandler<IAEItemStack> getSecurityInventory() {
return this.inventory;
}
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
final boolean wasActive = this.isActive;
this.isActive = data.readBoolean();
@Override
protected boolean readFromStream(final ByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
final boolean wasActive = this.isActive;
this.isActive = data.readBoolean();
final AEColor oldPaintedColor = this.paintedColor;
this.paintedColor = AEColor.values()[data.readByte()];
final AEColor oldPaintedColor = this.paintedColor;
this.paintedColor = AEColor.values()[data.readByte()];
return oldPaintedColor != this.paintedColor || wasActive != this.isActive || c;
}
return oldPaintedColor != this.paintedColor || wasActive != this.isActive || c;
}
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
data.writeBoolean( this.getProxy().isActive() );
data.writeByte( this.paintedColor.ordinal() );
}
@Override
protected void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
data.writeBoolean(this.getProxy().isActive());
data.writeByte(this.paintedColor.ordinal());
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.cm.writeToNBT( data );
data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() );
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.cm.writeToNBT(data);
data.setByte("paintedColor", (byte) this.paintedColor.ordinal());
data.setLong( "securityKey", this.securityKey );
this.getConfigSlot().writeToNBT( data, "config" );
data.setLong("securityKey", this.securityKey);
this.getConfigSlot().writeToNBT(data, "config");
final NBTTagCompound storedItems = new NBTTagCompound();
final NBTTagCompound storedItems = new NBTTagCompound();
int offset = 0;
for( final IAEItemStack ais : this.inventory.getStoredItems() )
{
final NBTTagCompound it = new NBTTagCompound();
ais.createItemStack().writeToNBT( it );
storedItems.setTag( String.valueOf( offset ), it );
offset++;
}
int offset = 0;
for (final IAEItemStack ais : this.inventory.getStoredItems()) {
final NBTTagCompound it = new NBTTagCompound();
ais.createItemStack().writeToNBT(it);
storedItems.setTag(String.valueOf(offset), it);
offset++;
}
data.setTag( "storedItems", storedItems );
return data;
}
data.setTag("storedItems", storedItems);
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.cm.readFromNBT( data );
if( data.hasKey( "paintedColor" ) )
{
this.paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.cm.readFromNBT(data);
if (data.hasKey("paintedColor")) {
this.paintedColor = AEColor.values()[data.getByte("paintedColor")];
}
this.securityKey = data.getLong( "securityKey" );
this.getConfigSlot().readFromNBT( data, "config" );
this.securityKey = data.getLong("securityKey");
this.getConfigSlot().readFromNBT(data, "config");
final NBTTagCompound storedItems = data.getCompoundTag( "storedItems" );
for( final Object key : storedItems.getKeySet() )
{
final NBTBase obj = storedItems.getTag( (String) key );
if( obj instanceof NBTTagCompound )
{
this.inventory.getStoredItems().add( AEItemStack.fromItemStack( new ItemStack( (NBTTagCompound) obj ) ) );
}
}
}
final NBTTagCompound storedItems = data.getCompoundTag("storedItems");
for (final Object key : storedItems.getKeySet()) {
final NBTBase obj = storedItems.getTag((String) key);
if (obj instanceof NBTTagCompound) {
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(new ItemStack((NBTTagCompound) obj)));
}
}
}
public void inventoryChanged()
{
try
{
this.saveChanges();
this.getProxy().getGrid().postEvent( new MENetworkSecurityChange() );
}
catch( final GridAccessException e )
{
// :P
}
}
public void inventoryChanged() {
try {
this.saveChanges();
this.getProxy().getGrid().postEvent(new MENetworkSecurityChange());
} catch (final GridAccessException e) {
// :P
}
}
@MENetworkEventSubscribe
public void bootUpdate( final MENetworkChannelsChanged changed )
{
this.markForUpdate();
}
@MENetworkEventSubscribe
public void bootUpdate(final MENetworkChannelsChanged changed) {
this.markForUpdate();
}
@MENetworkEventSubscribe
public void powerUpdate( final MENetworkPowerStatusChange changed )
{
this.markForUpdate();
}
@MENetworkEventSubscribe
public void powerUpdate(final MENetworkPowerStatusChange changed) {
this.markForUpdate();
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.SMART;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
@Override
public void onChunkUnload()
{
super.onChunkUnload();
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.UNREGISTER ) );
this.isActive = false;
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
this.isActive = false;
}
@Override
public void onReady()
{
super.onReady();
if( Platform.isServer() )
{
this.isActive = true;
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.REGISTER ) );
}
}
@Override
public void onReady() {
super.onReady();
if (Platform.isServer()) {
this.isActive = true;
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.REGISTER));
}
}
@Override
public void invalidate()
{
super.invalidate();
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.UNREGISTER ) );
this.isActive = false;
}
@Override
public void invalidate() {
super.invalidate();
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
this.isActive = false;
}
@Override
public DimensionalCoord getLocation()
{
return new DimensionalCoord( this );
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
public boolean isActive()
{
return this.isActive;
}
public boolean isActive() {
return this.isActive;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
return (IMEMonitor<T>) this.securityMonitor;
}
return null;
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
return (IMEMonitor<T>) this.securityMonitor;
}
return null;
}
}
@Override
public long getLocatableSerial()
{
return this.securityKey;
}
@Override
public long getLocatableSerial() {
return this.securityKey;
}
public boolean isPowered()
{
return this.getProxy().isActive();
}
public boolean isPowered() {
return this.getProxy().isActive();
}
@Override
public IConfigManager getConfigManager()
{
return this.cm;
}
@Override
public IConfigManager getConfigManager() {
return this.cm;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
}
}
@Override
public long getSecurityKey()
{
return this.securityKey;
}
@Override
public long getSecurityKey() {
return this.securityKey;
}
@Override
public void readPermissions( final Map<Integer, EnumSet<SecurityPermissions>> playerPerms )
{
final IPlayerRegistry pr = AEApi.instance().registries().players();
@Override
public void readPermissions(final Map<Integer, EnumSet<SecurityPermissions>> playerPerms) {
final IPlayerRegistry pr = AEApi.instance().registries().players();
// read permissions
for( final IAEItemStack ais : this.inventory.getStoredItems() )
{
final ItemStack is = ais.createItemStack();
final Item i = is.getItem();
if( i instanceof IBiometricCard )
{
final IBiometricCard bc = (IBiometricCard) i;
bc.registerPermissions( new PlayerSecurityWrapper( playerPerms ), pr, is );
}
}
// read permissions
for (final IAEItemStack ais : this.inventory.getStoredItems()) {
final ItemStack is = ais.createItemStack();
final Item i = is.getItem();
if (i instanceof IBiometricCard) {
final IBiometricCard bc = (IBiometricCard) i;
bc.registerPermissions(new PlayerSecurityWrapper(playerPerms), pr, is);
}
}
// make sure thea admin is Boss.
playerPerms.put( this.getProxy().getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
}
// make sure thea admin is Boss.
playerPerms.put(this.getProxy().getNode().getPlayerID(), EnumSet.allOf(SecurityPermissions.class));
}
@Override
public boolean isSecurityEnabled()
{
return this.isActive && this.getProxy().isActive();
}
@Override
public boolean isSecurityEnabled() {
return this.isActive && this.getProxy().isActive();
}
@Override
public int getOwner()
{
return this.getProxy().getNode().getPlayerID();
}
@Override
public int getOwner() {
return this.getProxy().getNode().getPlayerID();
}
@Override
public AEColor getColor()
{
return this.paintedColor;
}
@Override
public AEColor getColor() {
return this.paintedColor;
}
@Override
public boolean recolourBlock( final EnumFacing side, final AEColor newPaintedColor, final EntityPlayer who )
{
if( this.paintedColor == newPaintedColor )
{
return false;
}
@Override
public boolean recolourBlock(final EnumFacing side, final AEColor newPaintedColor, final EntityPlayer who) {
if (this.paintedColor == newPaintedColor) {
return false;
}
this.paintedColor = newPaintedColor;
this.saveChanges();
this.markForUpdate();
return true;
}
this.paintedColor = newPaintedColor;
this.saveChanges();
this.markForUpdate();
return true;
}
public AppEngInternalInventory getConfigSlot()
{
return this.configSlot;
}
public AppEngInternalInventory getConfigSlot() {
return this.configSlot;
}
}
@@ -22,19 +22,16 @@ package appeng.tile.misc;
import appeng.tile.AEBaseTile;
public class TileSkyCompass extends AEBaseTile
{
public class TileSkyCompass extends AEBaseTile {
@Override
public boolean requiresTESR()
{
return true;
}
@Override
public boolean requiresTESR() {
return true;
}
@Override
public boolean hasFastRenderer()
{
return true;
}
@Override
public boolean hasFastRenderer() {
return true;
}
}
@@ -19,19 +19,6 @@
package appeng.tile.misc;
import java.io.IOException;
import javax.annotation.Nonnull;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
@@ -49,284 +36,240 @@ import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import java.io.IOException;
public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable
{
public static final double POWER_PER_TICK = 5;
public static final int MIN_BURN_SPEED = 20;
public static final int MAX_BURN_SPEED = 200;
public static final double DILATION_SCALING = 25.0; // x4 ~ 40 AE/t at max
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
private final IItemHandler invExt = new WrapperFilteredItemHandler( this.inv, new FuelSlotFilter() );
public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable {
public static final double POWER_PER_TICK = 5;
public static final int MIN_BURN_SPEED = 20;
public static final int MAX_BURN_SPEED = 200;
public static final double DILATION_SCALING = 25.0; // x4 ~ 40 AE/t at max
private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 1);
private final IItemHandler invExt = new WrapperFilteredItemHandler(this.inv, new FuelSlotFilter());
private int burnSpeed = 100;
private double burnTime = 0;
private double maxBurnTime = 0;
private int burnSpeed = 100;
private double burnTime = 0;
private double maxBurnTime = 0;
// client side..
public boolean isOn;
// client side..
public boolean isOn;
public TileVibrationChamber()
{
this.getProxy().setIdlePowerUsage( 0 );
this.getProxy().setFlags();
}
public TileVibrationChamber() {
this.getProxy().setIdlePowerUsage(0);
this.getProxy().setFlags();
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.COVERED;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.COVERED;
}
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
final boolean wasOn = this.isOn;
@Override
protected boolean readFromStream(final ByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
final boolean wasOn = this.isOn;
this.isOn = data.readBoolean();
this.isOn = data.readBoolean();
return wasOn != this.isOn || c; // TESR doesn't need updates!
}
return wasOn != this.isOn || c; // TESR doesn't need updates!
}
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
data.writeBoolean( this.getBurnTime() > 0 );
}
@Override
protected void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
data.writeBoolean(this.getBurnTime() > 0);
}
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setDouble( "burnTime", this.getBurnTime() );
data.setDouble( "maxBurnTime", this.getMaxBurnTime() );
data.setInteger( "burnSpeed", this.getBurnSpeed() );
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
data.setDouble("burnTime", this.getBurnTime());
data.setDouble("maxBurnTime", this.getMaxBurnTime());
data.setInteger("burnSpeed", this.getBurnSpeed());
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.setBurnTime( data.getDouble( "burnTime" ) );
this.setMaxBurnTime( data.getDouble( "maxBurnTime" ) );
this.setBurnSpeed( data.getInteger( "burnSpeed" ) );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.setBurnTime(data.getDouble("burnTime"));
this.setMaxBurnTime(data.getDouble("maxBurnTime"));
this.setBurnSpeed(data.getInteger("burnSpeed"));
}
@Override
protected IItemHandler getItemHandlerForSide( @Nonnull EnumFacing facing )
{
return this.invExt;
}
@Override
protected IItemHandler getItemHandlerForSide(@Nonnull EnumFacing facing) {
return this.invExt;
}
@Override
public IItemHandler getInternalInventory()
{
return this.inv;
}
@Override
public IItemHandler getInternalInventory() {
return this.inv;
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( this.getBurnTime() <= 0 )
{
if( this.canEatFuel() )
{
try
{
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// wake up!
}
}
}
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added) {
if (this.getBurnTime() <= 0) {
if (this.canEatFuel()) {
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// wake up!
}
}
}
}
private boolean canEatFuel()
{
final ItemStack is = this.inv.getStackInSlot( 0 );
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
if( newBurnTime > 0 && is.getCount() > 0 )
{
return true;
}
}
return false;
}
private boolean canEatFuel() {
final ItemStack is = this.inv.getStackInSlot(0);
if (!is.isEmpty()) {
final int newBurnTime = TileEntityFurnace.getItemBurnTime(is);
return newBurnTime > 0 && is.getCount() > 0;
}
return false;
}
@Override
public DimensionalCoord getLocation()
{
return new DimensionalCoord( this );
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
if( this.getBurnTime() <= 0 )
{
this.eatFuel();
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
if (this.getBurnTime() <= 0) {
this.eatFuel();
}
return new TickingRequest( TickRates.VibrationChamber.getMin(), TickRates.VibrationChamber.getMax(), this.getBurnTime() <= 0, false );
}
return new TickingRequest(TickRates.VibrationChamber.getMin(), TickRates.VibrationChamber.getMax(), this.getBurnTime() <= 0, false);
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
if( this.getBurnTime() <= 0 )
{
this.eatFuel();
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
if (this.getBurnTime() <= 0) {
this.eatFuel();
if( this.getBurnTime() > 0 )
{
return TickRateModulation.URGENT;
}
if (this.getBurnTime() > 0) {
return TickRateModulation.URGENT;
}
this.setBurnSpeed( 100 );
return TickRateModulation.SLEEP;
}
this.setBurnSpeed(100);
return TickRateModulation.SLEEP;
}
this.setBurnSpeed( Math.max( MIN_BURN_SPEED, Math.min( this.getBurnSpeed(), MAX_BURN_SPEED ) ) );
final double dilation = this.getBurnSpeed() / DILATION_SCALING;
this.setBurnSpeed(Math.max(MIN_BURN_SPEED, Math.min(this.getBurnSpeed(), MAX_BURN_SPEED)));
final double dilation = this.getBurnSpeed() / DILATION_SCALING;
double timePassed = ticksSinceLastCall * dilation;
this.setBurnTime( this.getBurnTime() - timePassed );
if( this.getBurnTime() < 0 )
{
timePassed += this.getBurnTime();
this.setBurnTime( 0 );
}
double timePassed = ticksSinceLastCall * dilation;
this.setBurnTime(this.getBurnTime() - timePassed);
if (this.getBurnTime() < 0) {
timePassed += this.getBurnTime();
this.setBurnTime(0);
}
try
{
final IEnergyGrid grid = this.getProxy().getEnergy();
final double newPower = timePassed * POWER_PER_TICK;
final double overFlow = grid.injectPower( newPower, Actionable.SIMULATE );
try {
final IEnergyGrid grid = this.getProxy().getEnergy();
final double newPower = timePassed * POWER_PER_TICK;
final double overFlow = grid.injectPower(newPower, Actionable.SIMULATE);
// burn the over flow.
grid.injectPower( Math.max( 0.0, newPower - overFlow ), Actionable.MODULATE );
// burn the over flow.
grid.injectPower(Math.max(0.0, newPower - overFlow), Actionable.MODULATE);
if( overFlow > 0 )
{
this.setBurnSpeed( this.getBurnSpeed() - ticksSinceLastCall );
}
else
{
this.setBurnSpeed( this.getBurnSpeed() + ticksSinceLastCall );
}
if (overFlow > 0) {
this.setBurnSpeed(this.getBurnSpeed() - ticksSinceLastCall);
} else {
this.setBurnSpeed(this.getBurnSpeed() + ticksSinceLastCall);
}
this.setBurnSpeed( Math.max( MIN_BURN_SPEED, Math.min( this.getBurnSpeed(), MAX_BURN_SPEED ) ) );
return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER;
}
catch( final GridAccessException e )
{
this.setBurnSpeed( this.getBurnSpeed() - ticksSinceLastCall );
this.setBurnSpeed( Math.max( MIN_BURN_SPEED, Math.min( this.getBurnSpeed(), MAX_BURN_SPEED ) ) );
return TickRateModulation.SLOWER;
}
}
this.setBurnSpeed(Math.max(MIN_BURN_SPEED, Math.min(this.getBurnSpeed(), MAX_BURN_SPEED)));
return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER;
} catch (final GridAccessException e) {
this.setBurnSpeed(this.getBurnSpeed() - ticksSinceLastCall);
this.setBurnSpeed(Math.max(MIN_BURN_SPEED, Math.min(this.getBurnSpeed(), MAX_BURN_SPEED)));
return TickRateModulation.SLOWER;
}
}
private void eatFuel()
{
final ItemStack is = this.inv.getStackInSlot( 0 );
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
if( newBurnTime > 0 && is.getCount() > 0 )
{
this.setBurnTime( this.getBurnTime() + newBurnTime );
this.setMaxBurnTime( this.getBurnTime() );
private void eatFuel() {
final ItemStack is = this.inv.getStackInSlot(0);
if (!is.isEmpty()) {
final int newBurnTime = TileEntityFurnace.getItemBurnTime(is);
if (newBurnTime > 0 && is.getCount() > 0) {
this.setBurnTime(this.getBurnTime() + newBurnTime);
this.setMaxBurnTime(this.getBurnTime());
final Item fuelItem = is.getItem();
is.shrink( 1 );
final Item fuelItem = is.getItem();
is.shrink(1);
if( is.isEmpty() )
{
this.inv.setStackInSlot( 0, fuelItem.getContainerItem( is ) );
}
else
{
this.inv.setStackInSlot( 0, is );
}
this.saveChanges();
}
}
if (is.isEmpty()) {
this.inv.setStackInSlot(0, fuelItem.getContainerItem(is));
} else {
this.inv.setStackInSlot(0, is);
}
this.saveChanges();
}
}
if( this.getBurnTime() > 0 )
{
try
{
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// gah!
}
}
if (this.getBurnTime() > 0) {
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// gah!
}
}
// state change
if( ( !this.isOn && this.getBurnTime() > 0 ) || ( this.isOn && this.getBurnTime() <= 0 ) )
{
this.isOn = this.getBurnTime() > 0;
this.markForUpdate();
// state change
if ((!this.isOn && this.getBurnTime() > 0) || (this.isOn && this.getBurnTime() <= 0)) {
this.isOn = this.getBurnTime() > 0;
this.markForUpdate();
if( this.hasWorld() )
{
Platform.notifyBlocksOfNeighbors( this.world, this.pos );
}
}
}
if (this.hasWorld()) {
Platform.notifyBlocksOfNeighbors(this.world, this.pos);
}
}
}
public int getBurnSpeed()
{
return this.burnSpeed;
}
public int getBurnSpeed() {
return this.burnSpeed;
}
private void setBurnSpeed( final int burnSpeed )
{
this.burnSpeed = burnSpeed;
}
private void setBurnSpeed(final int burnSpeed) {
this.burnSpeed = burnSpeed;
}
public double getMaxBurnTime()
{
return this.maxBurnTime;
}
public double getMaxBurnTime() {
return this.maxBurnTime;
}
private void setMaxBurnTime( final double maxBurnTime )
{
this.maxBurnTime = maxBurnTime;
}
private void setMaxBurnTime(final double maxBurnTime) {
this.maxBurnTime = maxBurnTime;
}
public double getBurnTime()
{
return this.burnTime;
}
public double getBurnTime() {
return this.burnTime;
}
private void setBurnTime( final double burnTime )
{
this.burnTime = burnTime;
}
private void setBurnTime(final double burnTime) {
this.burnTime = burnTime;
}
private class FuelSlotFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return !TileEntityFurnace.isItemFuel( inv.getStackInSlot( slot ) );
}
private class FuelSlotFilter implements IAEItemFilter {
@Override
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
return !TileEntityFurnace.isItemFuel(inv.getStackInSlot(slot));
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return TileEntityFurnace.isItemFuel( stack );
}
}
@Override
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
return TileEntityFurnace.isItemFuel(stack);
}
}
}