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,16 +19,6 @@
package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
import appeng.api.AEApi;
import appeng.api.config.CopyMode;
import appeng.api.config.FuzzyMode;
@@ -49,219 +39,192 @@ import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperSupplierItemHandler;
import appeng.util.iterators.NullIterator;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
import java.util.Iterator;
public class ContainerCellWorkbench extends ContainerUpgradeable
{
private final TileCellWorkbench workBench;
@GuiSync( 2 )
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
private int lastUpgrades = 0;
public class ContainerCellWorkbench extends ContainerUpgradeable {
private final TileCellWorkbench workBench;
@GuiSync(2)
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
private int lastUpgrades = 0;
public ContainerCellWorkbench( final InventoryPlayer ip, final TileCellWorkbench te )
{
super( ip, te );
this.workBench = te;
}
public ContainerCellWorkbench(final InventoryPlayer ip, final TileCellWorkbench te) {
super(ip, te);
this.workBench = te;
}
public void setFuzzy( final FuzzyMode valueOf )
{
final ICellWorkbenchItem cwi = this.workBench.getCell();
if( cwi != null )
{
cwi.setFuzzyMode( this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ), valueOf );
}
}
public void setFuzzy(final FuzzyMode valueOf) {
final ICellWorkbenchItem cwi = this.workBench.getCell();
if (cwi != null) {
cwi.setFuzzyMode(this.workBench.getInventoryByName("cell").getStackInSlot(0), valueOf);
}
}
public void nextWorkBenchCopyMode()
{
this.workBench.getConfigManager().putSetting( Settings.COPY_MODE, Platform.nextEnum( this.getWorkBenchCopyMode() ) );
}
public void nextWorkBenchCopyMode() {
this.workBench.getConfigManager().putSetting(Settings.COPY_MODE, Platform.nextEnum(this.getWorkBenchCopyMode()));
}
private CopyMode getWorkBenchCopyMode()
{
return (CopyMode) this.workBench.getConfigManager().getSetting( Settings.COPY_MODE );
}
private CopyMode getWorkBenchCopyMode() {
return (CopyMode) this.workBench.getConfigManager().getSetting(Settings.COPY_MODE);
}
@Override
protected int getHeight()
{
return 251;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig()
{
final IItemHandler cell = this.getUpgradeable().getInventoryByName( "cell" );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.getPlayerInv() ) );
@Override
protected void setupConfig() {
final IItemHandler cell = this.getUpgradeable().getInventoryByName("cell");
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.getPlayerInv()));
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final WrapperSupplierItemHandler upgradeInventory = new WrapperSupplierItemHandler( this::getCellUpgradeInventory );
// null, 3 * 8 );
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final WrapperSupplierItemHandler upgradeInventory = new WrapperSupplierItemHandler(this::getCellUpgradeInventory);
// null, 3 * 8 );
int offset = 0;
final int y = 29;
final int x = 8;
for( int w = 0; w < 7; w++ )
{
for( int z = 0; z < 9; z++ )
{
this.addSlotToContainer( new SlotFakeTypeOnly( inv, offset, x + z * 18, y + w * 18 ) );
offset++;
}
}
int offset = 0;
final int y = 29;
final int x = 8;
for (int w = 0; w < 7; w++) {
for (int z = 0; z < 9; z++) {
this.addSlotToContainer(new SlotFakeTypeOnly(inv, offset, x + z * 18, y + w * 18));
offset++;
}
}
for( int zz = 0; zz < 3; zz++ )
{
for( int z = 0; z < 8; z++ )
{
final int iSLot = zz * 8 + z;
this.addSlotToContainer(
new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgradeInventory, this, iSLot, 187 + zz * 18, 8 + 18 * z, iSLot, this
.getInventoryPlayer() ) );
}
}
/*
* if ( supportCapacity() ) { for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new
* OptionalSlotFakeTypeOnly( inv, this, offset++, x, y, z, w, 1 ) );
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 2, 2 ) );
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 4, 3 ) ); }
*/
}
for (int zz = 0; zz < 3; zz++) {
for (int z = 0; z < 8; z++) {
final int iSLot = zz * 8 + z;
this.addSlotToContainer(
new OptionalSlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgradeInventory, this, iSLot, 187 + zz * 18, 8 + 18 * z, iSLot, this
.getInventoryPlayer()));
}
}
/*
* if ( supportCapacity() ) { for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new
* OptionalSlotFakeTypeOnly( inv, this, offset++, x, y, z, w, 1 ) );
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 2, 2 ) );
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 4, 3 ) ); }
*/
}
@Override
public int availableUpgrades()
{
final ItemStack is = this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if( this.prevStack != is )
{
this.prevStack = is;
this.lastUpgrades = this.getCellUpgradeInventory().getSlots();
}
return this.lastUpgrades;
}
@Override
public int availableUpgrades() {
final ItemStack is = this.workBench.getInventoryByName("cell").getStackInSlot(0);
if (this.prevStack != is) {
this.prevStack = is;
this.lastUpgrades = this.getCellUpgradeInventory().getSlots();
}
return this.lastUpgrades;
}
@Override
public void detectAndSendChanges()
{
final ItemStack is = this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if( Platform.isServer() )
{
for( final IContainerListener listener : this.listeners )
{
if( this.prevStack != is )
{
// if the bars changed an item was probably made, so just send shit!
for( final Slot s : this.inventorySlots )
{
if( s instanceof OptionalSlotRestrictedInput )
{
final OptionalSlotRestrictedInput sri = (OptionalSlotRestrictedInput) s;
listener.sendSlotContents( this, sri.slotNumber, sri.getStack() );
}
}
@Override
public void detectAndSendChanges() {
final ItemStack is = this.workBench.getInventoryByName("cell").getStackInSlot(0);
if (Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
if (this.prevStack != is) {
// if the bars changed an item was probably made, so just send shit!
for (final Slot s : this.inventorySlots) {
if (s instanceof OptionalSlotRestrictedInput) {
final OptionalSlotRestrictedInput sri = (OptionalSlotRestrictedInput) s;
listener.sendSlotContents(this, sri.slotNumber, sri.getStack());
}
}
if( listener instanceof EntityPlayerMP )
{
( (EntityPlayerMP) listener ).isChangingQuantityOnly = false;
}
}
}
if (listener instanceof EntityPlayerMP) {
((EntityPlayerMP) listener).isChangingQuantityOnly = false;
}
}
}
this.setCopyMode( this.getWorkBenchCopyMode() );
this.setFuzzyMode( this.getWorkBenchFuzzyMode() );
}
this.setCopyMode(this.getWorkBenchCopyMode());
this.setFuzzyMode(this.getWorkBenchFuzzyMode());
}
this.prevStack = is;
this.standardDetectAndSendChanges();
}
this.prevStack = is;
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled( final int idx )
{
return idx < this.availableUpgrades();
}
@Override
public boolean isSlotEnabled(final int idx) {
return idx < this.availableUpgrades();
}
public IItemHandler getCellUpgradeInventory()
{
final IItemHandler upgradeInventory = this.workBench.getCellUpgradeInventory();
public IItemHandler getCellUpgradeInventory() {
final IItemHandler upgradeInventory = this.workBench.getCellUpgradeInventory();
return upgradeInventory == null ? EmptyHandler.INSTANCE : upgradeInventory;
}
return upgradeInventory == null ? EmptyHandler.INSTANCE : upgradeInventory;
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "copyMode" ) )
{
this.workBench.getConfigManager().putSetting( Settings.COPY_MODE, this.getCopyMode() );
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("copyMode")) {
this.workBench.getConfigManager().putSetting(Settings.COPY_MODE, this.getCopyMode());
}
super.onUpdate( field, oldValue, newValue );
}
super.onUpdate(field, oldValue, newValue);
}
public void clear()
{
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
this.detectAndSendChanges();
}
public void clear() {
ItemHandlerUtil.clear(this.getUpgradeable().getInventoryByName("config"));
this.detectAndSendChanges();
}
private FuzzyMode getWorkBenchFuzzyMode()
{
final ICellWorkbenchItem cwi = this.workBench.getCell();
if( cwi != null )
{
return cwi.getFuzzyMode( this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ) );
}
return FuzzyMode.IGNORE_ALL;
}
private FuzzyMode getWorkBenchFuzzyMode() {
final ICellWorkbenchItem cwi = this.workBench.getCell();
if (cwi != null) {
return cwi.getFuzzyMode(this.workBench.getInventoryByName("cell").getStackInSlot(0));
}
return FuzzyMode.IGNORE_ALL;
}
public void partition()
{
public void partition() {
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final ItemStack is = this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 );
final IStorageChannel channel = is.getItem() instanceof IStorageCell ? ( (IStorageCell) is.getItem() ).getChannel() : AEApi.instance()
.storage()
.getStorageChannel( IItemStorageChannel.class );
final ItemStack is = this.getUpgradeable().getInventoryByName("cell").getStackInSlot(0);
final IStorageChannel channel = is.getItem() instanceof IStorageCell ? ((IStorageCell) is.getItem()).getChannel() : AEApi.instance()
.storage()
.getStorageChannel(IItemStorageChannel.class);
final IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory( is, null, channel );
final IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory(is, null, channel);
Iterator<IAEStack> i = new NullIterator<>();
if( cellInv != null )
{
final IItemList list = cellInv.getAvailableItems( channel.createList() );
i = list.iterator();
}
Iterator<IAEStack> i = new NullIterator<>();
if (cellInv != null) {
final IItemList list = cellInv.getAvailableItems(channel.createList());
i = list.iterator();
}
for( int x = 0; x < inv.getSlots(); x++ )
{
if( i.hasNext() )
{
// TODO: check if ok
final ItemStack g = i.next().asItemStackRepresentation();
ItemHandlerUtil.setStackInSlot( inv, x, g );
}
else
{
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
}
}
for (int x = 0; x < inv.getSlots(); x++) {
if (i.hasNext()) {
// TODO: check if ok
final ItemStack g = i.next().asItemStackRepresentation();
ItemHandlerUtil.setStackInSlot(inv, x, g);
} else {
ItemHandlerUtil.setStackInSlot(inv, x, ItemStack.EMPTY);
}
}
this.detectAndSendChanges();
}
this.detectAndSendChanges();
}
public CopyMode getCopyMode()
{
return this.copyMode;
}
public CopyMode getCopyMode() {
return this.copyMode;
}
private void setCopyMode( final CopyMode copyMode )
{
this.copyMode = copyMode;
}
private void setCopyMode(final CopyMode copyMode) {
this.copyMode = copyMode;
}
}
@@ -19,26 +19,23 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileChest;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerChest extends AEBaseContainer
{
public class ContainerChest extends AEBaseContainer {
private final TileChest chest;
private final TileChest chest;
public ContainerChest( final InventoryPlayer ip, final TileChest chest )
{
super( ip, chest, null );
this.chest = chest;
public ContainerChest(final InventoryPlayer ip, final TileChest chest) {
super(ip, chest, null);
this.chest = chest;
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest.getInternalInventory(), 1, 80, 37, this
.getInventoryPlayer() ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest.getInternalInventory(), 1, 80, 37, this
.getInventoryPlayer()));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
}
@@ -19,11 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.container.AEBaseContainer;
@@ -33,79 +28,73 @@ import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileCondenser;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ContainerCondenser extends AEBaseContainer implements IProgressProvider
{
public class ContainerCondenser extends AEBaseContainer implements IProgressProvider {
private final TileCondenser condenser;
@GuiSync( 0 )
public long requiredEnergy = 0;
@GuiSync( 1 )
public long storedPower = 0;
@GuiSync( 2 )
public CondenserOutput output = CondenserOutput.TRASH;
private ItemStack prevStack = ItemStack.EMPTY;
private final TileCondenser condenser;
@GuiSync(0)
public long requiredEnergy = 0;
@GuiSync(1)
public long storedPower = 0;
@GuiSync(2)
public CondenserOutput output = CondenserOutput.TRASH;
private final ItemStack prevStack = ItemStack.EMPTY;
public ContainerCondenser( final InventoryPlayer ip, final TileCondenser condenser )
{
super( ip, condenser, null );
this.condenser = condenser;
public ContainerCondenser(final InventoryPlayer ip, final TileCondenser condenser) {
super(ip, condenser, null);
this.condenser = condenser;
IItemHandler inv = condenser.getInternalInventory();
IItemHandler inv = condenser.getInternalInventory();
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip ) );
this.addSlotToContainer( new SlotOutput( inv, 1, 105, 52, -1 ) );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip ) ).setStackLimit( 1 ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip));
this.addSlotToContainer(new SlotOutput(inv, 1, 105, 52, -1));
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip)).setStackLimit(1));
this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 197 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
final ItemStack is = this.condenser.getInternalInventory().getStackInSlot( 1 );
if( Platform.isServer() )
{
final double maxStorage = this.condenser.getStorage();
final double requiredEnergy = this.condenser.getRequiredPower();
@Override
public void detectAndSendChanges() {
final ItemStack is = this.condenser.getInternalInventory().getStackInSlot(1);
if (Platform.isServer()) {
final double maxStorage = this.condenser.getStorage();
final double requiredEnergy = this.condenser.getRequiredPower();
this.requiredEnergy = requiredEnergy == 0 ? (int) maxStorage : (int) Math.min( requiredEnergy, maxStorage );
this.storedPower = (int) this.condenser.getStoredPower();
this.setOutput( (CondenserOutput) this.condenser.getConfigManager().getSetting( Settings.CONDENSER_OUTPUT ) );
this.requiredEnergy = requiredEnergy == 0 ? (int) maxStorage : (int) Math.min(requiredEnergy, maxStorage);
this.storedPower = (int) this.condenser.getStoredPower();
this.setOutput((CondenserOutput) this.condenser.getConfigManager().getSetting(Settings.CONDENSER_OUTPUT));
for( final IContainerListener listener : this.listeners )
{
if( !ItemStack.areItemsEqual( is, prevStack ) )
{
listener.sendSlotContents( this, 1, is );
}
}
}
for (final IContainerListener listener : this.listeners) {
if (!ItemStack.areItemsEqual(is, prevStack)) {
listener.sendSlotContents(this, 1, is);
}
}
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
@Override
public int getCurrentProgress()
{
return (int) this.storedPower;
}
@Override
public int getCurrentProgress() {
return (int) this.storedPower;
}
@Override
public int getMaxProgress()
{
return (int) this.requiredEnergy;
}
@Override
public int getMaxProgress() {
return (int) this.requiredEnergy;
}
public CondenserOutput getOutput()
{
return this.output;
}
public CondenserOutput getOutput() {
return this.output;
}
private void setOutput( final CondenserOutput output )
{
this.output = output;
}
private void setOutput(final CondenserOutput output) {
this.output = output;
}
}
@@ -19,12 +19,6 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.world.World;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.IActionHost;
@@ -35,63 +29,58 @@ import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
import appeng.me.helpers.PlayerSource;
import appeng.tile.inventory.AppEngInternalInventory;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class ContainerCraftAmount extends AEBaseContainer
{
public class ContainerCraftAmount extends AEBaseContainer {
private final Slot craftingItem;
private IAEItemStack itemToCreate;
private final Slot craftingItem;
private IAEItemStack itemToCreate;
public ContainerCraftAmount( final InventoryPlayer ip, final ITerminalHost te )
{
super( ip, te );
public ContainerCraftAmount(final InventoryPlayer ip, final ITerminalHost te) {
super(ip, te);
this.craftingItem = new SlotInaccessible( new AppEngInternalInventory( null, 1 ), 0, 34, 53 );
this.addSlotToContainer( this.getCraftingItem() );
}
this.craftingItem = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
this.addSlotToContainer(this.getCraftingItem());
}
@Override
public Slot getSlot( int slotId )
{
return super.getSlot( 0 );
}
@Override
public Slot getSlot(int slotId) {
return super.getSlot(0);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
this.verifyPermissions( SecurityPermissions.CRAFT, false );
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
this.verifyPermissions(SecurityPermissions.CRAFT, false);
}
public IGrid getGrid()
{
final IActionHost h = ( (IActionHost) this.getTarget() );
return h.getActionableNode().getGrid();
}
public IGrid getGrid() {
final IActionHost h = ((IActionHost) this.getTarget());
return h.getActionableNode().getGrid();
}
public World getWorld()
{
return this.getPlayerInv().player.world;
}
public World getWorld() {
return this.getPlayerInv().player.world;
}
public IActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
}
public IActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget());
}
public Slot getCraftingItem()
{
return this.craftingItem;
}
public Slot getCraftingItem() {
return this.craftingItem;
}
public IAEItemStack getItemToCraft()
{
return this.itemToCreate;
}
public IAEItemStack getItemToCraft() {
return this.itemToCreate;
}
public void setItemToCraft( @Nonnull final IAEItemStack itemToCreate )
{
this.itemToCreate = itemToCreate;
}
public void setItemToCraft(@Nonnull final IAEItemStack itemToCreate) {
this.itemToCreate = itemToCreate;
}
}
@@ -19,24 +19,6 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
import appeng.parts.reporting.PartExpandedProcessingPatternTerminal;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
@@ -62,428 +44,363 @@ import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.PlayerSource;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartExpandedProcessingPatternTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartTerminal;
import appeng.util.Platform;
public class ContainerCraftConfirm extends AEBaseContainer
{
private final ArrayList<CraftingCPURecord> cpus = new ArrayList<>();
private Future<ICraftingJob> job;
private ICraftingJob result;
@GuiSync( 0 )
public long bytesUsed;
@GuiSync( 1 )
public long cpuBytesAvail;
@GuiSync( 2 )
public int cpuCoProcessors;
@GuiSync( 3 )
public boolean autoStart = false;
@GuiSync( 4 )
public boolean simulation = true;
@GuiSync( 5 )
public int selectedCpu = -1;
@GuiSync( 6 )
public boolean noCPU = true;
@GuiSync( 7 )
public String myName = "";
public ContainerCraftConfirm( final InventoryPlayer ip, final ITerminalHost te )
{
super( ip, te );
}
public void cycleCpu( final boolean next )
{
if( next )
{
this.setSelectedCpu( this.getSelectedCpu() + 1 );
}
else
{
this.setSelectedCpu( this.getSelectedCpu() - 1 );
}
if( this.getSelectedCpu() < -1 )
{
this.setSelectedCpu( this.cpus.size() - 1 );
}
else if( this.getSelectedCpu() >= this.cpus.size() )
{
this.setSelectedCpu( -1 );
}
if( this.getSelectedCpu() == -1 )
{
this.setCpuAvailableBytes( 0 );
this.setCpuCoProcessors( 0 );
this.setName( "" );
}
else
{
this.setName( this.cpus.get( this.getSelectedCpu() ).getName() );
this.setCpuAvailableBytes( this.cpus.get( this.getSelectedCpu() ).getSize() );
this.setCpuCoProcessors( this.cpus.get( this.getSelectedCpu() ).getProcessors() );
}
}
@Override
public void detectAndSendChanges()
{
if( Platform.isClient() )
{
return;
}
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for( final ICraftingCPU c : cpuSet )
{
boolean found = false;
for( final CraftingCPURecord ccr : this.cpus )
{
if( ccr.getCpu() == c )
{
found = true;
break;
}
}
final boolean matched = this.cpuMatches( c );
if( matched )
{
matches++;
}
if( found == !matched )
{
changed = true;
}
}
if( changed || this.cpus.size() != matches )
{
this.cpus.clear();
for( final ICraftingCPU c : cpuSet )
{
if( this.cpuMatches( c ) )
{
this.cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
}
}
this.sendCPUs();
}
this.setNoCPU( this.cpus.isEmpty() );
super.detectAndSendChanges();
if( this.getJob() != null && this.getJob().isDone() )
{
try
{
this.result = this.getJob().get();
if( !this.result.isSimulation() )
{
this.setSimulation( false );
if( this.isAutoStart() )
{
this.startJob();
return;
}
}
else
{
this.setSimulation( true );
}
try
{
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final PacketMEInventoryUpdate c = this.result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
final IItemList<IAEItemStack> plan = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
this.result.populatePlan( plan );
this.setUsedBytes( this.result.getByteTotal() );
for( final IAEItemStack out : plan )
{
IAEItemStack o = out.copy();
o.reset();
o.setStackSize( out.getStackSize() );
final IAEItemStack p = out.copy();
p.reset();
p.setStackSize( out.getCountRequestable() );
final IStorageGrid sg = this.getGrid().getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> items = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
IAEItemStack m = null;
if( c != null && this.result.isSimulation() )
{
m = o.copy();
o = items.extractItems( o, Actionable.SIMULATE, this.getActionSource() );
if( o == null )
{
o = m.copy();
o.setStackSize( 0 );
}
m.setStackSize( m.getStackSize() - o.getStackSize() );
}
if( o.getStackSize() > 0 )
{
a.appendItem( o );
}
if( p.getStackSize() > 0 )
{
b.appendItem( p );
}
if( c != null && m != null && m.getStackSize() > 0 )
{
c.appendItem( m );
}
}
for( final Object g : this.listeners )
{
if( g instanceof EntityPlayer )
{
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
if( c != null )
{
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g );
}
}
}
}
catch( final IOException e )
{
// :P
}
}
catch( final Throwable e )
{
this.getPlayerInv().player.sendMessage( new TextComponentString( "Error: " + e.toString() ) );
AELog.debug( e );
this.setValidContainer( false );
this.result = null;
}
this.setJob( null );
}
this.verifyPermissions( SecurityPermissions.CRAFT, false );
}
private IGrid getGrid()
{
final IActionHost h = ( (IActionHost) this.getTarget() );
return h.getActionableNode().getGrid();
}
private boolean cpuMatches( final ICraftingCPU c )
{
return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy();
}
private void sendCPUs()
{
Collections.sort( this.cpus );
if( this.getSelectedCpu() >= this.cpus.size() )
{
this.setSelectedCpu( -1 );
this.setCpuAvailableBytes( 0 );
this.setCpuCoProcessors( 0 );
this.setName( "" );
}
else if( this.getSelectedCpu() != -1 )
{
this.setName( this.cpus.get( this.getSelectedCpu() ).getName() );
this.setCpuAvailableBytes( this.cpus.get( this.getSelectedCpu() ).getSize() );
this.setCpuCoProcessors( this.cpus.get( this.getSelectedCpu() ).getProcessors() );
}
}
public void startJob()
{
GuiBridge originalGui = null;
final IActionHost ah = this.getActionHost();
if( ah instanceof WirelessTerminalGuiObject )
{
originalGui = GuiBridge.GUI_WIRELESS_TERM;
}
if( ah instanceof PartTerminal )
{
originalGui = GuiBridge.GUI_ME;
}
if( ah instanceof PartCraftingTerminal )
{
originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
}
if( ah instanceof PartPatternTerminal )
{
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
}
if( ah instanceof PartExpandedProcessingPatternTerminal )
{
originalGui = GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL;
}
if( this.result != null && !this.isSimulation() )
{
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
final ICraftingLink g = cc.submitJob( this.result, null, this.getSelectedCpu() == -1 ? null : this.cpus.get( this.getSelectedCpu() ).getCpu(), true, this.getActionSrc() );
this.setAutoStart( false );
if( g != null && originalGui != null && this.getOpenContext() != null )
{
final TileEntity te = this.getOpenContext().getTile();
Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui );
}
}
}
private IActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
}
@Override
public void removeListener( final IContainerListener c )
{
super.removeListener( c );
if( this.getJob() != null )
{
this.getJob().cancel( true );
this.setJob( null );
}
}
@Override
public void onContainerClosed( final EntityPlayer par1EntityPlayer )
{
super.onContainerClosed( par1EntityPlayer );
if( this.getJob() != null )
{
this.getJob().cancel( true );
this.setJob( null );
}
}
public World getWorld()
{
return this.getPlayerInv().player.world;
}
public boolean isAutoStart()
{
return this.autoStart;
}
public void setAutoStart( final boolean autoStart )
{
this.autoStart = autoStart;
}
public long getUsedBytes()
{
return this.bytesUsed;
}
private void setUsedBytes( final long bytesUsed )
{
this.bytesUsed = bytesUsed;
}
public long getCpuAvailableBytes()
{
return this.cpuBytesAvail;
}
private void setCpuAvailableBytes( final long cpuBytesAvail )
{
this.cpuBytesAvail = cpuBytesAvail;
}
public int getCpuCoProcessors()
{
return this.cpuCoProcessors;
}
private void setCpuCoProcessors( final int cpuCoProcessors )
{
this.cpuCoProcessors = cpuCoProcessors;
}
public int getSelectedCpu()
{
return this.selectedCpu;
}
private void setSelectedCpu( final int selectedCpu )
{
this.selectedCpu = selectedCpu;
}
public String getName()
{
return this.myName;
}
private void setName( @Nonnull final String myName )
{
this.myName = myName;
}
public boolean hasNoCPU()
{
return this.noCPU;
}
private void setNoCPU( final boolean noCPU )
{
this.noCPU = noCPU;
}
public boolean isSimulation()
{
return this.simulation;
}
private void setSimulation( final boolean simulation )
{
this.simulation = simulation;
}
private Future<ICraftingJob> getJob()
{
return this.job;
}
public void setJob( final Future<ICraftingJob> job )
{
this.job = job;
}
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Future;
public class ContainerCraftConfirm extends AEBaseContainer {
private final ArrayList<CraftingCPURecord> cpus = new ArrayList<>();
private Future<ICraftingJob> job;
private ICraftingJob result;
@GuiSync(0)
public long bytesUsed;
@GuiSync(1)
public long cpuBytesAvail;
@GuiSync(2)
public int cpuCoProcessors;
@GuiSync(3)
public boolean autoStart = false;
@GuiSync(4)
public boolean simulation = true;
@GuiSync(5)
public int selectedCpu = -1;
@GuiSync(6)
public boolean noCPU = true;
@GuiSync(7)
public String myName = "";
public ContainerCraftConfirm(final InventoryPlayer ip, final ITerminalHost te) {
super(ip, te);
}
public void cycleCpu(final boolean next) {
if (next) {
this.setSelectedCpu(this.getSelectedCpu() + 1);
} else {
this.setSelectedCpu(this.getSelectedCpu() - 1);
}
if (this.getSelectedCpu() < -1) {
this.setSelectedCpu(this.cpus.size() - 1);
} else if (this.getSelectedCpu() >= this.cpus.size()) {
this.setSelectedCpu(-1);
}
if (this.getSelectedCpu() == -1) {
this.setCpuAvailableBytes(0);
this.setCpuCoProcessors(0);
this.setName("");
} else {
this.setName(this.cpus.get(this.getSelectedCpu()).getName());
this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize());
this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors());
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for (final ICraftingCPU c : cpuSet) {
boolean found = false;
for (final CraftingCPURecord ccr : this.cpus) {
if (ccr.getCpu() == c) {
found = true;
break;
}
}
final boolean matched = this.cpuMatches(c);
if (matched) {
matches++;
}
if (found == !matched) {
changed = true;
}
}
if (changed || this.cpus.size() != matches) {
this.cpus.clear();
for (final ICraftingCPU c : cpuSet) {
if (this.cpuMatches(c)) {
this.cpus.add(new CraftingCPURecord(c.getAvailableStorage(), c.getCoProcessors(), c));
}
}
this.sendCPUs();
}
this.setNoCPU(this.cpus.isEmpty());
super.detectAndSendChanges();
if (this.getJob() != null && this.getJob().isDone()) {
try {
this.result = this.getJob().get();
if (!this.result.isSimulation()) {
this.setSimulation(false);
if (this.isAutoStart()) {
this.startJob();
return;
}
} else {
this.setSimulation(true);
}
try {
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate((byte) 0);
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate((byte) 1);
final PacketMEInventoryUpdate c = this.result.isSimulation() ? new PacketMEInventoryUpdate((byte) 2) : null;
final IItemList<IAEItemStack> plan = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
this.result.populatePlan(plan);
this.setUsedBytes(this.result.getByteTotal());
for (final IAEItemStack out : plan) {
IAEItemStack o = out.copy();
o.reset();
o.setStackSize(out.getStackSize());
final IAEItemStack p = out.copy();
p.reset();
p.setStackSize(out.getCountRequestable());
final IStorageGrid sg = this.getGrid().getCache(IStorageGrid.class);
final IMEInventory<IAEItemStack> items = sg.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
IAEItemStack m = null;
if (c != null && this.result.isSimulation()) {
m = o.copy();
o = items.extractItems(o, Actionable.SIMULATE, this.getActionSource());
if (o == null) {
o = m.copy();
o.setStackSize(0);
}
m.setStackSize(m.getStackSize() - o.getStackSize());
}
if (o.getStackSize() > 0) {
a.appendItem(o);
}
if (p.getStackSize() > 0) {
b.appendItem(p);
}
if (c != null && m != null && m.getStackSize() > 0) {
c.appendItem(m);
}
}
for (final Object g : this.listeners) {
if (g instanceof EntityPlayer) {
NetworkHandler.instance().sendTo(a, (EntityPlayerMP) g);
NetworkHandler.instance().sendTo(b, (EntityPlayerMP) g);
if (c != null) {
NetworkHandler.instance().sendTo(c, (EntityPlayerMP) g);
}
}
}
} catch (final IOException e) {
// :P
}
} catch (final Throwable e) {
this.getPlayerInv().player.sendMessage(new TextComponentString("Error: " + e));
AELog.debug(e);
this.setValidContainer(false);
this.result = null;
}
this.setJob(null);
}
this.verifyPermissions(SecurityPermissions.CRAFT, false);
}
private IGrid getGrid() {
final IActionHost h = ((IActionHost) this.getTarget());
return h.getActionableNode().getGrid();
}
private boolean cpuMatches(final ICraftingCPU c) {
return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy();
}
private void sendCPUs() {
Collections.sort(this.cpus);
if (this.getSelectedCpu() >= this.cpus.size()) {
this.setSelectedCpu(-1);
this.setCpuAvailableBytes(0);
this.setCpuCoProcessors(0);
this.setName("");
} else if (this.getSelectedCpu() != -1) {
this.setName(this.cpus.get(this.getSelectedCpu()).getName());
this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize());
this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors());
}
}
public void startJob() {
GuiBridge originalGui = null;
final IActionHost ah = this.getActionHost();
if (ah instanceof WirelessTerminalGuiObject) {
originalGui = GuiBridge.GUI_WIRELESS_TERM;
}
if (ah instanceof PartTerminal) {
originalGui = GuiBridge.GUI_ME;
}
if (ah instanceof PartCraftingTerminal) {
originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
}
if (ah instanceof PartPatternTerminal) {
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
}
if (ah instanceof PartExpandedProcessingPatternTerminal) {
originalGui = GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL;
}
if (this.result != null && !this.isSimulation()) {
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
final ICraftingLink g = cc.submitJob(this.result, null, this.getSelectedCpu() == -1 ? null : this.cpus.get(this.getSelectedCpu()).getCpu(), true, this.getActionSrc());
this.setAutoStart(false);
if (g != null && originalGui != null && this.getOpenContext() != null) {
final TileEntity te = this.getOpenContext().getTile();
Platform.openGUI(this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui);
}
}
}
private IActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget());
}
@Override
public void removeListener(final IContainerListener c) {
super.removeListener(c);
if (this.getJob() != null) {
this.getJob().cancel(true);
this.setJob(null);
}
}
@Override
public void onContainerClosed(final EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
if (this.getJob() != null) {
this.getJob().cancel(true);
this.setJob(null);
}
}
public World getWorld() {
return this.getPlayerInv().player.world;
}
public boolean isAutoStart() {
return this.autoStart;
}
public void setAutoStart(final boolean autoStart) {
this.autoStart = autoStart;
}
public long getUsedBytes() {
return this.bytesUsed;
}
private void setUsedBytes(final long bytesUsed) {
this.bytesUsed = bytesUsed;
}
public long getCpuAvailableBytes() {
return this.cpuBytesAvail;
}
private void setCpuAvailableBytes(final long cpuBytesAvail) {
this.cpuBytesAvail = cpuBytesAvail;
}
public int getCpuCoProcessors() {
return this.cpuCoProcessors;
}
private void setCpuCoProcessors(final int cpuCoProcessors) {
this.cpuCoProcessors = cpuCoProcessors;
}
public int getSelectedCpu() {
return this.selectedCpu;
}
private void setSelectedCpu(final int selectedCpu) {
this.selectedCpu = selectedCpu;
}
public String getName() {
return this.myName;
}
private void setName(@Nonnull final String myName) {
this.myName = myName;
}
public boolean hasNoCPU() {
return this.noCPU;
}
private void setNoCPU(final boolean noCPU) {
this.noCPU = noCPU;
}
public boolean isSimulation() {
return this.simulation;
}
private void setSimulation(final boolean simulation) {
this.simulation = simulation;
}
private Future<ICraftingJob> getJob() {
return this.job;
}
public void setJob(final Future<ICraftingJob> job) {
this.job = job;
}
}
@@ -19,13 +19,6 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.CraftingItemList;
@@ -48,236 +41,195 @@ import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import java.io.IOException;
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject
{
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject {
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private String cpuName = null;
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private String cpuName = null;
@GuiSync( 0 )
public long eta = -1;
@GuiSync(0)
public long eta = -1;
public ContainerCraftingCPU( final InventoryPlayer ip, final Object te )
{
super( ip, te );
final IActionHost host = (IActionHost) ( te instanceof IActionHost ? te : null );
public ContainerCraftingCPU(final InventoryPlayer ip, final Object te) {
super(ip, te);
final IActionHost host = (IActionHost) (te instanceof IActionHost ? te : null);
if( host != null && host.getActionableNode() != null )
{
this.setNetwork( host.getActionableNode().getGrid() );
}
if (host != null && host.getActionableNode() != null) {
this.setNetwork(host.getActionableNode().getGrid());
}
if( te instanceof TileCraftingTile )
{
this.setCPU( (ICraftingCPU) ( (IAEMultiBlock) te ).getCluster() );
}
if (te instanceof TileCraftingTile) {
this.setCPU((ICraftingCPU) ((IAEMultiBlock) te).getCluster());
}
if( this.getNetwork() == null && Platform.isServer() )
{
this.setValidContainer( false );
}
}
if (this.getNetwork() == null && Platform.isServer()) {
this.setValidContainer(false);
}
}
protected void setCPU( final ICraftingCPU c )
{
if( c == this.getMonitor() )
{
return;
}
protected void setCPU(final ICraftingCPU c) {
if (c == this.getMonitor()) {
return;
}
if( this.getMonitor() != null )
{
this.getMonitor().removeListener( this );
}
if (this.getMonitor() != null) {
this.getMonitor().removeListener(this);
}
for( final Object g : this.listeners )
{
if( g instanceof EntityPlayer )
{
try
{
NetworkHandler.instance().sendTo( new PacketValueConfig( "CraftingStatus", "Clear" ), (EntityPlayerMP) g );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
for (final Object g : this.listeners) {
if (g instanceof EntityPlayer) {
try {
NetworkHandler.instance().sendTo(new PacketValueConfig("CraftingStatus", "Clear"), (EntityPlayerMP) g);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
if( c instanceof CraftingCPUCluster )
{
this.cpuName = c.getName();
this.setMonitor( (CraftingCPUCluster) c );
this.list.resetStatus();
this.getMonitor().getListOfItem( this.list, CraftingItemList.ALL );
this.getMonitor().addListener( this, null );
this.setEstimatedTime( 0 );
}
else
{
this.setMonitor( null );
this.cpuName = "";
this.setEstimatedTime( -1 );
}
}
if (c instanceof CraftingCPUCluster) {
this.cpuName = c.getName();
this.setMonitor((CraftingCPUCluster) c);
this.list.resetStatus();
this.getMonitor().getListOfItem(this.list, CraftingItemList.ALL);
this.getMonitor().addListener(this, null);
this.setEstimatedTime(0);
} else {
this.setMonitor(null);
this.cpuName = "";
this.setEstimatedTime(-1);
}
}
public void cancelCrafting()
{
if( this.getMonitor() != null )
{
this.getMonitor().cancel();
}
this.setEstimatedTime( -1 );
}
public void cancelCrafting() {
if (this.getMonitor() != null) {
this.getMonitor().cancel();
}
this.setEstimatedTime(-1);
}
@Override
public void removeListener( final IContainerListener c )
{
super.removeListener( c );
@Override
public void removeListener(final IContainerListener c) {
super.removeListener(c);
if( this.listeners.isEmpty() && this.getMonitor() != null )
{
this.getMonitor().removeListener( this );
}
}
if (this.listeners.isEmpty() && this.getMonitor() != null) {
this.getMonitor().removeListener(this);
}
}
@Override
public void onContainerClosed( final EntityPlayer player )
{
super.onContainerClosed( player );
if( this.getMonitor() != null )
{
this.getMonitor().removeListener( this );
}
}
@Override
public void onContainerClosed(final EntityPlayer player) {
super.onContainerClosed(player);
if (this.getMonitor() != null) {
this.getMonitor().removeListener(this);
}
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() && this.getMonitor() != null )
{
if( this.getEstimatedTime() >= 0 )
{
final long elapsedTime = this.getMonitor().getElapsedTime();
final double remainingItems = this.getMonitor().getRemainingItemCount();
final double startItems = this.getMonitor().getStartItemCount();
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
this.setEstimatedTime( eta );
}
if( !this.list.isEmpty() )
{
try
{
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
@Override
public void detectAndSendChanges() {
if (Platform.isServer() && this.getMonitor() != null) {
if (this.getEstimatedTime() >= 0) {
final long elapsedTime = this.getMonitor().getElapsedTime();
final double remainingItems = this.getMonitor().getRemainingItemCount();
final double startItems = this.getMonitor().getStartItemCount();
final long eta = (long) (elapsedTime / Math.max(1d, (startItems - remainingItems)) * remainingItems);
this.setEstimatedTime(eta);
}
if (!this.list.isEmpty()) {
try {
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate((byte) 0);
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate((byte) 1);
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate((byte) 2);
for( final IAEItemStack out : this.list )
{
a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
}
for (final IAEItemStack out : this.list) {
a.appendItem(this.getMonitor().getItemStack(out, CraftingItemList.STORAGE));
b.appendItem(this.getMonitor().getItemStack(out, CraftingItemList.ACTIVE));
c.appendItem(this.getMonitor().getItemStack(out, CraftingItemList.PENDING));
}
this.list.resetStatus();
this.list.resetStatus();
for( final Object g : this.listeners )
{
if( g instanceof EntityPlayer )
{
if( !a.isEmpty() )
{
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
}
for (final Object g : this.listeners) {
if (g instanceof EntityPlayer) {
if (!a.isEmpty()) {
NetworkHandler.instance().sendTo(a, (EntityPlayerMP) g);
}
if( !b.isEmpty() )
{
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
}
if (!b.isEmpty()) {
NetworkHandler.instance().sendTo(b, (EntityPlayerMP) g);
}
if( !c.isEmpty() )
{
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g );
}
}
}
}
catch( final IOException e )
{
// :P
}
}
}
super.detectAndSendChanges();
}
if (!c.isEmpty()) {
NetworkHandler.instance().sendTo(c, (EntityPlayerMP) g);
}
}
}
} catch (final IOException e) {
// :P
}
}
}
super.detectAndSendChanges();
}
@Override
public boolean isValid( final Object verificationToken )
{
return true;
}
@Override
public boolean isValid(final Object verificationToken) {
return true;
}
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
{
for( IAEItemStack is : change )
{
is = is.copy();
is.setStackSize( 1 );
this.list.add( is );
}
}
@Override
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource) {
for (IAEItemStack is : change) {
is = is.copy();
is.setStackSize(1);
this.list.add(is);
}
}
@Override
public void onListUpdate()
{
@Override
public void onListUpdate() {
}
}
@Override
public String getCustomInventoryName()
{
return this.cpuName;
}
@Override
public String getCustomInventoryName() {
return this.cpuName;
}
@Override
public boolean hasCustomInventoryName()
{
return this.cpuName != null && this.cpuName.length() > 0;
}
@Override
public boolean hasCustomInventoryName() {
return this.cpuName != null && this.cpuName.length() > 0;
}
public long getEstimatedTime()
{
return this.eta;
}
public long getEstimatedTime() {
return this.eta;
}
private void setEstimatedTime( final long eta )
{
this.eta = eta;
}
private void setEstimatedTime(final long eta) {
this.eta = eta;
}
CraftingCPUCluster getMonitor()
{
return this.monitor;
}
CraftingCPUCluster getMonitor() {
return this.monitor;
}
private void setMonitor( final CraftingCPUCluster monitor )
{
this.monitor = monitor;
}
private void setMonitor(final CraftingCPUCluster monitor) {
this.monitor = monitor;
}
IGrid getNetwork()
{
return this.network;
}
IGrid getNetwork() {
return this.network;
}
private void setNetwork( final IGrid network )
{
this.network = network;
}
private void setNetwork(final IGrid network) {
this.network = network;
}
}
@@ -19,49 +19,43 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.*;
import appeng.api.networking.IGrid;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCraftingCPUsUpdate;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCraftingCPUsUpdate;
import appeng.util.Platform;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import java.io.IOException;
import java.util.*;
public class ContainerCraftingStatus extends ContainerCraftingCPU
{
public class ContainerCraftingStatus extends ContainerCraftingCPU {
private ImmutableSet<ICraftingCPU> lastCpuSet = null;
private List<CraftingCPUStatus> cpus = new ArrayList<CraftingCPUStatus>();
private final WeakHashMap<ICraftingCPU, Integer> cpuSerialMap = new WeakHashMap<>();
private int nextCpuSerial = 1;
private int lastUpdate = 0;
@GuiSync(5)
public int selectedCpuSerial = -1;
private ImmutableSet<ICraftingCPU> lastCpuSet = null;
private List<CraftingCPUStatus> cpus = new ArrayList<CraftingCPUStatus>();
private final WeakHashMap<ICraftingCPU, Integer> cpuSerialMap = new WeakHashMap<>();
private int nextCpuSerial = 1;
private int lastUpdate = 0;
@GuiSync(5)
public int selectedCpuSerial = -1;
public ContainerCraftingStatus( final InventoryPlayer ip, final ITerminalHost te )
{
super( ip, te );
}
public ContainerCraftingStatus(final InventoryPlayer ip, final ITerminalHost te) {
super(ip, te);
}
@Override
public void detectAndSendChanges()
{
IGrid network = this.getNetwork();
if( Platform.isServer() && network != null )
{
final ICraftingGrid cc = network.getCache( ICraftingGrid.class );
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
@Override
public void detectAndSendChanges() {
IGrid network = this.getNetwork();
if (Platform.isServer() && network != null) {
final ICraftingGrid cc = network.getCache(ICraftingGrid.class);
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
/*int matches = 0;
boolean changed = false;
@@ -105,131 +99,111 @@ public class ContainerCraftingStatus extends ContainerCraftingCPU
this.noCPU = this.cpus.isEmpty(); */
// Update at least once a second
++lastUpdate;
if (!cpuSet.equals( lastCpuSet ) || lastUpdate > 20) {
lastUpdate = 0;
lastCpuSet = cpuSet;
updateCpuList();
sendCPUs();
}
}
// Update at least once a second
++lastUpdate;
if (!cpuSet.equals(lastCpuSet) || lastUpdate > 20) {
lastUpdate = 0;
lastCpuSet = cpuSet;
updateCpuList();
sendCPUs();
}
}
// Clear selection if CPU is no longer in list
if (selectedCpuSerial != -1) {
if (cpus.stream().noneMatch(c -> c.getSerial() == selectedCpuSerial)) {
selectCPU(-1);
}
}
// Clear selection if CPU is no longer in list
if (selectedCpuSerial != -1) {
if (cpus.stream().noneMatch(c -> c.getSerial() == selectedCpuSerial)) {
selectCPU(-1);
}
}
// Select a suitable CPU if none is selected
if (selectedCpuSerial == -1) {
// Try busy CPUs first
for (CraftingCPUStatus cpu : cpus) {
if (cpu.getRemainingItems() > 0) {
selectCPU(cpu.getSerial());
break;
}
}
// If we couldn't find a busy one, just select the first
if (selectedCpuSerial == -1 && !cpus.isEmpty()) {
selectCPU(cpus.get(0).getSerial());
}
}
// Select a suitable CPU if none is selected
if (selectedCpuSerial == -1) {
// Try busy CPUs first
for (CraftingCPUStatus cpu : cpus) {
if (cpu.getRemainingItems() > 0) {
selectCPU(cpu.getSerial());
break;
}
}
// If we couldn't find a busy one, just select the first
if (selectedCpuSerial == -1 && !cpus.isEmpty()) {
selectCPU(cpus.get(0).getSerial());
}
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
private static final Comparator<CraftingCPUStatus> CPU_COMPARATOR = Comparator
.comparing((CraftingCPUStatus e) -> e.getName() == null || e.getName().isEmpty())
.thenComparing(e -> e.getName() != null ? e.getName() : "")
.thenComparingInt(CraftingCPUStatus::getSerial);
private static final Comparator<CraftingCPUStatus> CPU_COMPARATOR = Comparator
.comparing((CraftingCPUStatus e) -> e.getName() == null || e.getName().isEmpty())
.thenComparing(e -> e.getName() != null ? e.getName() : "")
.thenComparingInt(CraftingCPUStatus::getSerial);
private void updateCpuList()
{
this.cpus.clear();
for (ICraftingCPU cpu : lastCpuSet)
{
int serial = getOrAssignCpuSerial(cpu);
this.cpus.add( new CraftingCPUStatus( cpu, serial ) );
}
this.cpus.sort(CPU_COMPARATOR);
}
private void updateCpuList() {
this.cpus.clear();
for (ICraftingCPU cpu : lastCpuSet) {
int serial = getOrAssignCpuSerial(cpu);
this.cpus.add(new CraftingCPUStatus(cpu, serial));
}
this.cpus.sort(CPU_COMPARATOR);
}
private int getOrAssignCpuSerial( ICraftingCPU cpu )
{
return cpuSerialMap.computeIfAbsent( cpu, unused -> nextCpuSerial++ );
}
private int getOrAssignCpuSerial(ICraftingCPU cpu) {
return cpuSerialMap.computeIfAbsent(cpu, unused -> nextCpuSerial++);
}
private boolean cpuMatches( final ICraftingCPU c )
{
return c.isBusy();
}
private boolean cpuMatches(final ICraftingCPU c) {
return c.isBusy();
}
private void sendCPUs()
{
final PacketCraftingCPUsUpdate update;
for( final Object player : this.listeners )
{
if( player instanceof EntityPlayerMP)
{
try
{
NetworkHandler.instance.sendTo( new PacketCraftingCPUsUpdate( this.cpus ), (EntityPlayerMP) player );
}
catch( IOException e )
{
AELog.debug( e );
}
}
}
}
private void sendCPUs() {
final PacketCraftingCPUsUpdate update;
for (final Object player : this.listeners) {
if (player instanceof EntityPlayerMP) {
try {
NetworkHandler.instance.sendTo(new PacketCraftingCPUsUpdate(this.cpus), (EntityPlayerMP) player);
} catch (IOException e) {
AELog.debug(e);
}
}
}
}
public void selectCPU( int serial )
{
if (Platform.isServer())
{
if( serial < -1 )
{
serial = -1;
}
public void selectCPU(int serial) {
if (Platform.isServer()) {
if (serial < -1) {
serial = -1;
}
final int searchedSerial = serial;
if( serial > -1 && cpus.stream().noneMatch(c -> c.getSerial() == searchedSerial) )
{
serial = -1;
}
final int searchedSerial = serial;
if (serial > -1 && cpus.stream().noneMatch(c -> c.getSerial() == searchedSerial)) {
serial = -1;
}
ICraftingCPU newSelectedCpu = null;
if( serial != -1 )
{
for( ICraftingCPU cpu : lastCpuSet )
{
if( cpuSerialMap.getOrDefault( cpu, -1 ) == serial )
{
newSelectedCpu = cpu;
break;
}
}
}
ICraftingCPU newSelectedCpu = null;
if (serial != -1) {
for (ICraftingCPU cpu : lastCpuSet) {
if (cpuSerialMap.getOrDefault(cpu, -1) == serial) {
newSelectedCpu = cpu;
break;
}
}
}
if( newSelectedCpu != getMonitor() )
{
this.selectedCpuSerial = serial;
setCPU( newSelectedCpu );
}
}
}
if (newSelectedCpu != getMonitor()) {
this.selectedCpuSerial = serial;
setCPU(newSelectedCpu);
}
}
}
public List<CraftingCPUStatus> getCPUs()
{
return Collections.unmodifiableList( cpus );
}
public List<CraftingCPUStatus> getCPUs() {
return Collections.unmodifiableList(cpus);
}
public void postCPUUpdate( CraftingCPUStatus[] cpus )
{
this.cpus = Arrays.asList( cpus );
}
public void postCPUUpdate(CraftingCPUStatus[] cpus) {
this.cpus = Arrays.asList(cpus);
}
}
@@ -19,15 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerNull;
import appeng.container.slot.SlotCraftingMatrix;
@@ -38,102 +29,94 @@ import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperInvItemHandler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket
{
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket {
private final PartCraftingTerminal ct;
private final AppEngInternalInventory output = new AppEngInternalInventory( this, 1 );
private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9];
private final SlotCraftingTerm outputSlot;
private IRecipe currentRecipe;
private final PartCraftingTerminal ct;
private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1);
private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9];
private final SlotCraftingTerm outputSlot;
private IRecipe currentRecipe;
public ContainerCraftingTerm( final InventoryPlayer ip, final ITerminalHost monitorable )
{
super( ip, monitorable, false );
this.ct = (PartCraftingTerminal) monitorable;
public ContainerCraftingTerm(final InventoryPlayer ip, final ITerminalHost monitorable) {
super(ip, monitorable, false);
this.ct = (PartCraftingTerminal) monitorable;
final IItemHandler crafting = this.ct.getInventoryByName( "crafting" );
final IItemHandler crafting = this.ct.getInventoryByName("crafting");
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 3; x++ )
{
this.addSlotToContainer( this.craftingSlots[x + y * 3] = new SlotCraftingMatrix( this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18 ) );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlotToContainer(this.craftingSlots[x + y * 3] = new SlotCraftingMatrix(this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18));
}
}
this.addSlotToContainer( this.outputSlot = new SlotCraftingTerm( this.getPlayerInv().player, this.getActionSource(), this
.getPowerSource(), monitorable, crafting, crafting, this.output, 131, -72 + 18, this ) );
this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this
.getPowerSource(), monitorable, crafting, crafting, this.output, 131, -72 + 18, this));
this.bindPlayerInventory( ip, 0, 0 );
this.bindPlayerInventory(ip, 0, 0);
this.onCraftMatrixChanged( new WrapperInvItemHandler( crafting ) );
}
this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting));
}
/**
* Callback for when the crafting matrix is changed.
*/
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged( IInventory inventory )
{
final ContainerNull cn = new ContainerNull();
final InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 );
@Override
public void onCraftMatrixChanged(IInventory inventory) {
final ContainerNull cn = new ContainerNull();
final InventoryCrafting ic = new InventoryCrafting(cn, 3, 3);
for( int x = 0; x < 9; x++ )
{
ic.setInventorySlotContents( x, this.craftingSlots[x].getStack() );
}
for (int x = 0; x < 9; x++) {
ic.setInventorySlotContents(x, this.craftingSlots[x].getStack());
}
if( this.currentRecipe == null || !this.currentRecipe.matches( ic, this.getPlayerInv().player.world ) )
{
this.currentRecipe = CraftingManager.findMatchingRecipe( ic, this.getPlayerInv().player.world );
}
if (this.currentRecipe == null || !this.currentRecipe.matches(ic, this.getPlayerInv().player.world)) {
this.currentRecipe = CraftingManager.findMatchingRecipe(ic, this.getPlayerInv().player.world);
}
if( this.currentRecipe == null )
{
this.outputSlot.putStack( ItemStack.EMPTY );
}
else
{
final ItemStack craftingResult = this.currentRecipe.getCraftingResult( ic );
if (this.currentRecipe == null) {
this.outputSlot.putStack(ItemStack.EMPTY);
} else {
final ItemStack craftingResult = this.currentRecipe.getCraftingResult(ic);
this.outputSlot.putStack( craftingResult );
}
}
this.outputSlot.putStack(craftingResult);
}
}
@Override
public void saveChanges()
{
@Override
public void saveChanges() {
}
}
@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 IItemHandler getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return new PlayerInvWrapper( this.getInventoryPlayer() );
}
return this.ct.getInventoryByName( name );
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getInventoryPlayer());
}
return this.ct.getInventoryByName(name);
}
@Override
public boolean useRealItems()
{
return true;
}
@Override
public boolean useRealItems() {
return true;
}
public IRecipe getCurrentRecipe()
{
return this.currentRecipe;
}
public IRecipe getCurrentRecipe() {
return this.currentRecipe;
}
}
@@ -19,29 +19,24 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileDrive;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerDrive extends AEBaseContainer
{
public class ContainerDrive extends AEBaseContainer {
public ContainerDrive( final InventoryPlayer ip, final TileDrive drive )
{
super( ip, drive, null );
public ContainerDrive(final InventoryPlayer ip, final TileDrive drive) {
super(ip, drive, null);
for( int y = 0; y < 5; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive
.getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getInventoryPlayer() ) );
}
}
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 2; x++) {
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive
.getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getInventoryPlayer()));
}
}
this.bindPlayerInventory( ip, 0, 199 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 199 - /* height of player inventory */82);
}
}
@@ -29,525 +29,424 @@ import static appeng.helpers.PatternHelper.PROCESSING_INPUT_LIMIT;
import static appeng.helpers.PatternHelper.PROCESSING_OUTPUT_LIMIT;
public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket
{
private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] gridSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT];
private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT;
private final PartExpandedProcessingPatternTerminal expandedProcessingPatternTerminal;
public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] gridSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT];
private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT;
private final PartExpandedProcessingPatternTerminal expandedProcessingPatternTerminal;
public ContainerExpandedProcessingPatternTerm( InventoryPlayer ip, ITerminalHost monitorable )
{
super( ip, monitorable, false );
public ContainerExpandedProcessingPatternTerm(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable, false);
this.expandedProcessingPatternTerminal = (PartExpandedProcessingPatternTerminal) monitorable;
this.expandedProcessingPatternTerminal = (PartExpandedProcessingPatternTerminal) monitorable;
final IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" );
final IItemHandler output = this.getExpandedPatternTerminal().getInventoryByName( "output" );
final IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName("pattern");
final IItemHandler output = this.getExpandedPatternTerminal().getInventoryByName("output");
this.crafting = this.getExpandedPatternTerminal().getInventoryByName( "crafting" );
this.crafting = this.getExpandedPatternTerminal().getInventoryByName("crafting");
for( int y = 0; y < 4; y++ )
{
for( int x = 0; x < 4; x++ )
{
this.addSlotToContainer( this.gridSlots[x + y * 4] = new SlotFakeCraftingMatrix( this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18 ) );
}
}
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
this.addSlotToContainer(this.gridSlots[x + y * 4] = new SlotFakeCraftingMatrix(this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18));
}
}
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlotToContainer( this.outputSlots[x + y * 2] = new SlotPatternOutputs( output, this, x + y * 2, 96 + x * 18, -76 + y * 18, 0, 0, 1 ) );
this.outputSlots[x + y * 2].setRenderDisabled( false );
this.outputSlots[x + y * 2].setIIcon( -1 );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 2; x++) {
this.addSlotToContainer(this.outputSlots[x + y * 2] = new SlotPatternOutputs(output, this, x + y * 2, 96 + x * 18, -76 + y * 18, 0, 0, 1));
this.outputSlots[x + y * 2].setRenderDisabled(false);
this.outputSlots[x + y * 2].setIIcon(-1);
}
}
this.addSlotToContainer( this.patternSlotIN = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this.getInventoryPlayer() ) );
this.addSlotToContainer( this.patternSlotOUT = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this.getInventoryPlayer() ) );
this.addSlotToContainer(this.patternSlotIN = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this.getInventoryPlayer()));
this.addSlotToContainer(this.patternSlotOUT = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this.getInventoryPlayer()));
this.patternSlotOUT.setStackLimit( 1 );
this.patternSlotOUT.setStackLimit(1);
this.bindPlayerInventory( ip, 0, 0 );
}
this.bindPlayerInventory(ip, 0, 0);
}
@Override
public ItemStack transferStackInSlot( final EntityPlayer p, final int idx )
{
if( Platform.isClient() )
{
return ItemStack.EMPTY;
}
if( this.inventorySlots.get( idx ) instanceof SlotPlayerInv || this.inventorySlots.get( idx ) instanceof SlotPlayerHotBar )
{
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
if( AEApi.instance().definitions().materials().blankPattern().isSameAs( itemStack ) )
{
IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName( "pattern" );
ItemStack remainder = patternInv.insertItem( 0, itemStack, false );
clickSlot.putStack( remainder );
}
}
return super.transferStackInSlot( p, idx );
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}
if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(itemStack)) {
IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName("pattern");
ItemStack remainder = patternInv.insertItem(0, itemStack, false);
clickSlot.putStack(remainder);
}
}
return super.transferStackInSlot(p, idx);
}
@Override
public void saveChanges()
{
@Override
public void saveChanges() {
}
}
@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) {
}
}
public void encodeAndMoveToInventory()
{
encode();
ItemStack output = this.patternSlotOUT.getStack();
if( !output.isEmpty() )
{
if( !getPlayerInv().addItemStackToInventory( output ) )
{
getPlayerInv().player.dropItem( output, false );
}
this.patternSlotOUT.putStack( ItemStack.EMPTY );
}
}
public void encodeAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if (!output.isEmpty()) {
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.dropItem(output, false);
}
this.patternSlotOUT.putStack(ItemStack.EMPTY);
}
}
public void encode()
{
ItemStack output = this.patternSlotOUT.getStack();
public void encode() {
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if( in == null || out == null )
{
return;
}
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if( !output.isEmpty() && !this.isPattern( output ) )
{
return;
} // if nothing is there we should snag a new pattern.
else if( output.isEmpty() )
{
output = this.patternSlotIN.getStack();
if( output.isEmpty() || !this.isPattern( output ) )
{
return; // no blanks.
}
// first check the output slots, should either be null, or a pattern
if (!output.isEmpty() && !this.isPattern(output)) {
return;
} // if nothing is there we should snag a new pattern.
else if (output.isEmpty()) {
output = this.patternSlotIN.getStack();
if (output.isEmpty() || !this.isPattern(output)) {
return; // no blanks.
}
// remove one, and clear the input slot.
output.setCount( output.getCount() - 1 );
if( output.getCount() == 0 )
{
this.patternSlotIN.putStack( ItemStack.EMPTY );
}
// remove one, and clear the input slot.
output.setCount(output.getCount() - 1);
if (output.getCount() == 0) {
this.patternSlotIN.putStack(ItemStack.EMPTY);
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack( 1 );
if( maybePattern.isPresent() )
{
output = maybePattern.get();
this.patternSlotOUT.putStack( output );
}
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
output = maybePattern.get();
this.patternSlotOUT.putStack(output);
}
}
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for( final ItemStack i : in )
{
tagIn.appendTag( this.createItemTag( i ) );
}
for (final ItemStack i : in) {
tagIn.appendTag(this.createItemTag(i));
}
for( final ItemStack i : out )
{
tagOut.appendTag( this.createItemTag( i ) );
}
for (final ItemStack i : out) {
tagOut.appendTag(this.createItemTag(i));
}
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", false );
encodedValue.setBoolean( "substitute", false );
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("crafting", false);
encodedValue.setBoolean("substitute", false);
output.setTagCompound( encodedValue );
}
output.setTagCompound(encodedValue);
}
boolean isPattern( final ItemStack output )
{
if( output.isEmpty() )
{
return false;
}
boolean isPattern(final ItemStack output) {
if (output.isEmpty()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs( output );
isPattern |= definitions.materials().blankPattern().isSameAs( output );
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return isPattern;
}
return isPattern;
}
NBTBase createItemTag( final ItemStack i )
{
final NBTTagCompound c = new NBTTagCompound();
NBTBase createItemTag(final ItemStack i) {
final NBTTagCompound c = new NBTTagCompound();
if( !i.isEmpty() )
{
i.writeToNBT( c );
}
if (!i.isEmpty()) {
i.writeToNBT(c);
}
return c;
}
return c;
}
@Override
public boolean isSlotEnabled( final int idx )
{
return true;
}
@Override
public boolean isSlotEnabled(final int idx) {
return true;
}
protected ItemStack[] getInputs()
{
final ItemStack[] input = new ItemStack[16];
boolean hasValue = false;
protected ItemStack[] getInputs() {
final ItemStack[] input = new ItemStack[16];
boolean hasValue = false;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() )
{
hasValue = true;
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty()) {
hasValue = true;
}
}
if( hasValue )
{
return input;
}
if (hasValue) {
return input;
}
return null;
}
return null;
}
protected ItemStack[] getOutputs()
{
final List<ItemStack> list = new ArrayList<>( 3 );
boolean hasValue = false;
protected ItemStack[] getOutputs() {
final List<ItemStack> list = new ArrayList<>(3);
boolean hasValue = false;
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() > 0 )
{
list.add( out );
hasValue = true;
}
}
if (!out.isEmpty() && out.getCount() > 0) {
list.add(out);
hasValue = true;
}
}
if( hasValue )
{
return list.toArray( new ItemStack[0] );
}
return null;
}
if (hasValue) {
return list.toArray(new ItemStack[0]);
}
return null;
}
public void clear()
{
for( final Slot s : this.gridSlots )
{
s.putStack( ItemStack.EMPTY );
}
public void clear() {
for (final Slot s : this.gridSlots) {
s.putStack(ItemStack.EMPTY);
}
for( final Slot s : this.outputSlots )
{
s.putStack( ItemStack.EMPTY );
}
for (final Slot s : this.outputSlots) {
s.putStack(ItemStack.EMPTY);
}
this.detectAndSendChanges();
}
this.detectAndSendChanges();
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return new PlayerInvWrapper( this.getInventoryPlayer() );
}
return this.getExpandedPatternTerminal().getInventoryByName( name );
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getInventoryPlayer());
}
return this.getExpandedPatternTerminal().getInventoryByName(name);
}
@Override
public boolean useRealItems()
{
return false;
}
@Override
public boolean useRealItems() {
return false;
}
public PartExpandedProcessingPatternTerminal getExpandedPatternTerminal()
{
return this.expandedProcessingPatternTerminal;
}
public PartExpandedProcessingPatternTerminal getExpandedPatternTerminal() {
return this.expandedProcessingPatternTerminal;
}
public void multiply( int multiple )
{
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true;
public void multiply(int multiple) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize() )
{
canMultiplyInputs = false;
}
}
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize() )
{
canMultiplyOutputs = false;
}
}
if( canMultiplyInputs && canMultiplyOutputs )
{
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{
ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() )
{
craftingSlot.getStack().setCount( stack.getCount() * multiple );
}
}
for( OptionalSlotFake outputSlot : this.outputSlots )
{
ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() )
{
outputSlot.getStack().setCount( stack.getCount() * multiple );
}
}
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize()) {
canMultiplyInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize()) {
canMultiplyOutputs = false;
}
}
if (canMultiplyInputs && canMultiplyOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() * multiple);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() * multiple);
}
}
}
}
public void divide( int divide )
{
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDivideInputs = true;
boolean canDivideOutputs = true;
public void divide(int divide) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDivideInputs = true;
boolean canDivideOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() % divide != 0 )
{
canDivideInputs = false;
}
}
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() % divide != 0 )
{
canDivideOutputs = false;
}
}
if( canDivideInputs && canDivideOutputs )
{
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{
ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() )
{
craftingSlot.getStack().setCount( stack.getCount() / divide );
}
}
for( OptionalSlotFake outputSlot : this.outputSlots )
{
ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() )
{
outputSlot.getStack().setCount( stack.getCount() / divide );
}
}
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() % divide != 0) {
canDivideInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() % divide != 0) {
canDivideOutputs = false;
}
}
if (canDivideInputs && canDivideOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() / divide);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() / divide);
}
}
}
}
public void increase( int increase )
{
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true;
public void increase(int increase) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() + increase > input[x].getMaxStackSize() )
{
canIncreaseInputs = false;
}
}
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() + increase > out.getMaxStackSize() )
{
canIncreaseOutputs = false;
}
}
if( canIncreaseInputs && canIncreaseOutputs )
{
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{
ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() )
{
craftingSlot.getStack().setCount( stack.getCount() + increase );
}
}
for( OptionalSlotFake outputSlot : this.outputSlots )
{
ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() )
{
outputSlot.getStack().setCount( stack.getCount() + increase );
}
}
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() + increase > input[x].getMaxStackSize()) {
canIncreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() + increase > out.getMaxStackSize()) {
canIncreaseOutputs = false;
}
}
if (canIncreaseInputs && canIncreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + increase);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + increase);
}
}
}
}
public void decrease( int decrease )
{
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true;
public void decrease(int decrease) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getCount() - decrease < 1 )
{
canDecreaseInputs = false;
}
}
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
if( !out.isEmpty() && out.getCount() - decrease < 1 )
{
canDecreaseOutputs = false;
}
}
if( canDecreaseInputs && canDecreaseOutputs )
{
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{
ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() )
{
craftingSlot.getStack().setCount( stack.getCount() - decrease );
}
}
for( OptionalSlotFake outputSlot : this.outputSlots )
{
ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() )
{
outputSlot.getStack().setCount( stack.getCount() - decrease );
}
}
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() - decrease < 1) {
canDecreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() - decrease < 1) {
canDecreaseOutputs = false;
}
}
if (canDecreaseInputs && canDecreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() - decrease);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() - decrease);
}
}
}
}
public void maximizeCount()
{
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canGrowInputs = true;
boolean canGrowOutputs = true;
int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0;
public void maximizeCount() {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canGrowInputs = true;
boolean canGrowOutputs = true;
int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0;
for( int x = 0; x < this.gridSlots.length; x++ )
{
input[x] = this.gridSlots[x].getStack();
if( !input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth )
{
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
}
if( !input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize() )
{
canGrowInputs = false;
}
}
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
{
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
}
if( !out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize() )
{
canGrowOutputs = false;
}
}
if( canGrowInputs && canGrowOutputs )
{
int maxStackGrowth = Math.min( maxInputStackGrowth, maxOutputStackGrowth );
for( SlotFakeCraftingMatrix craftingSlot : this.gridSlots )
{
ItemStack stack = craftingSlot.getStack();
if( !stack.isEmpty() )
{
craftingSlot.getStack().setCount( stack.getCount() + maxStackGrowth );
}
}
for( OptionalSlotFake outputSlot : this.outputSlots )
{
ItemStack stack = outputSlot.getStack();
if( !stack.isEmpty() )
{
outputSlot.getStack().setCount( stack.getCount() + maxStackGrowth );
}
}
}
}
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth) {
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
}
if (!input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize()) {
canGrowInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
{
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
}
if (!out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize()) {
canGrowOutputs = false;
}
}
if (canGrowInputs && canGrowOutputs) {
int maxStackGrowth = Math.min(maxInputStackGrowth, maxOutputStackGrowth);
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
}
}
@Override
public void onSlotChange( final Slot s )
{
if( s == this.patternSlotOUT && Platform.isServer() )
{
for( final IContainerListener listener : this.listeners )
{
for( final Slot slot : this.inventorySlots )
{
if( slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix )
{
listener.sendSlotContents( this, slot.slotNumber, slot.getStack() );
}
}
if( listener instanceof EntityPlayerMP )
{
( (EntityPlayerMP) listener ).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
}
@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
for (final Slot slot : this.inventorySlots) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
listener.sendSlotContents(this, slot.slotNumber, slot.getStack());
}
}
if (listener instanceof EntityPlayerMP) {
((EntityPlayerMP) listener).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
}
}
@@ -19,119 +19,98 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.config.*;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartFormationPlane;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
public class ContainerFormationPlane extends ContainerUpgradeable
{
public class ContainerFormationPlane extends ContainerUpgradeable {
@GuiSync( 6 )
public YesNo placeMode;
@GuiSync(6)
public YesNo placeMode;
public ContainerFormationPlane( final InventoryPlayer ip, final PartFormationPlane te )
{
super( ip, te );
}
public ContainerFormationPlane(final InventoryPlayer ip, final PartFormationPlane te) {
super(ip, te);
}
@Override
protected int getHeight()
{
return 251;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig()
{
final int xo = 8;
final int yo = 23 + 6;
@Override
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" );
for( int y = 0; y < 7; y++ )
{
for( int x = 0; x < 9; x++ )
{
if( y < 2 )
{
this.addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
}
else
{
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
}
final IItemHandler config = this.getUpgradeable().getInventoryByName("config");
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
if (y < 2) {
this.addSlotToContainer(new SlotFakeTypeOnly(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(config, this, y * 9 + x, xo, yo, x, y, y - 2));
}
}
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer()))
.setNotDraggable());
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.setFuzzyMode( (FuzzyMode) this.getUpgradeable().getConfigManager().getSetting( Settings.FUZZY_MODE ) );
this.setPlaceMode( (YesNo) this.getUpgradeable().getConfigManager().getSetting( Settings.PLACE_BLOCK ) );
}
if (Platform.isServer()) {
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setPlaceMode((YesNo) this.getUpgradeable().getConfigManager().getSetting(Settings.PLACE_BLOCK));
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled( final int idx )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
return upgrades > idx;
}
public YesNo getPlaceMode()
{
return this.placeMode;
}
public YesNo getPlaceMode() {
return this.placeMode;
}
private void setPlaceMode( final YesNo placeMode )
{
this.placeMode = placeMode;
}
private void setPlaceMode(final YesNo placeMode) {
this.placeMode = placeMode;
}
}
@@ -19,35 +19,32 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.grindstone.TileGrinder;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
public class ContainerGrinder extends AEBaseContainer
{
public class ContainerGrinder extends AEBaseContainer {
public ContainerGrinder( final InventoryPlayer ip, final TileGrinder grinder )
{
super( ip, grinder, null );
public ContainerGrinder(final InventoryPlayer ip, final TileGrinder grinder) {
super(ip, grinder, null);
IItemHandler inv = grinder.getInternalInventory();
IItemHandler inv = grinder.getInternalInventory();
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17, this.getInventoryPlayer()));
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17, this.getInventoryPlayer()));
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17, this.getInventoryPlayer()));
this.addSlotToContainer( new SlotInaccessible( inv, 6, 80, 40 ) );
this.addSlotToContainer(new SlotInaccessible(inv, 6, 80, 40));
this.addSlotToContainer( new SlotOutput( inv, 3, 112, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( inv, 4, 112 + 18, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( inv, 5, 112 + 36, 63, 2 * 16 + 15 ) );
this.addSlotToContainer(new SlotOutput(inv, 3, 112, 63, 2 * 16 + 15));
this.addSlotToContainer(new SlotOutput(inv, 4, 112 + 18, 63, 2 * 16 + 15));
this.addSlotToContainer(new SlotOutput(inv, 5, 112 + 36, 63, 2 * 16 + 15));
this.bindPlayerInventory( ip, 0, 176 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 176 - /* height of player inventory */82);
}
}
@@ -19,124 +19,103 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FullnessMode;
import appeng.api.config.OperationMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.*;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileIOPort;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
public class ContainerIOPort extends ContainerUpgradeable
{
public class ContainerIOPort extends ContainerUpgradeable {
@GuiSync( 2 )
public FullnessMode fMode = FullnessMode.EMPTY;
@GuiSync( 3 )
public OperationMode opMode = OperationMode.EMPTY;
@GuiSync(2)
public FullnessMode fMode = FullnessMode.EMPTY;
@GuiSync(3)
public OperationMode opMode = OperationMode.EMPTY;
public ContainerIOPort( final InventoryPlayer ip, final TileIOPort te )
{
super( ip, te );
}
public ContainerIOPort(final InventoryPlayer ip, final TileIOPort te) {
super(ip, te);
}
@Override
protected int getHeight()
{
return 166;
}
@Override
protected int getHeight() {
return 166;
}
@Override
protected void setupConfig()
{
int offX = 19;
int offY = 17;
@Override
protected void setupConfig() {
int offX = 19;
int offY = 17;
final IItemHandler cells = this.getUpgradeable().getInventoryByName( "cells" );
final IItemHandler cells = this.getUpgradeable().getInventoryByName("cells");
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlotToContainer(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, cells, x + y * 2, offX + x * 18, offY + y * 18, this
.getInventoryPlayer() ) );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 2; x++) {
this.addSlotToContainer(
new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, cells, x + y * 2, offX + x * 18, offY + y * 18, this
.getInventoryPlayer()));
}
}
offX = 122;
offY = 17;
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlotToContainer(
new SlotOutput( cells, 6 + x + y * 2, offX + x * 18, offY + y * 18, SlotRestrictedInput.PlacableItemType.STORAGE_CELLS.IIcon ) );
}
}
offX = 122;
offY = 17;
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 2; x++) {
this.addSlotToContainer(
new SlotOutput(cells, 6 + x + y * 2, offX + x * 18, offY + y * 18, SlotRestrictedInput.PlacableItemType.STORAGE_CELLS.IIcon));
}
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades()
{
return 3;
}
@Override
public int availableUpgrades() {
return 3;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.setOperationMode( (OperationMode) this.getUpgradeable().getConfigManager().getSetting( Settings.OPERATION_MODE ) );
this.setFullMode( (FullnessMode) this.getUpgradeable().getConfigManager().getSetting( Settings.FULLNESS_MODE ) );
this.setRedStoneMode( (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED ) );
}
if (Platform.isServer()) {
this.setOperationMode((OperationMode) this.getUpgradeable().getConfigManager().getSetting(Settings.OPERATION_MODE));
this.setFullMode((FullnessMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FULLNESS_MODE));
this.setRedStoneMode((RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED));
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
public FullnessMode getFullMode()
{
return this.fMode;
}
public FullnessMode getFullMode() {
return this.fMode;
}
private void setFullMode( final FullnessMode fMode )
{
this.fMode = fMode;
}
private void setFullMode(final FullnessMode fMode) {
this.fMode = fMode;
}
public OperationMode getOperationMode()
{
return this.opMode;
}
public OperationMode getOperationMode() {
return this.opMode;
}
private void setOperationMode( final OperationMode opMode )
{
this.opMode = opMode;
}
private void setOperationMode(final OperationMode opMode) {
this.opMode = opMode;
}
}
@@ -19,11 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
import appeng.api.features.IInscriberRecipe;
@@ -33,6 +28,10 @@ import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileInscriber;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
/**
@@ -41,172 +40,141 @@ import appeng.util.Platform;
* @version rv2
* @since rv0
*/
public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider
{
public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider {
private final TileInscriber ti;
private final TileInscriber ti;
private final Slot top;
private final Slot middle;
private final Slot bottom;
private final Slot top;
private final Slot middle;
private final Slot bottom;
@GuiSync( 2 )
public int maxProcessingTime = -1;
@GuiSync(2)
public int maxProcessingTime = -1;
@GuiSync( 3 )
public int processingTime = -1;
@GuiSync(3)
public int processingTime = -1;
public ContainerInscriber( final InventoryPlayer ip, final TileInscriber te )
{
super( ip, te );
this.ti = te;
public ContainerInscriber(final InventoryPlayer ip, final TileInscriber te) {
super(ip, te);
this.ti = te;
IItemHandler inv = te.getInternalInventory();
IItemHandler inv = te.getInternalInventory();
this.addSlotToContainer(
this.top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0, 45, 16, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 1, 45, 62, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv, 2, 63, 39, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.top = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0, 45, 16, this.getInventoryPlayer()));
this.addSlotToContainer(
this.bottom = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 1, 45, 62, this.getInventoryPlayer()));
this.addSlotToContainer(
this.middle = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv, 2, 63, 39, this.getInventoryPlayer()));
this.addSlotToContainer( new SlotOutput( inv, 3, 113, 40, -1 ) );
}
this.addSlotToContainer(new SlotOutput(inv, 3, 113, 40, -1));
}
@Override
protected int getHeight()
{
return 176;
}
@Override
protected int getHeight() {
return 176;
}
@Override
/**
* Overridden super.setupConfig to prevent setting up the fake slots
*/
protected void setupConfig()
{
this.setupUpgrades();
}
@Override
/**
* Overridden super.setupConfig to prevent setting up the fake slots
*/
protected void setupConfig() {
this.setupUpgrades();
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades()
{
return 3;
}
@Override
public int availableUpgrades() {
return 3;
}
@Override
public void detectAndSendChanges()
{
this.standardDetectAndSendChanges();
@Override
public void detectAndSendChanges() {
this.standardDetectAndSendChanges();
if( Platform.isServer() )
{
this.maxProcessingTime = this.ti.getMaxProcessingTime();
this.processingTime = this.ti.getProcessingTime();
}
}
if (Platform.isServer()) {
this.maxProcessingTime = this.ti.getMaxProcessingTime();
this.processingTime = this.ti.getProcessingTime();
}
}
@Override
public boolean isValidForSlot( final Slot s, final ItemStack is )
{
final ItemStack top = this.ti.getInternalInventory().getStackInSlot( 0 );
final ItemStack bot = this.ti.getInternalInventory().getStackInSlot( 1 );
@Override
public boolean isValidForSlot(final Slot s, final ItemStack is) {
final ItemStack top = this.ti.getInternalInventory().getStackInSlot(0);
final ItemStack bot = this.ti.getInternalInventory().getStackInSlot(1);
if( s == this.middle )
{
IItemDefinition press = AEApi.instance().definitions().materials().namePress();
if( press.isSameAs( top ) || press.isSameAs( bot ) )
{
return !press.isSameAs( is );
}
if (s == this.middle) {
IItemDefinition press = AEApi.instance().definitions().materials().namePress();
if (press.isSameAs(top) || press.isSameAs(bot)) {
return !press.isSameAs(is);
}
boolean matches = false;
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
final boolean matchA = !top
.isEmpty() && ( Platform.itemComparisons().isSameItem( top, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) || Platform
.itemComparisons()
.isSameItem( top, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
final boolean matchB = !bot
.isEmpty() && ( Platform.itemComparisons().isSameItem( bot, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) || Platform
.itemComparisons()
.isSameItem( bot, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
boolean matches = false;
for (final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes()) {
final boolean matchA = !top
.isEmpty() && (Platform.itemComparisons().isSameItem(top, recipe.getTopOptional().orElse(ItemStack.EMPTY)) || Platform
.itemComparisons()
.isSameItem(top, recipe.getBottomOptional().orElse(ItemStack.EMPTY)));
final boolean matchB = !bot
.isEmpty() && (Platform.itemComparisons().isSameItem(bot, recipe.getTopOptional().orElse(ItemStack.EMPTY)) || Platform
.itemComparisons()
.isSameItem(bot, recipe.getBottomOptional().orElse(ItemStack.EMPTY)));
if( matchA || matchB )
{
matches = true;
for( final ItemStack option : recipe.getInputs() )
{
if( Platform.itemComparisons().isSameItem( is, option ) )
{
return true;
}
}
}
}
if( matches )
{
return false;
}
}
else if( ( s == this.top && !bot.isEmpty() ) || ( s == this.bottom && !top.isEmpty() ) )
{
ItemStack otherSlot;
if( s == this.top )
{
otherSlot = this.bottom.getStack();
}
else
{
otherSlot = this.top.getStack();
}
if (matchA || matchB) {
matches = true;
for (final ItemStack option : recipe.getInputs()) {
if (Platform.itemComparisons().isSameItem(is, option)) {
return true;
}
}
}
}
return !matches;
} else if ((s == this.top && !bot.isEmpty()) || (s == this.bottom && !top.isEmpty())) {
ItemStack otherSlot;
if (s == this.top) {
otherSlot = this.bottom.getStack();
} else {
otherSlot = this.top.getStack();
}
// name presses
final IItemDefinition namePress = AEApi.instance().definitions().materials().namePress();
if( namePress.isSameAs( otherSlot ) )
{
return namePress.isSameAs( is );
}
// name presses
final IItemDefinition namePress = AEApi.instance().definitions().materials().namePress();
if (namePress.isSameAs(otherSlot)) {
return namePress.isSameAs(is);
}
// everything else
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
boolean isValid = false;
if( Platform.itemComparisons().isSameItem( otherSlot, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) )
{
isValid = Platform.itemComparisons().isSameItem( is, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) );
}
else if( Platform.itemComparisons().isSameItem( otherSlot, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) )
{
isValid = Platform.itemComparisons().isSameItem( is, recipe.getTopOptional().orElse( ItemStack.EMPTY ) );
}
// everything else
for (final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes()) {
boolean isValid = false;
if (Platform.itemComparisons().isSameItem(otherSlot, recipe.getTopOptional().orElse(ItemStack.EMPTY))) {
isValid = Platform.itemComparisons().isSameItem(is, recipe.getBottomOptional().orElse(ItemStack.EMPTY));
} else if (Platform.itemComparisons().isSameItem(otherSlot, recipe.getBottomOptional().orElse(ItemStack.EMPTY))) {
isValid = Platform.itemComparisons().isSameItem(is, recipe.getTopOptional().orElse(ItemStack.EMPTY));
}
if( isValid )
{
return true;
}
}
return false;
}
if (isValid) {
return true;
}
}
return false;
}
return true;
}
return true;
}
@Override
public int getCurrentProgress()
{
return this.processingTime;
}
@Override
public int getCurrentProgress() {
return this.processingTime;
}
@Override
public int getMaxProgress()
{
return this.maxProcessingTime;
}
@Override
public int getMaxProgress() {
return this.maxProcessingTime;
}
}
@@ -19,133 +19,114 @@
package appeng.container.implementations;
import appeng.api.config.Upgrades;
import appeng.container.slot.*;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.util.IConfigManager;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.*;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerInterface extends ContainerUpgradeable implements IOptionalSlotHost
{
public class ContainerInterface extends ContainerUpgradeable implements IOptionalSlotHost {
private final DualityInterface myDuality;
private final DualityInterface myDuality;
@GuiSync( 3 )
public YesNo bMode = YesNo.NO;
@GuiSync(3)
public YesNo bMode = YesNo.NO;
@GuiSync( 4 )
public YesNo iTermMode = YesNo.YES;
@GuiSync(4)
public YesNo iTermMode = YesNo.YES;
@GuiSync( 7 )
public int patternExpansions = 0;
@GuiSync(7)
public int patternExpansions = 0;
public ContainerInterface( final InventoryPlayer ip, final IInterfaceHost te )
{
super( ip, te.getInterfaceDuality().getHost() );
public ContainerInterface(final InventoryPlayer ip, final IInterfaceHost te) {
super(ip, te.getInterfaceDuality().getHost());
this.myDuality = te.getInterfaceDuality();
this.myDuality = te.getInterfaceDuality();
for (int row = 0 ; row < 4 ; ++row)
{
for( int x = 0; x < 9; x++ )
{
this.addSlotToContainer( new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, this.myDuality
.getPatterns(), this, x + row * 9, 8 + 18 * x, 97 + ( 18 * row ), row, this.getInventoryPlayer() ).setStackLimit( 1 ) );
}
}
for (int row = 0; row < 4; ++row) {
for (int x = 0; x < 9; x++) {
this.addSlotToContainer(new OptionalSlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, this.myDuality
.getPatterns(), this, x + row * 9, 8 + 18 * x, 97 + (18 * row), row, this.getInventoryPlayer()).setStackLimit(1));
}
}
for( int x = 0; x < DualityInterface.NUMBER_OF_CONFIG_SLOTS; x++ )
{
this.addSlotToContainer( new SlotFake( this.myDuality.getConfig(), x, 8 + 18 * x, 35 ) );
}
for (int x = 0; x < DualityInterface.NUMBER_OF_CONFIG_SLOTS; x++) {
this.addSlotToContainer(new SlotFake(this.myDuality.getConfig(), x, 8 + 18 * x, 35));
}
for( int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++ )
{
this.addSlotToContainer( new SlotNormal( this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18 ) );
}
}
for (int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++) {
this.addSlotToContainer(new SlotNormal(this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18));
}
}
@Override
protected int getHeight()
{
return 256;
}
@Override
protected int getHeight() {
return 256;
}
@Override
protected void setupConfig()
{
this.setupUpgrades();
}
@Override
protected void setupConfig() {
this.setupUpgrades();
}
@Override
public int availableUpgrades()
{
return 4;
}
@Override
public int availableUpgrades() {
return 4;
}
@Override
public boolean isSlotEnabled( final int idx )
{
return myDuality.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION) >= idx;
}
@Override
public boolean isSlotEnabled(final int idx) {
return myDuality.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION) >= idx;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (patternExpansions != getPatternUpgrades())
{
patternExpansions = getPatternUpgrades();
this.myDuality.dropExcessPatterns();
}
super.detectAndSendChanges();
}
if (patternExpansions != getPatternUpgrades()) {
patternExpansions = getPatternUpgrades();
this.myDuality.dropExcessPatterns();
}
super.detectAndSendChanges();
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue ) {
super.onUpdate(field, oldValue, newValue);
if ( Platform.isClient() && field.equals("patternExpansions"))
this.myDuality.dropExcessPatterns();
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
super.onUpdate(field, oldValue, newValue);
if (Platform.isClient() && field.equals("patternExpansions"))
this.myDuality.dropExcessPatterns();
}
@Override
protected void loadSettingsFromHost( final IConfigManager cm )
{
this.setBlockingMode( (YesNo) cm.getSetting( Settings.BLOCK ) );
this.setInterfaceTerminalMode( (YesNo) cm.getSetting( Settings.INTERFACE_TERMINAL ) );
}
@Override
protected void loadSettingsFromHost(final IConfigManager cm) {
this.setBlockingMode((YesNo) cm.getSetting(Settings.BLOCK));
this.setInterfaceTerminalMode((YesNo) cm.getSetting(Settings.INTERFACE_TERMINAL));
}
public YesNo getBlockingMode()
{
return this.bMode;
}
public YesNo getBlockingMode() {
return this.bMode;
}
private void setBlockingMode( final YesNo bMode )
{
this.bMode = bMode;
}
private void setBlockingMode(final YesNo bMode) {
this.bMode = bMode;
}
public YesNo getInterfaceTerminalMode()
{
return this.iTermMode;
}
public YesNo getInterfaceTerminalMode() {
return this.iTermMode;
}
private void setInterfaceTerminalMode( final YesNo iTermMode )
{
this.iTermMode = iTermMode;
}
private void setInterfaceTerminalMode(final YesNo iTermMode) {
this.iTermMode = iTermMode;
}
public int getPatternUpgrades()
{
return this.myDuality.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION );
}
public int getPatternUpgrades() {
return this.myDuality.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION);
}
}
@@ -19,20 +19,6 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import appeng.parts.reporting.PartInterfaceConfigurationTerminal;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.networking.IGrid;
@@ -45,356 +31,303 @@ import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction;
import appeng.parts.misc.PartInterface;
import appeng.parts.reporting.PartInterfaceConfigurationTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperRangeItemHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public final class ContainerInterfaceConfigurationTerminal extends AEBaseContainer
{
public final class ContainerInterfaceConfigurationTerminal extends AEBaseContainer {
/**
* this stuff is all server side..
*/
/**
* this stuff is all server side..
*/
private static long autoBase = Long.MIN_VALUE;
private final Map<IInterfaceHost, ConfigTracker> diList = new HashMap<>();
private final Map<Long, ConfigTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
private static long autoBase = Long.MIN_VALUE;
private final Map<IInterfaceHost, ConfigTracker> diList = new HashMap<>();
private final Map<Long, ConfigTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
public ContainerInterfaceConfigurationTerminal( final InventoryPlayer ip, final PartInterfaceConfigurationTerminal anchor )
{
super( ip, anchor );
public ContainerInterfaceConfigurationTerminal(final InventoryPlayer ip, final PartInterfaceConfigurationTerminal anchor) {
super(ip, anchor);
if( Platform.isServer() )
{
this.grid = anchor.getActionableNode().getGrid();
}
if (Platform.isServer()) {
this.grid = anchor.getActionableNode().getGrid();
}
this.bindPlayerInventory( ip, 14, 235 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 14, 235 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isClient() )
{
return;
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
super.detectAndSendChanges();
super.detectAndSendChanges();
if( this.grid == null )
{
return;
}
if (this.grid == null) {
return;
}
int total = 0;
boolean missing = false;
int total = 0;
boolean missing = false;
final IActionHost host = this.getActionHost();
if( host != null )
{
final IGridNode agn = host.getActionableNode();
if( agn != null && agn.isActive() )
{
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
{
if( gn.isActive() )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
{
continue;
}
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.grid.getMachines(TileInterface.class)) {
if (gn.isActive()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if (ih.getInterfaceDuality().getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.NO) {
continue;
}
final ConfigTracker t = this.diList.get( ih );
final ConfigTracker t = this.diList.get(ih);
if( t == null )
{
missing = true;
}
else
{
final DualityInterface dual = ih.getInterfaceDuality();
if( !t.unlocalizedName.equals( dual.getTermName() ) )
{
missing = true;
}
}
if (t == null) {
missing = true;
} else {
final DualityInterface dual = ih.getInterfaceDuality();
if (!t.unlocalizedName.equals(dual.getTermName())) {
missing = true;
}
}
total++;
}
}
total++;
}
}
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
{
if( gn.isActive() )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
{
continue;
}
for (final IGridNode gn : this.grid.getMachines(PartInterface.class)) {
if (gn.isActive()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if (ih.getInterfaceDuality().getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.NO) {
continue;
}
final ConfigTracker t = this.diList.get( ih );
final ConfigTracker t = this.diList.get(ih);
if( t == null )
{
missing = true;
}
else
{
final DualityInterface dual = ih.getInterfaceDuality();
if( !t.unlocalizedName.equals( dual.getTermName() ) )
{
missing = true;
}
}
if (t == null) {
missing = true;
} else {
final DualityInterface dual = ih.getInterfaceDuality();
if (!t.unlocalizedName.equals(dual.getTermName())) {
missing = true;
}
}
total++;
}
}
}
}
total++;
}
}
}
}
if( total != this.diList.size() || missing )
{
this.regenList( this.data );
}
else
{
for( final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet() )
{
final ConfigTracker inv = en.getValue();
for( int x = 0; x < inv.server.getSlots(); x++ )
{
if( this.isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
{
this.addItems( this.data, inv, x, 1 );
}
}
}
}
if (total != this.diList.size() || missing) {
this.regenList(this.data);
} else {
for (final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet()) {
final ConfigTracker inv = en.getValue();
for (int x = 0; x < inv.server.getSlots(); x++) {
if (this.isDifferent(inv.server.getStackInSlot(x), inv.client.getStackInSlot(x))) {
this.addItems(this.data, inv, x, 1);
}
}
}
}
if( !this.data.hasNoTags() )
{
try
{
NetworkHandler.instance().sendTo( new PacketCompressedNBT( this.data ), (EntityPlayerMP) this.getPlayerInv().player );
}
catch( final IOException e )
{
// :P
}
if (!this.data.hasNoTags()) {
try {
NetworkHandler.instance().sendTo(new PacketCompressedNBT(this.data), (EntityPlayerMP) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
this.data = new NBTTagCompound();
}
}
this.data = new NBTTagCompound();
}
}
public ConfigTracker getSlotByID( long id )
{
return this.byId.get( id );
}
public ConfigTracker getSlotByID(long id) {
return this.byId.get(id);
}
@Override
public void doAction( final EntityPlayerMP player, final InventoryAction action, final int slot, final long id )
{
final ConfigTracker inv = this.byId.get( id );
if( inv != null )
{
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
final IItemHandler theSlot = new WrapperRangeItemHandler( inv.server, slot, slot + 1 );
@Override
public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) {
final ConfigTracker inv = this.byId.get(id);
if (inv != null) {
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
final IItemHandler theSlot = new WrapperRangeItemHandler(inv.server, slot, slot + 1);
ItemStack inSlot = theSlot.getStackInSlot( 0 );
ItemStack inSlot = theSlot.getStackInSlot(0);
switch ( action )
{
case PICKUP_OR_SET_DOWN:
if( hasItemInHand )
{
ItemHandlerUtil.setStackInSlot( theSlot, 0, player.inventory.getItemStack().copy() );
}
else
{
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
}
break;
case PLACE_SINGLE:
if( inSlot.getMaxStackSize() > inSlot.getCount() )
{
inSlot.grow( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
break;
case PICKUP_SINGLE:
if( theSlot.getStackInSlot( 0 ).getCount() > 1 )
{
inSlot.shrink( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
break;
case SPLIT_OR_PLACE_SINGLE:
if( hasItemInHand )
{
if( ItemStack.areItemsEqual( inSlot, player.inventory.getItemStack() ) && ItemStack.areItemStackTagsEqual( inSlot, player.inventory.getItemStack() ) )
{
inSlot.grow( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot.copy() );
}
else
{
ItemStack configuredStack = player.inventory.getItemStack().copy();
configuredStack.setCount( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, configuredStack );
}
switch (action) {
case PICKUP_OR_SET_DOWN:
if (hasItemInHand) {
ItemHandlerUtil.setStackInSlot(theSlot, 0, player.inventory.getItemStack().copy());
} else {
ItemHandlerUtil.setStackInSlot(theSlot, 0, ItemStack.EMPTY);
}
break;
case PLACE_SINGLE:
if (inSlot.getMaxStackSize() > inSlot.getCount()) {
inSlot.grow(1);
ItemHandlerUtil.setStackInSlot(theSlot, 0, inSlot);
}
break;
case PICKUP_SINGLE:
if (theSlot.getStackInSlot(0).getCount() > 1) {
inSlot.shrink(1);
ItemHandlerUtil.setStackInSlot(theSlot, 0, inSlot);
}
break;
case SPLIT_OR_PLACE_SINGLE:
if (hasItemInHand) {
if (ItemStack.areItemsEqual(inSlot, player.inventory.getItemStack()) && ItemStack.areItemStackTagsEqual(inSlot, player.inventory.getItemStack())) {
inSlot.grow(1);
ItemHandlerUtil.setStackInSlot(theSlot, 0, inSlot.copy());
} else {
ItemStack configuredStack = player.inventory.getItemStack().copy();
configuredStack.setCount(1);
ItemHandlerUtil.setStackInSlot(theSlot, 0, configuredStack);
}
}
else if( !inSlot.isEmpty() )
{
inSlot.shrink( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot.copy() );
}
} else if (!inSlot.isEmpty()) {
inSlot.shrink(1);
ItemHandlerUtil.setStackInSlot(theSlot, 0, inSlot.copy());
}
break;
case SHIFT_CLICK:
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
break;
break;
case SHIFT_CLICK:
ItemHandlerUtil.setStackInSlot(theSlot, 0, ItemStack.EMPTY);
break;
case CREATIVE_DUPLICATE:
case CREATIVE_DUPLICATE:
if( player.capabilities.isCreativeMode && hasItemInHand )
{
ItemHandlerUtil.setStackInSlot( theSlot, 0, player.inventory.getItemStack().copy() );
}
if (player.capabilities.isCreativeMode && hasItemInHand) {
ItemHandlerUtil.setStackInSlot(theSlot, 0, player.inventory.getItemStack().copy());
}
break;
default:
return;
}
break;
default:
return;
}
this.updateHeld( player );
}
}
this.updateHeld(player);
}
}
private void regenList( final NBTTagCompound data )
{
this.byId.clear();
this.diList.clear();
private void regenList(final NBTTagCompound data) {
this.byId.clear();
this.diList.clear();
final IActionHost host = this.getActionHost();
if( host != null )
{
final IGridNode agn = host.getActionableNode();
if( agn != null && agn.isActive() )
{
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new ConfigTracker( dual, dual.getConfig(), dual.getTermName() ) );
}
}
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.grid.getMachines(TileInterface.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new ConfigTracker(dual, dual.getConfig(), dual.getTermName()));
}
}
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new ConfigTracker( dual, dual.getConfig(), dual.getTermName() ) );
}
}
}
}
for (final IGridNode gn : this.grid.getMachines(PartInterface.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new ConfigTracker(dual, dual.getConfig(), dual.getTermName()));
}
}
}
}
data.setBoolean( "clear", true );
data.setBoolean("clear", true);
for( final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet() )
{
final ConfigTracker inv = en.getValue();
this.byId.put( inv.which, inv );
this.addItems( data, inv, 0, inv.server.getSlots() );
}
}
for (final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet()) {
final ConfigTracker inv = en.getValue();
this.byId.put(inv.which, inv);
this.addItems(data, inv, 0, inv.server.getSlots());
}
}
private boolean isDifferent( final ItemStack a, final ItemStack b )
{
if( a.isEmpty() && b.isEmpty() )
{
return false;
}
private boolean isDifferent(final ItemStack a, final ItemStack b) {
if (a.isEmpty() && b.isEmpty()) {
return false;
}
if( a.isEmpty() || b.isEmpty() )
{
return true;
}
if (a.isEmpty() || b.isEmpty()) {
return true;
}
return !ItemStack.areItemStacksEqual( a, b );
}
return !ItemStack.areItemStacksEqual(a, b);
}
private void addItems( final NBTTagCompound data, final ConfigTracker inv, final int offset, final int length )
{
final String name = '=' + Long.toString( inv.which, Character.MAX_RADIX );
final NBTTagCompound tag = data.getCompoundTag( name );
private void addItems(final NBTTagCompound data, final ConfigTracker inv, final int offset, final int length) {
final String name = '=' + Long.toString(inv.which, Character.MAX_RADIX);
final NBTTagCompound tag = data.getCompoundTag(name);
if( tag.hasNoTags() )
{
tag.setLong( "sortBy", inv.sortBy );
tag.setString( "un", inv.unlocalizedName );
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
tag.setInteger( "dim", inv.dim );
}
if (tag.hasNoTags()) {
tag.setLong("sortBy", inv.sortBy);
tag.setString("un", inv.unlocalizedName);
tag.setTag("pos", NBTUtil.createPosTag(inv.pos));
tag.setInteger("dim", inv.dim);
}
for( int x = 0; x < length; x++ )
{
final NBTTagCompound itemNBT = new NBTTagCompound();
for (int x = 0; x < length; x++) {
final NBTTagCompound itemNBT = new NBTTagCompound();
final ItemStack is = inv.server.getStackInSlot( x + offset );
final ItemStack is = inv.server.getStackInSlot(x + offset);
// "update" client side.
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
// "update" client side.
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if( !is.isEmpty() )
{
is.writeToNBT( itemNBT );
}
if (!is.isEmpty()) {
is.writeToNBT(itemNBT);
}
tag.setTag( Integer.toString( x + offset ), itemNBT );
}
tag.setTag(Integer.toString(x + offset), itemNBT);
}
data.setTag( name, tag );
}
data.setTag(name, tag);
}
public static class ConfigTracker
{
public static class ConfigTracker {
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IItemHandler client;
private final IItemHandler server;
private final BlockPos pos;
private final int dim;
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IItemHandler client;
private final IItemHandler server;
private final BlockPos pos;
private final int dim;
public ConfigTracker( final DualityInterface dual, final IItemHandler configSlots, final String unlocalizedName )
{
this.server = configSlots;
this.client = new AppEngInternalInventory( null, this.server.getSlots() );
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
this.pos = dual.getLocation().getPos();
this.dim = dual.getLocation().getWorld().provider.getDimension();
}
public ConfigTracker(final DualityInterface dual, final IItemHandler configSlots, final String unlocalizedName) {
this.server = configSlots;
this.client = new AppEngInternalInventory(null, this.server.getSlots());
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
this.pos = dual.getLocation().getPos();
this.dim = dual.getLocation().getWorld().provider.getDimension();
}
public IItemHandler getServer()
{
return server;
}
}
public IItemHandler getServer() {
return server;
}
}
}
@@ -19,21 +19,8 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import appeng.api.config.Upgrades;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
@@ -57,414 +44,347 @@ import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.WrapperRangeItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public final class ContainerInterfaceTerminal extends AEBaseContainer
{
public final class ContainerInterfaceTerminal extends AEBaseContainer {
/**
* this stuff is all server side..
*/
/**
* this stuff is all server side..
*/
private static long autoBase = Long.MIN_VALUE;
private final Map<IInterfaceHost, InvTracker> diList = new HashMap<>();
private final Map<Long, InvTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
private static long autoBase = Long.MIN_VALUE;
private final Map<IInterfaceHost, InvTracker> diList = new HashMap<>();
private final Map<Long, InvTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
public ContainerInterfaceTerminal( final InventoryPlayer ip, final PartInterfaceTerminal anchor )
{
super( ip, anchor );
public ContainerInterfaceTerminal(final InventoryPlayer ip, final PartInterfaceTerminal anchor) {
super(ip, anchor);
if( Platform.isServer() )
{
this.grid = anchor.getActionableNode().getGrid();
}
if (Platform.isServer()) {
this.grid = anchor.getActionableNode().getGrid();
}
this.bindPlayerInventory( ip, 14, 256 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 14, 256 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isClient() )
{
return;
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
super.detectAndSendChanges();
super.detectAndSendChanges();
if( this.grid == null )
{
return;
}
if (this.grid == null) {
return;
}
int total = 0;
boolean missing = false;
int total = 0;
boolean missing = false;
final IActionHost host = this.getActionHost();
if( host != null )
{
final IGridNode agn = host.getActionableNode();
if( agn != null && agn.isActive() )
{
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
{
if( gn.isActive() )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
{
continue;
}
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.grid.getMachines(TileInterface.class)) {
if (gn.isActive()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if (ih.getInterfaceDuality().getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.NO) {
continue;
}
final InvTracker t = this.diList.get( ih );
final InvTracker t = this.diList.get(ih);
if( t == null )
{
missing = true;
}
else
{
final DualityInterface dual = ih.getInterfaceDuality();
if( !t.unlocalizedName.equals( dual.getTermName() ) )
{
missing = true;
}
}
if (t == null) {
missing = true;
} else {
final DualityInterface dual = ih.getInterfaceDuality();
if (!t.unlocalizedName.equals(dual.getTermName())) {
missing = true;
}
}
total++;
}
}
total++;
}
}
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
{
if( gn.isActive() )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
{
continue;
}
for (final IGridNode gn : this.grid.getMachines(PartInterface.class)) {
if (gn.isActive()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if (ih.getInterfaceDuality().getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.NO) {
continue;
}
final InvTracker t = this.diList.get( ih );
final InvTracker t = this.diList.get(ih);
if( t == null )
{
missing = true;
}
else
{
final DualityInterface dual = ih.getInterfaceDuality();
if( !t.unlocalizedName.equals( dual.getTermName() ) )
{
missing = true;
}
}
if (t == null) {
missing = true;
} else {
final DualityInterface dual = ih.getInterfaceDuality();
if (!t.unlocalizedName.equals(dual.getTermName())) {
missing = true;
}
}
total++;
}
}
}
}
total++;
}
}
}
}
if( total != this.diList.size() || missing )
{
this.regenList( this.data );
}
else
{
for( final Entry<IInterfaceHost, InvTracker> en : this.diList.entrySet() )
{
final InvTracker inv = en.getValue();
for( int x = 0; x < inv.server.getSlots(); x++ )
{
if( this.isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
{
this.addItems( this.data, inv, x, 1 );
}
}
}
}
if (total != this.diList.size() || missing) {
this.regenList(this.data);
} else {
for (final Entry<IInterfaceHost, InvTracker> en : this.diList.entrySet()) {
final InvTracker inv = en.getValue();
for (int x = 0; x < inv.server.getSlots(); x++) {
if (this.isDifferent(inv.server.getStackInSlot(x), inv.client.getStackInSlot(x))) {
this.addItems(this.data, inv, x, 1);
}
}
}
}
if( !this.data.hasNoTags() )
{
try
{
NetworkHandler.instance().sendTo( new PacketCompressedNBT( this.data ), (EntityPlayerMP) this.getPlayerInv().player );
}
catch( final IOException e )
{
// :P
}
if (!this.data.hasNoTags()) {
try {
NetworkHandler.instance().sendTo(new PacketCompressedNBT(this.data), (EntityPlayerMP) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
this.data = new NBTTagCompound();
}
}
this.data = new NBTTagCompound();
}
}
@Override
public void doAction( final EntityPlayerMP player, final InventoryAction action, final int slot, final long id )
{
final InvTracker inv = this.byId.get( id );
if( inv != null )
{
final ItemStack is = inv.server.getStackInSlot( slot );
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
@Override
public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) {
final InvTracker inv = this.byId.get(id);
if (inv != null) {
final ItemStack is = inv.server.getStackInSlot(slot);
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
final InventoryAdaptor playerHand = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
final InventoryAdaptor playerHand = new AdaptorItemHandler(new WrapperCursorItemHandler(player.inventory));
final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
final IItemHandler theSlot = new WrapperFilteredItemHandler(new WrapperRangeItemHandler(inv.server, slot, slot + 1), new PatternSlotFilter());
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler(theSlot);
IItemHandler interfaceHandler = inv.server;
boolean canInsert = true;
IItemHandler interfaceHandler = inv.server;
boolean canInsert = true;
switch ( action )
{
case PICKUP_OR_SET_DOWN:
if( hasItemInHand )
{
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
{
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
{
canInsert = false;
break;
}
}
if( canInsert )
{
ItemStack inSlot = theSlot.getStackInSlot( 0 );
if( inSlot.isEmpty() )
{
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
}
else
{
inSlot = inSlot.copy();
final ItemStack inHand = player.inventory.getItemStack().copy();
switch (action) {
case PICKUP_OR_SET_DOWN:
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSlots(); s++) {
if (Platform.itemComparisons().isSameItem(interfaceHandler.getStackInSlot(s), player.inventory.getItemStack())) {
canInsert = false;
break;
}
}
if (canInsert) {
ItemStack inSlot = theSlot.getStackInSlot(0);
if (inSlot.isEmpty()) {
player.inventory.setItemStack(interfaceSlot.addItems(player.inventory.getItemStack()));
} else {
inSlot = inSlot.copy();
final ItemStack inHand = player.inventory.getItemStack().copy();
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
player.inventory.setItemStack( ItemStack.EMPTY );
ItemHandlerUtil.setStackInSlot(theSlot, 0, ItemStack.EMPTY);
player.inventory.setItemStack(ItemStack.EMPTY);
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
player.inventory.setItemStack(interfaceSlot.addItems(inHand.copy()));
if( player.inventory.getItemStack().isEmpty() )
{
player.inventory.setItemStack( inSlot );
}
else
{
player.inventory.setItemStack( inHand );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
}
}
}
else
{
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerHand.addItems( theSlot.getStackInSlot( 0 ) ) );
}
if (player.inventory.getItemStack().isEmpty()) {
player.inventory.setItemStack(inSlot);
} else {
player.inventory.setItemStack(inHand);
ItemHandlerUtil.setStackInSlot(theSlot, 0, inSlot);
}
}
}
} else {
ItemHandlerUtil.setStackInSlot(theSlot, 0, playerHand.addItems(theSlot.getStackInSlot(0)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
if( hasItemInHand )
{
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
{
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
{
canInsert = false;
break;
}
}
if( canInsert )
{
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
if( !extra.isEmpty() && !interfaceSlot.containsItems() )
{
extra = interfaceSlot.addItems( extra );
}
if( !extra.isEmpty() )
{
playerHand.addItems( extra );
}
}
}
else if( !is.isEmpty() )
{
ItemStack extra = interfaceSlot.removeItems( ( is.getCount() + 1 ) / 2, ItemStack.EMPTY, null );
if( !extra.isEmpty() )
{
extra = playerHand.addItems( extra );
}
if( !extra.isEmpty() )
{
interfaceSlot.addItems( extra );
}
}
break;
case SPLIT_OR_PLACE_SINGLE:
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSlots(); s++) {
if (Platform.itemComparisons().isSameItem(interfaceHandler.getStackInSlot(s), player.inventory.getItemStack())) {
canInsert = false;
break;
}
}
if (canInsert) {
ItemStack extra = playerHand.removeItems(1, ItemStack.EMPTY, null);
if (!extra.isEmpty() && !interfaceSlot.containsItems()) {
extra = interfaceSlot.addItems(extra);
}
if (!extra.isEmpty()) {
playerHand.addItems(extra);
}
}
} else if (!is.isEmpty()) {
ItemStack extra = interfaceSlot.removeItems((is.getCount() + 1) / 2, ItemStack.EMPTY, null);
if (!extra.isEmpty()) {
extra = playerHand.addItems(extra);
}
if (!extra.isEmpty()) {
interfaceSlot.addItems(extra);
}
}
break;
case SHIFT_CLICK:
break;
case SHIFT_CLICK:
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player);
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) );
ItemHandlerUtil.setStackInSlot(theSlot, 0, playerInv.addItems(theSlot.getStackInSlot(0)));
break;
case MOVE_REGION:
break;
case MOVE_REGION:
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player );
for( int x = 0; x < inv.server.getSlots(); x++ )
{
ItemHandlerUtil.setStackInSlot( inv.server, x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
}
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor(player);
for (int x = 0; x < inv.server.getSlots(); x++) {
ItemHandlerUtil.setStackInSlot(inv.server, x, playerInvAd.addItems(inv.server.getStackInSlot(x)));
}
break;
case CREATIVE_DUPLICATE:
break;
case CREATIVE_DUPLICATE:
if( player.capabilities.isCreativeMode && !hasItemInHand )
{
player.inventory.setItemStack( is.isEmpty() ? ItemStack.EMPTY : is.copy() );
}
if (player.capabilities.isCreativeMode && !hasItemInHand) {
player.inventory.setItemStack(is.isEmpty() ? ItemStack.EMPTY : is.copy());
}
break;
default:
return;
}
break;
default:
return;
}
this.updateHeld( player );
}
}
this.updateHeld(player);
}
}
private void regenList( final NBTTagCompound data )
{
this.byId.clear();
this.diList.clear();
private void regenList(final NBTTagCompound data) {
this.byId.clear();
this.diList.clear();
final IActionHost host = this.getActionHost();
if( host != null )
{
final IGridNode agn = host.getActionableNode();
if( agn != null && agn.isActive() )
{
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) );
}
}
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.grid.getMachines(TileInterface.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new InvTracker(dual, dual.getPatterns(), dual.getTermName()));
}
}
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
{
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) );
}
}
}
}
for (final IGridNode gn : this.grid.getMachines(PartInterface.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new InvTracker(dual, dual.getPatterns(), dual.getTermName()));
}
}
}
}
data.setBoolean( "clear", true );
data.setBoolean("clear", true);
for( final Entry<IInterfaceHost, InvTracker> en : this.diList.entrySet() )
{
final InvTracker inv = en.getValue();
this.byId.put( inv.which, inv );
this.addItems( data, inv, 0, inv.server.getSlots() );
}
}
for (final Entry<IInterfaceHost, InvTracker> en : this.diList.entrySet()) {
final InvTracker inv = en.getValue();
this.byId.put(inv.which, inv);
this.addItems(data, inv, 0, inv.server.getSlots());
}
}
private boolean isDifferent( final ItemStack a, final ItemStack b )
{
if( a.isEmpty() && b.isEmpty() )
{
return false;
}
private boolean isDifferent(final ItemStack a, final ItemStack b) {
if (a.isEmpty() && b.isEmpty()) {
return false;
}
if( a.isEmpty() || b.isEmpty() )
{
return true;
}
if (a.isEmpty() || b.isEmpty()) {
return true;
}
return !ItemStack.areItemStacksEqual( a, b );
}
return !ItemStack.areItemStacksEqual(a, b);
}
private void addItems( final NBTTagCompound data, final InvTracker inv, final int offset, final int length )
{
final String name = '=' + Long.toString( inv.which, Character.MAX_RADIX );
final NBTTagCompound tag = data.getCompoundTag( name );
private void addItems(final NBTTagCompound data, final InvTracker inv, final int offset, final int length) {
final String name = '=' + Long.toString(inv.which, Character.MAX_RADIX);
final NBTTagCompound tag = data.getCompoundTag(name);
if( tag.hasNoTags() )
{
tag.setLong( "sortBy", inv.sortBy );
tag.setString( "un", inv.unlocalizedName );
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
tag.setInteger( "dim", inv.dim );
tag.setInteger( "numUpgrades", inv.numUpgrades );
}
if (tag.hasNoTags()) {
tag.setLong("sortBy", inv.sortBy);
tag.setString("un", inv.unlocalizedName);
tag.setTag("pos", NBTUtil.createPosTag(inv.pos));
tag.setInteger("dim", inv.dim);
tag.setInteger("numUpgrades", inv.numUpgrades);
}
for( int x = 0; x < length; x++ )
{
final NBTTagCompound itemNBT = new NBTTagCompound();
for (int x = 0; x < length; x++) {
final NBTTagCompound itemNBT = new NBTTagCompound();
final ItemStack is = inv.server.getStackInSlot( x + offset );
final ItemStack is = inv.server.getStackInSlot(x + offset);
// "update" client side.
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
// "update" client side.
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if( !is.isEmpty() )
{
is.writeToNBT( itemNBT );
}
if (!is.isEmpty()) {
is.writeToNBT(itemNBT);
}
tag.setTag( Integer.toString( x + offset ), itemNBT );
}
tag.setTag(Integer.toString(x + offset), itemNBT);
}
data.setTag( name, tag );
}
data.setTag(name, tag);
}
private static class InvTracker
{
private static class InvTracker {
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IItemHandler client;
private final IItemHandler server;
private final BlockPos pos;
private final int dim;
private final int numUpgrades;
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IItemHandler client;
private final IItemHandler server;
private final BlockPos pos;
private final int dim;
private final int numUpgrades;
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
{
this.server = patterns;
this.client = new AppEngInternalInventory( null, this.server.getSlots() );
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
this.pos = dual.getLocation().getPos();
this.dim = dual.getLocation().getWorld().provider.getDimension();
this.numUpgrades = dual.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION);
}
}
public InvTracker(final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName) {
this.server = patterns;
this.client = new AppEngInternalInventory(null, this.server.getSlots());
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
this.pos = dual.getLocation().getPos();
this.dim = dual.getLocation().getWorld().provider.getDimension();
this.numUpgrades = dual.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION);
}
}
private static class PatternSlotFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
private static class PatternSlotFilter implements IAEItemFilter {
@Override
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern;
}
}
@Override
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern;
}
}
}
@@ -19,6 +19,12 @@
package appeng.container.implementations;
import appeng.api.config.*;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartLevelEmitter;
import appeng.util.Platform;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -26,148 +32,116 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartLevelEmitter;
import appeng.util.Platform;
public class ContainerLevelEmitter extends ContainerUpgradeable {
public class ContainerLevelEmitter extends ContainerUpgradeable
{
private final PartLevelEmitter lvlEmitter;
private final PartLevelEmitter lvlEmitter;
@SideOnly(Side.CLIENT)
private GuiTextField textField;
@GuiSync(2)
public LevelType lvType;
@GuiSync(3)
public long EmitterValue = -1;
@GuiSync(4)
public YesNo cmType;
@SideOnly( Side.CLIENT )
private GuiTextField textField;
@GuiSync( 2 )
public LevelType lvType;
@GuiSync( 3 )
public long EmitterValue = -1;
@GuiSync( 4 )
public YesNo cmType;
public ContainerLevelEmitter(final InventoryPlayer ip, final PartLevelEmitter te) {
super(ip, te);
this.lvlEmitter = te;
}
public ContainerLevelEmitter( final InventoryPlayer ip, final PartLevelEmitter te )
{
super( ip, te );
this.lvlEmitter = te;
}
@SideOnly(Side.CLIENT)
public void setTextField(final GuiTextField level) {
this.textField = level;
this.textField.setText(String.valueOf(this.EmitterValue));
}
@SideOnly( Side.CLIENT )
public void setTextField( final GuiTextField level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
public void setLevel(final long l, final EntityPlayer player) {
this.lvlEmitter.setReportingValue(l);
this.EmitterValue = l;
}
public void setLevel( final long l, final EntityPlayer player )
{
this.lvlEmitter.setReportingValue( l );
this.EmitterValue = l;
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
if (this.availableUpgrades() > 0) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
}
@Override
protected void setupConfig()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 1 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 2 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 3 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80 + 44;
this.addSlotToContainer(new SlotFakeTypeOnly(inv, 0, x, y));
}
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80 + 44;
this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
public int availableUpgrades() {
@Override
public int availableUpgrades()
{
return 1;
}
return 1;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
if (Platform.isServer()) {
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setCraftingMode((YesNo) this.getUpgradeable().getConfigManager().getSetting(Settings.CRAFT_VIA_REDSTONE));
this.setLevelMode((LevelType) this.getUpgradeable().getConfigManager().getSetting(Settings.LEVEL_TYPE));
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setRedStoneMode((RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
}
if( Platform.isServer() )
{
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setCraftingMode( (YesNo) this.getUpgradeable().getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ) );
this.setLevelMode( (LevelType) this.getUpgradeable().getConfigManager().getSetting( Settings.LEVEL_TYPE ) );
this.setFuzzyMode( (FuzzyMode) this.getUpgradeable().getConfigManager().getSetting( Settings.FUZZY_MODE ) );
this.setRedStoneMode( (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) );
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("EmitterValue")) {
if (this.textField != null) {
this.textField.setText(String.valueOf(this.EmitterValue));
}
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "EmitterValue" ) )
{
if( this.textField != null )
{
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
}
}
@Override
public YesNo getCraftingMode() {
return this.cmType;
}
@Override
public YesNo getCraftingMode()
{
return this.cmType;
}
@Override
public void setCraftingMode(final YesNo cmType) {
this.cmType = cmType;
}
@Override
public void setCraftingMode( final YesNo cmType )
{
this.cmType = cmType;
}
public LevelType getLevelMode() {
return this.lvType;
}
public LevelType getLevelMode()
{
return this.lvType;
}
private void setLevelMode( final LevelType lvType )
{
this.lvType = lvType;
}
private void setLevelMode(final LevelType lvType) {
this.lvType = lvType;
}
}
@@ -19,11 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
@@ -36,132 +31,120 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider
{
public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider {
private static final int MAX_CRAFT_PROGRESS = 100;
private final TileMolecularAssembler tma;
@GuiSync( 4 )
public int craftProgress = 0;
private static final int MAX_CRAFT_PROGRESS = 100;
private final TileMolecularAssembler tma;
@GuiSync(4)
public int craftProgress = 0;
public ContainerMAC( final InventoryPlayer ip, final TileMolecularAssembler te )
{
super( ip, te );
this.tma = te;
}
public ContainerMAC(final InventoryPlayer ip, final TileMolecularAssembler te) {
super(ip, te);
this.tma = te;
}
public boolean isValidItemForSlot( final int slotIndex, final ItemStack i )
{
final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" );
public boolean isValidItemForSlot(final int slotIndex, final ItemStack i) {
final IItemHandler mac = this.getUpgradeable().getInventoryByName("mac");
final ItemStack is = mac.getStackInSlot( 10 );
if( is.isEmpty() )
{
return false;
}
final ItemStack is = mac.getStackInSlot(10);
if (is.isEmpty()) {
return false;
}
if( is.getItem() instanceof ItemEncodedPattern )
{
final World w = this.getTileEntity().getWorld();
final ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
final ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
if( ph.isCraftable() )
{
return ph.isValidItemForSlot( slotIndex, i, w );
}
}
if (is.getItem() instanceof ItemEncodedPattern) {
final World w = this.getTileEntity().getWorld();
final ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
final ICraftingPatternDetails ph = iep.getPatternForItem(is, w);
if (ph.isCraftable()) {
return ph.isValidItemForSlot(slotIndex, i, w);
}
}
return false;
}
return false;
}
@Override
protected int getHeight()
{
return 197;
}
@Override
protected int getHeight() {
return 197;
}
@Override
protected void setupConfig()
{
int offX = 29;
int offY = 30;
@Override
protected void setupConfig() {
int offX = 29;
int offY = 30;
final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" );
final IItemHandler mac = this.getUpgradeable().getInventoryByName("mac");
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 3; x++ )
{
final SlotMACPattern s = new SlotMACPattern( this, mac, x + y * 3, offX + x * 18, offY + y * 18 );
this.addSlotToContainer( s );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
final SlotMACPattern s = new SlotMACPattern(this, mac, x + y * 3, offX + x * 18, offY + y * 18);
this.addSlotToContainer(s);
}
}
offX = 126;
offY = 16;
offX = 126;
offY = 16;
this.addSlotToContainer(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10, offX, offY, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotOutput( mac, 9, offX, offY + 32, -1 ) );
this.addSlotToContainer(
new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10, offX, offY, this.getInventoryPlayer()));
this.addSlotToContainer(new SlotOutput(mac, 9, offX, offY + 32, -1));
offX = 122;
offY = 17;
offX = 122;
offY = 17;
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer()))
.setNotDraggable());
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.setRedStoneMode( (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED ) );
}
if (Platform.isServer()) {
this.setRedStoneMode((RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED));
}
this.craftProgress = this.tma.getCraftingProgress();
this.craftProgress = this.tma.getCraftingProgress();
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
@Override
public int getCurrentProgress()
{
return this.craftProgress;
}
@Override
public int getCurrentProgress() {
return this.craftProgress;
}
@Override
public int getMaxProgress()
{
return MAX_CRAFT_PROGRESS;
}
@Override
public int getMaxProgress() {
return MAX_CRAFT_PROGRESS;
}
}
@@ -19,26 +19,8 @@
package appeng.container.implementations;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
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.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
@@ -71,397 +53,315 @@ import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.Loader;
public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack>
{
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEItemStack> monitor;
private final IItemList<IAEItemStack> items = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private final IConfigManager clientCM;
private final ITerminalHost host;
@GuiSync( 99 )
public boolean canAccessViewCells = false;
@GuiSync( 98 )
public boolean hasPower = false;
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
protected int jeiOffset = Loader.isModLoaded( "jei" ) ? 24 : 0;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.BufferOverflowException;
public ContainerMEMonitorable( final InventoryPlayer ip, final ITerminalHost monitorable )
{
this( ip, monitorable, true );
}
public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {
protected ContainerMEMonitorable( final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory )
{
super( ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null );
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEItemStack> monitor;
private final IItemList<IAEItemStack> items = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
private final IConfigManager clientCM;
private final ITerminalHost host;
@GuiSync(99)
public boolean canAccessViewCells = false;
@GuiSync(98)
public boolean hasPower = false;
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
protected int jeiOffset = Loader.isModLoaded("jei") ? 24 : 0;
this.host = monitorable;
this.clientCM = new ConfigManager( this );
this.clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME );
this.clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
this.clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
public ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable) {
this(ip, monitorable, true);
}
if( Platform.isServer() )
{
this.serverCM = monitorable.getConfigManager();
protected ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) {
super(ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null);
this.monitor = monitorable.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( this.monitor != null )
{
this.monitor.addListener( this, null );
this.host = monitorable;
this.clientCM = new ConfigManager(this);
this.setCellInventory( this.monitor );
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
if( monitorable instanceof IPortableCell )
{
this.setPowerSource( (IEnergySource) monitorable );
}
else if( monitorable instanceof IMEChest )
{
this.setPowerSource( (IEnergySource) monitorable );
}
else if( monitorable instanceof IGridHost || monitorable instanceof IActionHost )
{
final IGridNode node;
if( monitorable instanceof IGridHost )
{
node = ( (IGridHost) monitorable ).getGridNode( AEPartLocation.INTERNAL );
}
else if( monitorable instanceof IActionHost )
{
node = ( (IActionHost) monitorable ).getActionableNode();
}
else
{
node = null;
}
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
if( node != null )
{
this.networkNode = node;
final IGrid g = node.getGrid();
if( g != null )
{
this.setPowerSource( new ChannelPowerSrc( this.networkNode, (IEnergySource) g.getCache( IEnergyGrid.class ) ) );
}
}
}
}
else
{
this.setValidContainer( false );
}
}
else
{
this.monitor = null;
}
this.monitor = monitorable.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (this.monitor != null) {
this.monitor.addListener(this, null);
this.canAccessViewCells = false;
if( monitorable instanceof IViewCellStorage )
{
for( int y = 0; y < 5; y++ )
{
this.cellView[y] = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.VIEW_CELL, ( (IViewCellStorage) monitorable )
.getViewCellStorage(), y, 206, y * 18 + 8 + jeiOffset, this.getInventoryPlayer() );
this.cellView[y].setAllowEdit( this.canAccessViewCells );
this.addSlotToContainer( this.cellView[y] );
}
}
this.setCellInventory(this.monitor);
if( bindInventory )
{
this.bindPlayerInventory( ip, 0, 0 );
}
}
if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IGridHost || monitorable instanceof IActionHost) {
final IGridNode node;
if (monitorable instanceof IGridHost) {
node = ((IGridHost) monitorable).getGridNode(AEPartLocation.INTERNAL);
} else if (monitorable instanceof IActionHost) {
node = ((IActionHost) monitorable).getActionableNode();
} else {
node = null;
}
public IGridNode getNetworkNode()
{
return this.networkNode;
}
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
}
}
}
} else {
this.setValidContainer(false);
}
} else {
this.monitor = null;
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() )
{
if( this.monitor != this.host.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) )
{
this.setValidContainer( false );
}
this.canAccessViewCells = false;
if (monitorable instanceof IViewCellStorage) {
for (int y = 0; y < 5; y++) {
this.cellView[y] = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.VIEW_CELL, ((IViewCellStorage) monitorable)
.getViewCellStorage(), y, 206, y * 18 + 8 + jeiOffset, this.getInventoryPlayer());
this.cellView[y].setAllowEdit(this.canAccessViewCells);
this.addSlotToContainer(this.cellView[y]);
}
}
for( final Settings set : this.serverCM.getSettings() )
{
final Enum<?> sideLocal = this.serverCM.getSetting( set );
final Enum<?> sideRemote = this.clientCM.getSetting( set );
if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0);
}
}
if( sideLocal != sideRemote )
{
this.clientCM.putSetting( set, sideLocal );
for( final IContainerListener crafter : this.listeners )
{
if( crafter instanceof EntityPlayerMP )
{
try
{
NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
}
}
public IGridNode getNetworkNode() {
return this.networkNode;
}
if( !this.items.isEmpty() )
{
try
{
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.host.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))) {
this.setValidContainer(false);
}
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
for( final IAEItemStack is : this.items )
{
final IAEItemStack send = monitorCache.findPrecise( is );
if( send == null )
{
is.setStackSize( 0 );
piu.appendItem( is );
}
else
{
piu.appendItem( send );
}
}
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final IContainerListener crafter : this.listeners) {
if (crafter instanceof EntityPlayerMP) {
try {
NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
}
}
if( !piu.isEmpty() )
{
this.items.resetStatus();
if (!this.items.isEmpty()) {
try {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for( final Object c : this.listeners )
{
if( c instanceof EntityPlayer )
{
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
}
}
}
}
catch( final IOException e )
{
AELog.debug( e );
}
}
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
this.updatePowerStatus();
for (final IAEItemStack is : this.items) {
final IAEItemStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendItem(is);
} else {
piu.appendItem(send);
}
}
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells = this.hasAccess( SecurityPermissions.BUILD, false );
if( this.canAccessViewCells != oldAccessible )
{
for( int y = 0; y < 5; y++ )
{
if( this.cellView[y] != null )
{
this.cellView[y].setAllowEdit( this.canAccessViewCells );
}
}
}
if (!piu.isEmpty()) {
this.items.resetStatus();
super.detectAndSendChanges();
}
for (final Object c : this.listeners) {
if (c instanceof EntityPlayer) {
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
}
}
}
} catch (final IOException e) {
AELog.debug(e);
}
}
}
this.updatePowerStatus();
protected void updatePowerStatus()
{
try
{
if( this.networkNode != null )
{
this.setPowered( this.networkNode.isActive() );
}
else if( this.getPowerSource() instanceof IEnergyGrid )
{
this.setPowered( ( (IEnergyGrid) this.getPowerSource() ).isNetworkPowered() );
}
else
{
this.setPowered( this.getPowerSource().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8 );
}
}
catch( final Throwable t )
{
// :P
}
}
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells = this.hasAccess(SecurityPermissions.BUILD, false);
if (this.canAccessViewCells != oldAccessible) {
for (int y = 0; y < 5; y++) {
if (this.cellView[y] != null) {
this.cellView[y].setAllowEdit(this.canAccessViewCells);
}
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "canAccessViewCells" ) )
{
for( int y = 0; y < 5; y++ )
{
if( this.cellView[y] != null )
{
this.cellView[y].setAllowEdit( this.canAccessViewCells );
}
}
}
super.detectAndSendChanges();
}
super.onUpdate( field, oldValue, newValue );
}
}
@Override
public void addListener( final IContainerListener c )
{
super.addListener( c );
protected void updatePowerStatus() {
try {
if (this.networkNode != null) {
this.setPowered(this.networkNode.isActive());
} else if (this.getPowerSource() instanceof IEnergyGrid) {
this.setPowered(((IEnergyGrid) this.getPowerSource()).isNetworkPowered());
} else {
this.setPowered(this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8);
}
} catch (final Throwable t) {
// :P
}
}
this.queueInventory( c );
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("canAccessViewCells")) {
for (int y = 0; y < 5; y++) {
if (this.cellView[y] != null) {
this.cellView[y].setAllowEdit(this.canAccessViewCells);
}
}
}
private void queueInventory( final IContainerListener c )
{
if( Platform.isServer() && c instanceof EntityPlayer && this.monitor != null )
{
try
{
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
super.onUpdate(field, oldValue, newValue);
}
for( final IAEItemStack send : monitorCache )
{
try
{
piu.appendItem( send );
}
catch( final BufferOverflowException boe )
{
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
@Override
public void addListener(final IContainerListener c) {
super.addListener(c);
piu = new PacketMEInventoryUpdate();
piu.appendItem( send );
}
}
this.queueInventory(c);
}
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
try {
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
@Override
public void removeListener( final IContainerListener c )
{
super.removeListener( c );
for (final IAEItemStack send : monitorCache) {
try {
piu.appendItem(send);
} catch (final BufferOverflowException boe) {
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
if( this.listeners.isEmpty() && this.monitor != null )
{
this.monitor.removeListener( this );
}
}
piu = new PacketMEInventoryUpdate();
piu.appendItem(send);
}
}
@Override
public void onContainerClosed( final EntityPlayer player )
{
super.onContainerClosed( player );
if( this.monitor != null )
{
this.monitor.removeListener( this );
}
}
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
@Override
public boolean isValid( final Object verificationToken )
{
return true;
}
@Override
public void removeListener(final IContainerListener c) {
super.removeListener(c);
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
{
for( final IAEItemStack is : change )
{
this.items.add( is );
}
}
if (this.listeners.isEmpty() && this.monitor != null) {
this.monitor.removeListener(this);
}
}
@Override
public void onListUpdate()
{
for( final IContainerListener c : this.listeners )
{
this.queueInventory( c );
}
}
@Override
public void onContainerClosed(final EntityPlayer player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public boolean isValid(final Object verificationToken) {
return true;
}
@Override
public IConfigManager getConfigManager()
{
if( Platform.isServer() )
{
return this.serverCM;
}
return this.clientCM;
}
@Override
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source) {
for (final IAEItemStack is : change) {
this.items.add(is);
}
}
public ItemStack[] getViewCells()
{
final ItemStack[] list = new ItemStack[this.cellView.length];
@Override
public void onListUpdate() {
for (final IContainerListener c : this.listeners) {
this.queueInventory(c);
}
}
for( int x = 0; x < this.cellView.length; x++ )
{
list[x] = this.cellView[x].getStack();
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
return list;
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
public SlotRestrictedInput getCellViewSlot( final int index )
{
return this.cellView[index];
}
public ItemStack[] getViewCells() {
final ItemStack[] list = new ItemStack[this.cellView.length];
public boolean isPowered()
{
return this.hasPower;
}
for (int x = 0; x < this.cellView.length; x++) {
list[x] = this.cellView[x].getStack();
}
private void setPowered( final boolean isPowered )
{
this.hasPower = isPowered;
}
return list;
}
private IConfigManagerHost getGui()
{
return this.gui;
}
public SlotRestrictedInput getCellViewSlot(final int index) {
return this.cellView[index];
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
}
@@ -19,80 +19,64 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.container.interfaces.IInventorySlotAware;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class ContainerMEPortableCell extends ContainerMEMonitorable
{
public class ContainerMEPortableCell extends ContainerMEMonitorable {
private double powerMultiplier = 0.5;
private double powerMultiplier = 0.5;
private final IPortableCell civ;
private int ticks = 0;
private final int slot;
private final IPortableCell civ;
private int ticks = 0;
private final int slot;
public ContainerMEPortableCell( final InventoryPlayer ip, final IPortableCell monitorable )
{
super( ip, monitorable, false );
if( monitorable instanceof IInventorySlotAware )
{
final int slotIndex = ( (IInventorySlotAware) monitorable ).getInventorySlot();
this.lockPlayerInventorySlot( slotIndex );
this.slot = slotIndex;
}
else
{
this.slot = -1;
this.lockPlayerInventorySlot( ip.currentItem );
}
this.civ = monitorable;
this.bindPlayerInventory( ip, 0, 0 );
}
public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable) {
super(ip, monitorable, false);
if (monitorable instanceof IInventorySlotAware) {
final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot();
this.lockPlayerInventorySlot(slotIndex);
this.slot = slotIndex;
} else {
this.slot = -1;
this.lockPlayerInventorySlot(ip.currentItem);
}
this.civ = monitorable;
this.bindPlayerInventory(ip, 0, 0);
}
@Override
public void detectAndSendChanges()
{
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot( this.slot );
@Override
public void detectAndSendChanges() {
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
if( this.civ == null || currentItem.isEmpty() )
{
this.setValidContainer( false );
}
else if( this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack() )
{
if( ItemStack.areItemsEqual( this.civ.getItemStack(), currentItem ) )
{
this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.civ.getItemStack() );
}
else
{
this.setValidContainer( false );
}
}
if (this.civ == null || currentItem.isEmpty()) {
this.setValidContainer(false);
} else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) {
if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack());
} else {
this.setValidContainer(false);
}
}
// drain 1 ae t
this.ticks++;
if( this.ticks > 10 )
{
this.civ.extractAEPower( this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG );
this.ticks = 0;
}
super.detectAndSendChanges();
}
// drain 1 ae t
this.ticks++;
if (this.ticks > 10) {
this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0;
}
super.detectAndSendChanges();
}
private double getPowerMultiplier()
{
return this.powerMultiplier;
}
private double getPowerMultiplier() {
return this.powerMultiplier;
}
void setPowerMultiplier( final double powerMultiplier )
{
this.powerMultiplier = powerMultiplier;
}
void setPowerMultiplier(final double powerMultiplier) {
this.powerMultiplier = powerMultiplier;
}
}
@@ -19,13 +19,6 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.networking.IGrid;
@@ -43,150 +36,128 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import java.io.IOException;
public class ContainerNetworkStatus extends AEBaseContainer
{
public class ContainerNetworkStatus extends AEBaseContainer {
@GuiSync( 0 )
public long avgAddition;
@GuiSync( 1 )
public long powerUsage;
@GuiSync( 2 )
public long currentPower;
@GuiSync( 3 )
public long maxPower;
private IGrid network;
private int delay = 40;
@GuiSync(0)
public long avgAddition;
@GuiSync(1)
public long powerUsage;
@GuiSync(2)
public long currentPower;
@GuiSync(3)
public long maxPower;
private IGrid network;
private int delay = 40;
public ContainerNetworkStatus( final InventoryPlayer ip, final INetworkTool te )
{
super( ip, null, null );
final IGridHost host = te.getGridHost();
public ContainerNetworkStatus(final InventoryPlayer ip, final INetworkTool te) {
super(ip, null, null);
final IGridHost host = te.getGridHost();
if( host != null )
{
this.findNode( host, AEPartLocation.INTERNAL );
for( final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS )
{
this.findNode( host, d );
}
}
if (host != null) {
this.findNode(host, AEPartLocation.INTERNAL);
for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) {
this.findNode(host, d);
}
}
if( this.network == null && Platform.isServer() )
{
this.setValidContainer( false );
}
}
if (this.network == null && Platform.isServer()) {
this.setValidContainer(false);
}
}
private void findNode( final IGridHost host, final AEPartLocation d )
{
if( this.network == null )
{
final IGridNode node = host.getGridNode( d );
if( node != null )
{
this.network = node.getGrid();
}
}
}
private void findNode(final IGridHost host, final AEPartLocation d) {
if (this.network == null) {
final IGridNode node = host.getGridNode(d);
if (node != null) {
this.network = node.getGrid();
}
}
}
@Override
public void detectAndSendChanges()
{
this.delay++;
if( Platform.isServer() && this.delay > 15 && this.network != null )
{
this.delay = 0;
@Override
public void detectAndSendChanges() {
this.delay++;
if (Platform.isServer() && this.delay > 15 && this.network != null) {
this.delay = 0;
final IEnergyGrid eg = this.network.getCache( IEnergyGrid.class );
if( eg != null )
{
this.setAverageAddition( (long) ( 100.0 * eg.getAvgPowerInjection() ) );
this.setPowerUsage( (long) ( 100.0 * eg.getAvgPowerUsage() ) );
this.setCurrentPower( (long) ( 100.0 * eg.getStoredPower() ) );
this.setMaxPower( (long) ( 100.0 * eg.getMaxStoredPower() ) );
}
final IEnergyGrid eg = this.network.getCache(IEnergyGrid.class);
if (eg != null) {
this.setAverageAddition((long) (100.0 * eg.getAvgPowerInjection()));
this.setPowerUsage((long) (100.0 * eg.getAvgPowerUsage()));
this.setCurrentPower((long) (100.0 * eg.getStoredPower()));
this.setMaxPower((long) (100.0 * eg.getMaxStoredPower()));
}
try
{
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
try {
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
for( final Class<? extends IGridHost> machineClass : this.network.getMachinesClasses() )
{
final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
for( final IGridNode machine : this.network.getMachines( machineClass ) )
{
final IGridBlock blk = machine.getGridBlock();
final ItemStack is = blk.getMachineRepresentation();
if( !is.isEmpty() )
{
final IAEItemStack ais = AEItemStack.fromItemStack( is );
ais.setStackSize( 1 );
ais.setCountRequestable( (long) ( blk.getIdlePowerUsage() * 100.0 ) );
list.add( ais );
}
}
for (final Class<? extends IGridHost> machineClass : this.network.getMachinesClasses()) {
final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
for (final IGridNode machine : this.network.getMachines(machineClass)) {
final IGridBlock blk = machine.getGridBlock();
final ItemStack is = blk.getMachineRepresentation();
if (!is.isEmpty()) {
final IAEItemStack ais = AEItemStack.fromItemStack(is);
ais.setStackSize(1);
ais.setCountRequestable((long) (blk.getIdlePowerUsage() * 100.0));
list.add(ais);
}
}
for( final IAEItemStack ais : list )
{
piu.appendItem( ais );
}
}
for (final IAEItemStack ais : list) {
piu.appendItem(ais);
}
}
for( final Object c : this.listeners )
{
if( c instanceof EntityPlayer )
{
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
}
}
}
catch( final IOException e )
{
// :P
}
}
super.detectAndSendChanges();
}
for (final Object c : this.listeners) {
if (c instanceof EntityPlayer) {
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
}
}
} catch (final IOException e) {
// :P
}
}
super.detectAndSendChanges();
}
public long getCurrentPower()
{
return this.currentPower;
}
public long getCurrentPower() {
return this.currentPower;
}
private void setCurrentPower( final long currentPower )
{
this.currentPower = currentPower;
}
private void setCurrentPower(final long currentPower) {
this.currentPower = currentPower;
}
public long getMaxPower()
{
return this.maxPower;
}
public long getMaxPower() {
return this.maxPower;
}
private void setMaxPower( final long maxPower )
{
this.maxPower = maxPower;
}
private void setMaxPower(final long maxPower) {
this.maxPower = maxPower;
}
public long getAverageAddition()
{
return this.avgAddition;
}
public long getAverageAddition() {
return this.avgAddition;
}
private void setAverageAddition( final long avgAddition )
{
this.avgAddition = avgAddition;
}
private void setAverageAddition(final long avgAddition) {
this.avgAddition = avgAddition;
}
public long getPowerUsage()
{
return this.powerUsage;
}
public long getPowerUsage() {
return this.powerUsage;
}
private void setPowerUsage( final long powerUsage )
{
this.powerUsage = powerUsage;
}
private void setPowerUsage(final long powerUsage) {
this.powerUsage = powerUsage;
}
}
@@ -19,99 +19,81 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ContainerNetworkTool extends AEBaseContainer
{
public class ContainerNetworkTool extends AEBaseContainer {
private final INetworkTool toolInv;
private final INetworkTool toolInv;
@GuiSync( 1 )
public boolean facadeMode;
@GuiSync(1)
public boolean facadeMode;
public ContainerNetworkTool( final InventoryPlayer ip, final INetworkTool te )
{
super( ip, null, null );
this.toolInv = te;
public ContainerNetworkTool(final InventoryPlayer ip, final INetworkTool te) {
super(ip, null, null);
this.toolInv = te;
this.lockPlayerInventorySlot( ip.currentItem );
this.lockPlayerInventorySlot(ip.currentItem);
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 3; x++ )
{
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te
.getInventory(), y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getInventoryPlayer() ) ) );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, te
.getInventory(), y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getInventoryPlayer())));
}
}
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
public void toggleFacadeMode()
{
final NBTTagCompound data = Platform.openNbtData( this.toolInv.getItemStack() );
data.setBoolean( "hideFacades", !data.getBoolean( "hideFacades" ) );
this.detectAndSendChanges();
}
public void toggleFacadeMode() {
final NBTTagCompound data = Platform.openNbtData(this.toolInv.getItemStack());
data.setBoolean("hideFacades", !data.getBoolean("hideFacades"));
this.detectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
final ItemStack currentItem = this.getPlayerInv().getCurrentItem();
@Override
public void detectAndSendChanges() {
final ItemStack currentItem = this.getPlayerInv().getCurrentItem();
if( currentItem != this.toolInv.getItemStack() )
{
if( !currentItem.isEmpty() )
{
if( ItemStack.areItemsEqual( this.toolInv.getItemStack(), currentItem ) )
{
this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() );
}
else
{
this.setValidContainer( false );
}
}
else
{
this.setValidContainer( false );
}
}
if (currentItem != this.toolInv.getItemStack()) {
if (!currentItem.isEmpty()) {
if (ItemStack.areItemsEqual(this.toolInv.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.toolInv.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
if( this.isValidContainer() )
{
final NBTTagCompound data = Platform.openNbtData( currentItem );
this.setFacadeMode( data.getBoolean( "hideFacades" ) );
}
if (this.isValidContainer()) {
final NBTTagCompound data = Platform.openNbtData(currentItem);
this.setFacadeMode(data.getBoolean("hideFacades"));
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
@Override
public void onSlotChange( Slot s )
{
super.detectAndSendChanges();
}
@Override
public void onSlotChange(Slot s) {
super.detectAndSendChanges();
}
public boolean isFacadeMode()
{
return this.facadeMode;
}
public boolean isFacadeMode() {
return this.facadeMode;
}
private void setFacadeMode( final boolean facadeMode )
{
this.facadeMode = facadeMode;
}
private void setFacadeMode(final boolean facadeMode) {
this.facadeMode = facadeMode;
}
}
@@ -1,7 +1,10 @@
package appeng.container.implementations;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.config.AccessRestriction;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
@@ -23,118 +26,96 @@ import java.util.Iterator;
import java.util.Set;
public class ContainerOreDictStorageBus extends AEBaseContainer
{
public class ContainerOreDictStorageBus extends AEBaseContainer {
private final PartOreDicStorageBus part;
@GuiSync( 3 )
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync( 4 )
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerOreDictStorageBus( final InventoryPlayer ip, final PartOreDicStorageBus anchor )
{
super( ip, anchor );
public ContainerOreDictStorageBus(final InventoryPlayer ip, final PartOreDicStorageBus anchor) {
super(ip, anchor);
this.part = anchor;
this.bindPlayerInventory( ip, 14, 256 - /* height of player inventory */82 );
this.bindPlayerInventory(ip, 14, 256 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.setReadWriteMode( (AccessRestriction) part.getConfigManager().getSetting( Settings.ACCESS ) );
this.setStorageFilter( (StorageFilter) part.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
if (Platform.isServer()) {
this.setReadWriteMode((AccessRestriction) part.getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter((StorageFilter) part.getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
super.detectAndSendChanges();
}
public void partition()
{
public void partition() {
final IMEInventory<IAEItemStack> cellInv = this.part.getInternalHandler();
if( cellInv == null )
{
if (cellInv == null) {
return;
}
Set<Integer> oreIDs = new HashSet<>();
for( IAEItemStack itemStack : cellInv.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ) )
{
OreReference ref = ( (AEItemStack) itemStack ).getOre().orElse( null );
if( ref != null )
{
oreIDs.addAll( ref.getOres() );
for (IAEItemStack itemStack : cellInv.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())) {
OreReference ref = ((AEItemStack) itemStack).getOre().orElse(null);
if (ref != null) {
oreIDs.addAll(ref.getOres());
}
}
String oreMatch = "(";
String append = "";
for( Iterator<Integer> it = oreIDs.iterator(); it.hasNext(); )
{
for (Iterator<Integer> it = oreIDs.iterator(); it.hasNext(); ) {
int oreID = it.next();
if( it.hasNext() )
{
if (it.hasNext()) {
append = ")|(";
}
else
{
} else {
append = ")";
}
oreMatch = oreMatch.concat( OreDictionary.getOreName( oreID ) + append );
oreMatch = oreMatch.concat(OreDictionary.getOreName(oreID) + append);
}
if( oreMatch.equals( "(" ) )
{
if (oreMatch.equals("(")) {
oreMatch = "";
}
part.saveOreMatch( oreMatch );
part.saveOreMatch(oreMatch);
this.detectAndSendChanges();
}
public void saveOreMatch( String value )
{
part.saveOreMatch( value );
public void saveOreMatch(String value) {
part.saveOreMatch(value);
}
public void sendRegex()
{
try
{
NetworkHandler.instance().sendTo( new PacketValueConfig( "OreDictStorageBus.sendRegex", part.getOreExp() ), (EntityPlayerMP) getInventoryPlayer().player );
}
catch( IOException e )
{
public void sendRegex() {
try {
NetworkHandler.instance().sendTo(new PacketValueConfig("OreDictStorageBus.sendRegex", part.getOreExp()), (EntityPlayerMP) getInventoryPlayer().player);
} catch (IOException e) {
e.printStackTrace();
}
}
public AccessRestriction getReadWriteMode()
{
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode( final AccessRestriction rwMode )
{
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter()
{
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter( final StorageFilter storageFilter )
{
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
}
File diff suppressed because it is too large Load Diff
@@ -19,6 +19,12 @@
package appeng.container.implementations;
import appeng.api.config.SecurityPermissions;
import appeng.api.parts.IPart;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.helpers.IPriorityHost;
import appeng.util.Platform;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -26,71 +32,54 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.config.SecurityPermissions;
import appeng.api.parts.IPart;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.helpers.IPriorityHost;
import appeng.util.Platform;
public class ContainerPriority extends AEBaseContainer {
public class ContainerPriority extends AEBaseContainer
{
private final IPriorityHost priHost;
private final IPriorityHost priHost;
@SideOnly(Side.CLIENT)
private GuiTextField textField;
@GuiSync(2)
public long PriorityValue = -1;
@SideOnly( Side.CLIENT )
private GuiTextField textField;
@GuiSync( 2 )
public long PriorityValue = -1;
public ContainerPriority(final InventoryPlayer ip, final IPriorityHost te) {
super(ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null));
this.priHost = te;
}
public ContainerPriority( final InventoryPlayer ip, final IPriorityHost te )
{
super( ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) );
this.priHost = te;
}
@SideOnly(Side.CLIENT)
public void setTextField(final GuiTextField level) {
this.textField = level;
this.textField.setText(String.valueOf(this.PriorityValue));
}
@SideOnly( Side.CLIENT )
public void setTextField( final GuiTextField level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.PriorityValue ) );
}
public void setPriority(final int newValue, final EntityPlayer player) {
this.priHost.setPriority(newValue);
this.PriorityValue = newValue;
}
public void setPriority( final int newValue, final EntityPlayer player )
{
this.priHost.setPriority( newValue );
this.PriorityValue = newValue;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
this.verifyPermissions(SecurityPermissions.BUILD, false);
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
this.verifyPermissions( SecurityPermissions.BUILD, false );
if (Platform.isServer()) {
this.PriorityValue = this.priHost.getPriority();
}
}
if( Platform.isServer() )
{
this.PriorityValue = this.priHost.getPriority();
}
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("PriorityValue")) {
if (this.textField != null) {
this.textField.setText(String.valueOf(this.PriorityValue));
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "PriorityValue" ) )
{
if( this.textField != null )
{
this.textField.setText( String.valueOf( this.PriorityValue ) );
}
}
super.onUpdate(field, oldValue, newValue);
}
super.onUpdate( field, oldValue, newValue );
}
public IPriorityHost getPriorityHost()
{
return this.priHost;
}
public IPriorityHost getPriorityHost() {
return this.priHost;
}
}
@@ -19,23 +19,20 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.qnb.TileQuantumBridge;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerQNB extends AEBaseContainer
{
public class ContainerQNB extends AEBaseContainer {
public ContainerQNB( final InventoryPlayer ip, final TileQuantumBridge quantumBridge )
{
super( ip, quantumBridge, null );
public ContainerQNB(final InventoryPlayer ip, final TileQuantumBridge quantumBridge) {
super(ip, quantumBridge, null);
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge
.getInternalInventory(), 0, 80, 37, this.getInventoryPlayer() ) ).setStackLimit( 1 ) );
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge
.getInternalInventory(), 0, 80, 37, this.getInventoryPlayer())).setStackLimit(1));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
}
@@ -19,9 +19,13 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.contents.QuartzKnifeObj;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
@@ -30,150 +34,118 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import javax.annotation.Nonnull;
public class ContainerQuartzKnife extends AEBaseContainer
{
public class ContainerQuartzKnife extends AEBaseContainer {
private final QuartzKnifeObj toolInv;
private final QuartzKnifeObj toolInv;
private final IItemHandler inSlot = new AppEngInternalInventory( null, 1, 1 );
private String myName = "";
private final IItemHandler inSlot = new AppEngInternalInventory(null, 1, 1);
private String myName = "";
public ContainerQuartzKnife( final InventoryPlayer ip, final QuartzKnifeObj te )
{
super( ip, null, null );
this.toolInv = te;
public ContainerQuartzKnife(final InventoryPlayer ip, final QuartzKnifeObj te) {
super(ip, null, null);
this.toolInv = te;
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) );
this.addSlotToContainer( new QuartzKniveSlot( this.inSlot, 0, 134, 44, -1 ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip));
this.addSlotToContainer(new QuartzKniveSlot(this.inSlot, 0, 134, 44, -1));
this.lockPlayerInventorySlot( ip.currentItem );
this.lockPlayerInventorySlot(ip.currentItem);
this.bindPlayerInventory( ip, 0, 184 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 184 - /* height of player inventory */82);
}
public void setName( final String value )
{
this.myName = value;
}
public void setName(final String value) {
this.myName = value;
}
@Override
public void detectAndSendChanges()
{
final ItemStack currentItem = this.getPlayerInv().getCurrentItem();
@Override
public void detectAndSendChanges() {
final ItemStack currentItem = this.getPlayerInv().getCurrentItem();
if( currentItem != this.toolInv.getItemStack() )
{
if( !currentItem.isEmpty() )
{
if( ItemStack.areItemsEqual( this.toolInv.getItemStack(), currentItem ) )
{
this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() );
}
else
{
this.setValidContainer( false );
}
}
else
{
this.setValidContainer( false );
}
}
if (currentItem != this.toolInv.getItemStack()) {
if (!currentItem.isEmpty()) {
if (ItemStack.areItemsEqual(this.toolInv.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.toolInv.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
@Override
public void onContainerClosed( final EntityPlayer par1EntityPlayer )
{
if( this.inSlot.getStackInSlot( 0 ) != null )
{
par1EntityPlayer.dropItem( this.inSlot.getStackInSlot( 0 ), false );
}
}
@Override
public void onContainerClosed(final EntityPlayer par1EntityPlayer) {
if (this.inSlot.getStackInSlot(0) != null) {
par1EntityPlayer.dropItem(this.inSlot.getStackInSlot(0), false);
}
}
private class QuartzKniveSlot extends SlotOutput
{
QuartzKniveSlot( IItemHandler a, int b, int c, int d, int i )
{
super( a, b, c, d, i );
}
private class QuartzKniveSlot extends SlotOutput {
QuartzKniveSlot(IItemHandler a, int b, int c, int d, int i) {
super(a, b, c, d, i);
}
@Override
public ItemStack getStack()
{
final IItemHandler baseInv = this.getItemHandler();
final ItemStack input = baseInv.getStackInSlot( 0 );
if( input == ItemStack.EMPTY )
{
return ItemStack.EMPTY;
}
@Override
public ItemStack getStack() {
final IItemHandler baseInv = this.getItemHandler();
final ItemStack input = baseInv.getStackInSlot(0);
if (input == ItemStack.EMPTY) {
return ItemStack.EMPTY;
}
if( SlotRestrictedInput.isMetalIngot( input ) )
{
if( ContainerQuartzKnife.this.myName.length() > 0 )
{
return AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).map( namePressStack ->
{
final NBTTagCompound compound = Platform.openNbtData( namePressStack );
compound.setString( "InscribeName", ContainerQuartzKnife.this.myName );
if (SlotRestrictedInput.isMetalIngot(input)) {
if (ContainerQuartzKnife.this.myName.length() > 0) {
return AEApi.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack ->
{
final NBTTagCompound compound = Platform.openNbtData(namePressStack);
compound.setString("InscribeName", ContainerQuartzKnife.this.myName);
return namePressStack;
} ).orElse( ItemStack.EMPTY );
}
}
return ItemStack.EMPTY;
}
return namePressStack;
}).orElse(ItemStack.EMPTY);
}
}
return ItemStack.EMPTY;
}
@Override
@Nonnull
public ItemStack decrStackSize( int amount )
{
ItemStack ret = this.getStack();
if( !ret.isEmpty() )
{
this.makePlate();
}
return ret;
}
@Override
@Nonnull
public ItemStack decrStackSize(int amount) {
ItemStack ret = this.getStack();
if (!ret.isEmpty()) {
this.makePlate();
}
return ret;
}
@Override
public void putStack( final ItemStack stack )
{
if( stack.isEmpty() )
{
this.makePlate();
}
}
@Override
public void putStack(final ItemStack stack) {
if (stack.isEmpty()) {
this.makePlate();
}
}
private void makePlate()
{
if( Platform.isServer() )
{
if( !this.getItemHandler().extractItem( 0, 1, false ).isEmpty() )
{
final ItemStack item = ContainerQuartzKnife.this.toolInv.getItemStack();
final ItemStack before = item.copy();
item.damageItem( 1, ContainerQuartzKnife.this.getPlayerInv().player );
private void makePlate() {
if (Platform.isServer()) {
if (!this.getItemHandler().extractItem(0, 1, false).isEmpty()) {
final ItemStack item = ContainerQuartzKnife.this.toolInv.getItemStack();
final ItemStack before = item.copy();
item.damageItem(1, ContainerQuartzKnife.this.getPlayerInv().player);
if( item.getCount() == 0 )
{
ContainerQuartzKnife.this.getPlayerInv()
.setInventorySlotContents( ContainerQuartzKnife.this.getPlayerInv().currentItem, ItemStack.EMPTY );
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( ContainerQuartzKnife.this.getPlayerInv().player, before, null ) );
}
if (item.getCount() == 0) {
ContainerQuartzKnife.this.getPlayerInv()
.setInventorySlotContents(ContainerQuartzKnife.this.getPlayerInv().currentItem, ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(ContainerQuartzKnife.this.getPlayerInv().player, before, null));
}
ContainerQuartzKnife.this.detectAndSendChanges();
}
}
}
}
ContainerQuartzKnife.this.detectAndSendChanges();
}
}
}
}
}
@@ -25,7 +25,7 @@ public class ContainerRenamer extends AEBaseContainer {
@SideOnly(Side.CLIENT)
public void setTextField(final MEGuiTextField name) {
this.textField = name;
if(getCustomName() != null) textField.setText(getCustomName());
if (getCustomName() != null) textField.setText(getCustomName());
}
public void setNewName(String newValue) {
@@ -36,13 +36,13 @@ public class ContainerRenamer extends AEBaseContainer {
@Override
public void setCustomName(final String customName) {
super.setCustomName(customName);
if(!Platform.isServer() && customName != null) textField.setText(customName);
if (!Platform.isServer() && customName != null) textField.setText(customName);
}
@Override
public void detectAndSendChanges() {
verifyPermissions(SecurityPermissions.BUILD, false);
super.detectAndSendChanges();
if(!Platform.isServer() && getCustomName() != null) textField.setText(getCustomName());
if (!Platform.isServer() && getCustomName() != null) textField.setText(getCustomName());
}
}
@@ -19,12 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.INetworkEncodable;
@@ -38,155 +32,134 @@ import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileSecurityStation;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory
{
public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory {
private final SlotRestrictedInput configSlot;
private final SlotRestrictedInput configSlot;
private final AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory( this, 2 );
private final AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory(this, 2);
private final SlotRestrictedInput wirelessIn;
private final SlotOutput wirelessOut;
private final SlotRestrictedInput wirelessIn;
private final SlotOutput wirelessOut;
private final TileSecurityStation securityBox;
@GuiSync( 0 )
public int permissionMode = 0;
private final TileSecurityStation securityBox;
@GuiSync(0)
public int permissionMode = 0;
public ContainerSecurityStation( final InventoryPlayer ip, final ITerminalHost monitorable )
{
super( ip, monitorable, false );
public ContainerSecurityStation(final InventoryPlayer ip, final ITerminalHost monitorable) {
super(ip, monitorable, false);
this.securityBox = (TileSecurityStation) monitorable;
this.securityBox = (TileSecurityStation) monitorable;
this.addSlotToContainer( this.configSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD, this.securityBox
.getConfigSlot(), 0, 37, -33, ip ) );
this.addSlotToContainer(this.configSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD, this.securityBox
.getConfigSlot(), 0, 37, -33, ip));
this.addSlotToContainer(
this.wirelessIn = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODABLE_ITEM, this.wirelessEncoder, 0, 212, 10, ip ) );
this.addSlotToContainer( this.wirelessOut = new SlotOutput( this.wirelessEncoder, 1, 212, 68, -1 ) );
this.addSlotToContainer(
this.wirelessIn = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODABLE_ITEM, this.wirelessEncoder, 0, 212, 10, ip));
this.addSlotToContainer(this.wirelessOut = new SlotOutput(this.wirelessEncoder, 1, 212, 68, -1));
this.bindPlayerInventory( ip, 0, 0 );
}
this.bindPlayerInventory(ip, 0, 0);
}
public void toggleSetting( final String value, final EntityPlayer player )
{
try
{
final SecurityPermissions permission = SecurityPermissions.valueOf( value );
public void toggleSetting(final String value, final EntityPlayer player) {
try {
final SecurityPermissions permission = SecurityPermissions.valueOf(value);
final ItemStack a = this.configSlot.getStack();
if( !a.isEmpty() && a.getItem() instanceof IBiometricCard )
{
final IBiometricCard bc = (IBiometricCard) a.getItem();
if( bc.hasPermission( a, permission ) )
{
bc.removePermission( a, permission );
}
else
{
bc.addPermission( a, permission );
}
}
}
catch( final EnumConstantNotPresentException ex )
{
// :(
}
}
final ItemStack a = this.configSlot.getStack();
if (!a.isEmpty() && a.getItem() instanceof IBiometricCard) {
final IBiometricCard bc = (IBiometricCard) a.getItem();
if (bc.hasPermission(a, permission)) {
bc.removePermission(a, permission);
} else {
bc.addPermission(a, permission);
}
}
} catch (final EnumConstantNotPresentException ex) {
// :(
}
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.SECURITY, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.SECURITY, false);
this.setPermissionMode( 0 );
this.setPermissionMode(0);
final ItemStack a = this.configSlot.getStack();
if( !a.isEmpty() && a.getItem() instanceof IBiometricCard )
{
final IBiometricCard bc = (IBiometricCard) a.getItem();
final ItemStack a = this.configSlot.getStack();
if (!a.isEmpty() && a.getItem() instanceof IBiometricCard) {
final IBiometricCard bc = (IBiometricCard) a.getItem();
for( final SecurityPermissions sp : bc.getPermissions( a ) )
{
this.setPermissionMode( this.getPermissionMode() | ( 1 << sp.ordinal() ) );
}
}
for (final SecurityPermissions sp : bc.getPermissions(a)) {
this.setPermissionMode(this.getPermissionMode() | (1 << sp.ordinal()));
}
}
this.updatePowerStatus();
this.updatePowerStatus();
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
@Override
public void onContainerClosed( final EntityPlayer player )
{
super.onContainerClosed( player );
@Override
public void onContainerClosed(final EntityPlayer player) {
super.onContainerClosed(player);
if( this.wirelessIn.getHasStack() )
{
player.dropItem( this.wirelessIn.getStack(), false );
}
if (this.wirelessIn.getHasStack()) {
player.dropItem(this.wirelessIn.getStack(), false);
}
if( this.wirelessOut.getHasStack() )
{
player.dropItem( this.wirelessOut.getStack(), false );
}
}
if (this.wirelessOut.getHasStack()) {
player.dropItem(this.wirelessOut.getStack(), false);
}
}
@Override
public void saveChanges()
{
// :P
}
@Override
public void saveChanges() {
// :P
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( !this.wirelessOut.getHasStack() )
{
if( this.wirelessIn.getHasStack() )
{
final ItemStack term = this.wirelessIn.getStack().copy();
INetworkEncodable networkEncodable = null;
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (!this.wirelessOut.getHasStack()) {
if (this.wirelessIn.getHasStack()) {
final ItemStack term = this.wirelessIn.getStack().copy();
INetworkEncodable networkEncodable = null;
if( term.getItem() instanceof INetworkEncodable )
{
networkEncodable = (INetworkEncodable) term.getItem();
}
if (term.getItem() instanceof INetworkEncodable) {
networkEncodable = (INetworkEncodable) term.getItem();
}
final IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless().getWirelessTerminalHandler( term );
if( wTermHandler != null )
{
networkEncodable = wTermHandler;
}
final IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless().getWirelessTerminalHandler(term);
if (wTermHandler != null) {
networkEncodable = wTermHandler;
}
if( networkEncodable != null )
{
networkEncodable.setEncryptionKey( term, String.valueOf( this.securityBox.getSecurityKey() ), "" );
if (networkEncodable != null) {
networkEncodable.setEncryptionKey(term, String.valueOf(this.securityBox.getSecurityKey()), "");
this.wirelessIn.putStack( ItemStack.EMPTY );
this.wirelessOut.putStack( term );
this.wirelessIn.putStack(ItemStack.EMPTY);
this.wirelessOut.putStack(term);
// update the two slots in question...
for( final IContainerListener listener : this.listeners )
{
listener.sendSlotContents( this, this.wirelessIn.slotNumber, this.wirelessIn.getStack() );
listener.sendSlotContents( this, this.wirelessOut.slotNumber, this.wirelessOut.getStack() );
}
}
}
}
}
// update the two slots in question...
for (final IContainerListener listener : this.listeners) {
listener.sendSlotContents(this, this.wirelessIn.slotNumber, this.wirelessIn.getStack());
listener.sendSlotContents(this, this.wirelessOut.slotNumber, this.wirelessOut.getStack());
}
}
}
}
}
public int getPermissionMode()
{
return this.permissionMode;
}
public int getPermissionMode() {
return this.permissionMode;
}
private void setPermissionMode( final int permissionMode )
{
this.permissionMode = permissionMode;
}
private void setPermissionMode(final int permissionMode) {
this.permissionMode = permissionMode;
}
}
@@ -19,41 +19,35 @@
package appeng.container.implementations;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import appeng.tile.storage.TileSkyChest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerSkyChest extends AEBaseContainer
{
public class ContainerSkyChest extends AEBaseContainer {
private final TileSkyChest chest;
private final TileSkyChest chest;
public ContainerSkyChest( final InventoryPlayer ip, final TileSkyChest chest )
{
super( ip, chest, null );
this.chest = chest;
public ContainerSkyChest(final InventoryPlayer ip, final TileSkyChest chest) {
super(ip, chest, null);
this.chest = chest;
for( int y = 0; y < 4; y++ )
{
for( int x = 0; x < 9; x++ )
{
this.addSlotToContainer( new SlotNormal( this.chest.getInternalInventory(), y * 9 + x, 8 + 18 * x, 24 + 18 * y ) );
}
}
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 9; x++) {
this.addSlotToContainer(new SlotNormal(this.chest.getInternalInventory(), y * 9 + x, 8 + 18 * x, 24 + 18 * y));
}
}
this.chest.openInventory( ip.player );
this.chest.openInventory(ip.player);
this.bindPlayerInventory( ip, 0, 195 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 195 - /* height of player inventory */82);
}
@Override
public void onContainerClosed( final EntityPlayer par1EntityPlayer )
{
super.onContainerClosed( par1EntityPlayer );
this.chest.closeInventory( par1EntityPlayer );
}
@Override
public void onContainerClosed(final EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
this.chest.closeInventory(par1EntityPlayer);
}
}
@@ -19,8 +19,6 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
@@ -33,126 +31,109 @@ import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.spatial.TileSpatialIOPort;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerSpatialIOPort extends AEBaseContainer
{
public class ContainerSpatialIOPort extends AEBaseContainer {
@GuiSync( 0 )
public long currentPower;
@GuiSync( 1 )
public long maxPower;
@GuiSync( 2 )
public long reqPower;
@GuiSync( 3 )
public long eff;
private IGrid network;
private int delay = 40;
@GuiSync(0)
public long currentPower;
@GuiSync(1)
public long maxPower;
@GuiSync(2)
public long reqPower;
@GuiSync(3)
public long eff;
private IGrid network;
private int delay = 40;
@GuiSync( 31 )
public int xSize;
@GuiSync( 32 )
public int ySize;
@GuiSync( 33 )
public int zSize;
@GuiSync(31)
public int xSize;
@GuiSync(32)
public int ySize;
@GuiSync(33)
public int zSize;
public ContainerSpatialIOPort( final InventoryPlayer ip, final TileSpatialIOPort spatialIOPort )
{
super( ip, spatialIOPort, null );
public ContainerSpatialIOPort(final InventoryPlayer ip, final TileSpatialIOPort spatialIOPort) {
super(ip, spatialIOPort, null);
if( Platform.isServer() )
{
this.network = spatialIOPort.getGridNode( AEPartLocation.INTERNAL ).getGrid();
}
if (Platform.isServer()) {
this.network = spatialIOPort.getGridNode(AEPartLocation.INTERNAL).getGrid();
}
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort
.getInternalInventory(), 0, 52, 48, this.getInventoryPlayer() ) );
this.addSlotToContainer(
new SlotOutput( spatialIOPort.getInternalInventory(), 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort
.getInternalInventory(), 0, 52, 48, this.getInventoryPlayer()));
this.addSlotToContainer(
new SlotOutput(spatialIOPort.getInternalInventory(), 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon));
this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 197 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.delay++;
if( this.delay > 15 && this.network != null )
{
this.delay = 0;
if (Platform.isServer()) {
this.delay++;
if (this.delay > 15 && this.network != null) {
this.delay = 0;
final IEnergyGrid eg = this.network.getCache( IEnergyGrid.class );
final ISpatialCache sc = this.network.getCache( ISpatialCache.class );
if( eg != null )
{
this.setCurrentPower( (long) ( 100.0 * eg.getStoredPower() ) );
this.setMaxPower( (long) ( 100.0 * eg.getMaxStoredPower() ) );
this.setRequiredPower( (long) ( 100.0 * sc.requiredPower() ) );
this.setEfficency( (long) ( 100.0f * sc.currentEfficiency() ) );
final IEnergyGrid eg = this.network.getCache(IEnergyGrid.class);
final ISpatialCache sc = this.network.getCache(ISpatialCache.class);
if (eg != null) {
this.setCurrentPower((long) (100.0 * eg.getStoredPower()));
this.setMaxPower((long) (100.0 * eg.getMaxStoredPower()));
this.setRequiredPower((long) (100.0 * sc.requiredPower()));
this.setEfficency((long) (100.0f * sc.currentEfficiency()));
final DimensionalCoord min = sc.getMin();
final DimensionalCoord max = sc.getMax();
final DimensionalCoord min = sc.getMin();
final DimensionalCoord max = sc.getMax();
if( min != null && max != null && sc.isValidRegion() )
{
this.xSize = sc.getMax().x - sc.getMin().x - 1;
this.ySize = sc.getMax().y - sc.getMin().y - 1;
this.zSize = sc.getMax().z - sc.getMin().z - 1;
}
else
{
this.xSize = 0;
this.ySize = 0;
this.zSize = 0;
}
}
}
}
if (min != null && max != null && sc.isValidRegion()) {
this.xSize = sc.getMax().x - sc.getMin().x - 1;
this.ySize = sc.getMax().y - sc.getMin().y - 1;
this.zSize = sc.getMax().z - sc.getMin().z - 1;
} else {
this.xSize = 0;
this.ySize = 0;
this.zSize = 0;
}
}
}
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
public long getCurrentPower()
{
return this.currentPower;
}
public long getCurrentPower() {
return this.currentPower;
}
private void setCurrentPower( final long currentPower )
{
this.currentPower = currentPower;
}
private void setCurrentPower(final long currentPower) {
this.currentPower = currentPower;
}
public long getMaxPower()
{
return this.maxPower;
}
public long getMaxPower() {
return this.maxPower;
}
private void setMaxPower( final long maxPower )
{
this.maxPower = maxPower;
}
private void setMaxPower(final long maxPower) {
this.maxPower = maxPower;
}
public long getRequiredPower()
{
return this.reqPower;
}
public long getRequiredPower() {
return this.reqPower;
}
private void setRequiredPower( final long reqPower )
{
this.reqPower = reqPower;
}
private void setRequiredPower(final long reqPower) {
this.reqPower = reqPower;
}
public long getEfficency()
{
return this.eff;
}
public long getEfficency() {
return this.eff;
}
private void setEfficency( final long eff )
{
this.eff = eff;
}
private void setEfficency(final long eff) {
this.eff = eff;
}
}
@@ -19,19 +19,8 @@
package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.config.*;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
@@ -44,159 +33,139 @@ import appeng.parts.misc.PartStorageBus;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.iterators.NullIterator;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.Iterator;
public class ContainerStorageBus extends ContainerUpgradeable
{
public class ContainerStorageBus extends ContainerUpgradeable {
private final PartStorageBus storageBus;
private final PartStorageBus storageBus;
@GuiSync( 3 )
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync( 4 )
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerStorageBus( final InventoryPlayer ip, final PartStorageBus te )
{
super( ip, te );
this.storageBus = te;
}
public ContainerStorageBus(final InventoryPlayer ip, final PartStorageBus te) {
super(ip, te);
this.storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig()
{
final int xo = 8;
final int yo = 23 + 6;
@Override
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" );
for( int y = 0; y < 7; y++ )
{
for( int x = 0; x < 9; x++ )
{
if( y < 2 )
{
this.addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
}
else
{
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
}
final IItemHandler config = this.getUpgradeable().getInventoryByName("config");
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
if (y < 2) {
this.addSlotToContainer(new SlotFakeTypeOnly(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(config, this, y * 9 + x, xo, yo, x, y, y - 2));
}
}
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer()))
.setNotDraggable());
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if( Platform.isServer() )
{
this.setFuzzyMode( (FuzzyMode) this.getUpgradeable().getConfigManager().getSetting( Settings.FUZZY_MODE ) );
this.setReadWriteMode( (AccessRestriction) this.getUpgradeable().getConfigManager().getSetting( Settings.ACCESS ) );
this.setStorageFilter( (StorageFilter) this.getUpgradeable().getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
}
if (Platform.isServer()) {
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setReadWriteMode((AccessRestriction) this.getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter((StorageFilter) this.getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled( final int idx )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
return upgrades > idx;
}
public void clear()
{
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
this.detectAndSendChanges();
}
public void clear() {
ItemHandlerUtil.clear(this.getUpgradeable().getInventoryByName("config"));
this.detectAndSendChanges();
}
public void partition()
{
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
public void partition() {
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final IMEInventory<IAEItemStack> cellInv = this.storageBus.getInternalHandler();
final IMEInventory<IAEItemStack> cellInv = this.storageBus.getInternalHandler();
Iterator<IAEItemStack> i = new NullIterator<>();
if( cellInv != null )
{
final IItemList<IAEItemStack> list = cellInv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
i = list.iterator();
}
Iterator<IAEItemStack> i = new NullIterator<>();
if (cellInv != null) {
final IItemList<IAEItemStack> list = cellInv
.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
i = list.iterator();
}
for( int x = 0; x < inv.getSlots(); x++ )
{
if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) )
{
// TODO: check if ok
final ItemStack g = i.next().asItemStackRepresentation();
ItemHandlerUtil.setStackInSlot( inv, x, g );
}
else
{
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
}
}
for (int x = 0; x < inv.getSlots(); x++) {
if (i.hasNext() && this.isSlotEnabled((x / 9) - 2)) {
// TODO: check if ok
final ItemStack g = i.next().asItemStackRepresentation();
ItemHandlerUtil.setStackInSlot(inv, x, g);
} else {
ItemHandlerUtil.setStackInSlot(inv, x, ItemStack.EMPTY);
}
}
this.detectAndSendChanges();
}
this.detectAndSendChanges();
}
public AccessRestriction getReadWriteMode()
{
return this.rwMode;
}
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode( final AccessRestriction rwMode )
{
this.rwMode = rwMode;
}
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter()
{
return this.storageFilter;
}
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter( final StorageFilter storageFilter )
{
this.storageFilter = storageFilter;
}
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
}
@@ -19,7 +19,18 @@
package appeng.container.implementations;
import appeng.api.config.*;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.parts.IPart;
import appeng.api.util.IConfigManager;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.*;
import appeng.items.contents.NetworkToolViewer;
import appeng.items.tools.ToolNetworkTool;
import appeng.parts.automation.PartExportBus;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -28,304 +39,229 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.parts.IPart;
import appeng.api.util.IConfigManager;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.tools.ToolNetworkTool;
import appeng.parts.automation.PartExportBus;
import appeng.util.Platform;
public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost {
public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost
{
private final IUpgradeableHost upgradeable;
@GuiSync(0)
public RedstoneMode rsMode = RedstoneMode.IGNORE;
@GuiSync(1)
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
@GuiSync(5)
public YesNo cMode = YesNo.NO;
@GuiSync(6)
public SchedulingMode schedulingMode = SchedulingMode.DEFAULT;
private int tbSlot;
private NetworkToolViewer tbInventory;
private final IUpgradeableHost upgradeable;
@GuiSync( 0 )
public RedstoneMode rsMode = RedstoneMode.IGNORE;
@GuiSync( 1 )
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
@GuiSync( 5 )
public YesNo cMode = YesNo.NO;
@GuiSync( 6 )
public SchedulingMode schedulingMode = SchedulingMode.DEFAULT;
private int tbSlot;
private NetworkToolViewer tbInventory;
public ContainerUpgradeable(final InventoryPlayer ip, final IUpgradeableHost te) {
super(ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null));
this.upgradeable = te;
public ContainerUpgradeable( final InventoryPlayer ip, final IUpgradeableHost te )
{
super( ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) );
this.upgradeable = te;
World w = null;
int xCoord = 0;
int yCoord = 0;
int zCoord = 0;
World w = null;
int xCoord = 0;
int yCoord = 0;
int zCoord = 0;
if (te instanceof TileEntity) {
final TileEntity myTile = (TileEntity) te;
w = myTile.getWorld();
xCoord = myTile.getPos().getX();
yCoord = myTile.getPos().getY();
zCoord = myTile.getPos().getZ();
}
if( te instanceof TileEntity )
{
final TileEntity myTile = (TileEntity) te;
w = myTile.getWorld();
xCoord = myTile.getPos().getX();
yCoord = myTile.getPos().getY();
zCoord = myTile.getPos().getZ();
}
if (te instanceof IPart) {
final TileEntity mk = te.getTile();
w = mk.getWorld();
xCoord = mk.getPos().getX();
yCoord = mk.getPos().getY();
zCoord = mk.getPos().getZ();
}
if( te instanceof IPart )
{
final TileEntity mk = te.getTile();
w = mk.getWorld();
xCoord = mk.getPos().getX();
yCoord = mk.getPos().getY();
zCoord = mk.getPos().getZ();
}
final IInventory pi = this.getPlayerInv();
for (int x = 0; x < pi.getSizeInventory(); x++) {
final ItemStack pii = pi.getStackInSlot(x);
if (!pii.isEmpty() && pii.getItem() instanceof ToolNetworkTool) {
this.lockPlayerInventorySlot(x);
this.tbSlot = x;
this.tbInventory = (NetworkToolViewer) ((IGuiItem) pii.getItem()).getGuiObject(pii, w, new BlockPos(xCoord, yCoord, zCoord));
break;
}
}
final IInventory pi = this.getPlayerInv();
for( int x = 0; x < pi.getSizeInventory(); x++ )
{
final ItemStack pii = pi.getStackInSlot( x );
if( !pii.isEmpty() && pii.getItem() instanceof ToolNetworkTool )
{
this.lockPlayerInventorySlot( x );
this.tbSlot = x;
this.tbInventory = (NetworkToolViewer) ( (IGuiItem) pii.getItem() ).getGuiObject( pii, w, new BlockPos( xCoord, yCoord, zCoord ) );
break;
}
}
if (this.hasToolbox()) {
for (int v = 0; v < 3; v++) {
for (int u = 0; u < 3; u++) {
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory
.getInternalInventory(), u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getInventoryPlayer())).setPlayerSide());
}
}
}
if( this.hasToolbox() )
{
for( int v = 0; v < 3; v++ )
{
for( int u = 0; u < 3; u++ )
{
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory
.getInternalInventory(), u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() );
}
}
}
this.setupConfig();
this.setupConfig();
this.bindPlayerInventory(ip, 0, this.getHeight() - /* height of player inventory */82);
}
this.bindPlayerInventory( ip, 0, this.getHeight() - /* height of player inventory */82 );
}
public boolean hasToolbox() {
return this.tbInventory != null;
}
public boolean hasToolbox()
{
return this.tbInventory != null;
}
protected int getHeight() {
return 184;
}
protected int getHeight()
{
return 184;
}
protected void setupConfig() {
this.setupUpgrades();
protected void setupConfig()
{
this.setupUpgrades();
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80;
this.addSlotToContainer(new SlotFakeTypeOnly(inv, 0, x, y));
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80;
this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
if (this.supportCapacity()) {
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 1, x, y, -1, 0, 1));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 2, x, y, 1, 0, 1));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 3, x, y, 0, -1, 1));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 4, x, y, 0, 1, 1));
if( this.supportCapacity() )
{
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 5, x, y, -1, -1, 2));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 6, x, y, 1, -1, 2));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 7, x, y, -1, 1, 2));
this.addSlotToContainer(new OptionalSlotFakeTypeOnly(inv, this, 8, x, y, 1, 1, 2));
}
}
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
}
}
protected void setupUpgrades() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
if (this.availableUpgrades() > 0) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
}
}
protected void setupUpgrades()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 1 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 2 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 3 )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
}
protected boolean supportCapacity() {
return true;
}
protected boolean supportCapacity()
{
return true;
}
public int availableUpgrades() {
return 4;
}
public int availableUpgrades()
{
return 4;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
if (Platform.isServer()) {
final IConfigManager cm = this.getUpgradeable().getConfigManager();
this.loadSettingsFromHost(cm);
}
if( Platform.isServer() )
{
final IConfigManager cm = this.getUpgradeable().getConfigManager();
this.loadSettingsFromHost( cm );
}
this.checkToolbox();
this.checkToolbox();
for (final Object o : this.inventorySlots) {
if (o instanceof OptionalSlotFake) {
final OptionalSlotFake fs = (OptionalSlotFake) o;
if (!fs.isSlotEnabled() && !fs.getDisplayStack().isEmpty()) {
fs.clearStack();
}
}
}
for( final Object o : this.inventorySlots )
{
if( o instanceof OptionalSlotFake )
{
final OptionalSlotFake fs = (OptionalSlotFake) o;
if( !fs.isSlotEnabled() && !fs.getDisplayStack().isEmpty() )
{
fs.clearStack();
}
}
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
protected void loadSettingsFromHost(final IConfigManager cm) {
this.setFuzzyMode((FuzzyMode) cm.getSetting(Settings.FUZZY_MODE));
this.setRedStoneMode((RedstoneMode) cm.getSetting(Settings.REDSTONE_CONTROLLED));
if (this.getUpgradeable() instanceof PartExportBus) {
this.setCraftingMode((YesNo) cm.getSetting(Settings.CRAFT_ONLY));
this.setSchedulingMode((SchedulingMode) cm.getSetting(Settings.SCHEDULING_MODE));
}
}
protected void loadSettingsFromHost( final IConfigManager cm )
{
this.setFuzzyMode( (FuzzyMode) cm.getSetting( Settings.FUZZY_MODE ) );
this.setRedStoneMode( (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED ) );
if( this.getUpgradeable() instanceof PartExportBus )
{
this.setCraftingMode( (YesNo) cm.getSetting( Settings.CRAFT_ONLY ) );
this.setSchedulingMode( (SchedulingMode) cm.getSetting( Settings.SCHEDULING_MODE ) );
}
}
protected void checkToolbox() {
if (this.hasToolbox()) {
final ItemStack currentItem = this.getPlayerInv().getStackInSlot(this.tbSlot);
protected void checkToolbox()
{
if( this.hasToolbox() )
{
final ItemStack currentItem = this.getPlayerInv().getStackInSlot( this.tbSlot );
if (currentItem != this.tbInventory.getItemStack()) {
if (!currentItem.isEmpty()) {
if (ItemStack.areItemsEqual(this.tbInventory.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.tbSlot, this.tbInventory.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
}
}
if( currentItem != this.tbInventory.getItemStack() )
{
if( !currentItem.isEmpty() )
{
if( ItemStack.areItemsEqual( this.tbInventory.getItemStack(), currentItem ) )
{
this.getPlayerInv().setInventorySlotContents( this.tbSlot, this.tbInventory.getItemStack() );
}
else
{
this.setValidContainer( false );
}
}
else
{
this.setValidContainer( false );
}
}
}
}
protected void standardDetectAndSendChanges() {
super.detectAndSendChanges();
}
protected void standardDetectAndSendChanges()
{
super.detectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
@Override
public boolean isSlotEnabled( final int idx )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
if (idx == 1 && upgrades > 0) {
return true;
}
return idx == 2 && upgrades > 1;
}
if( idx == 1 && upgrades > 0 )
{
return true;
}
if( idx == 2 && upgrades > 1 )
{
return true;
}
public FuzzyMode getFuzzyMode() {
return this.fzMode;
}
return false;
}
public void setFuzzyMode(final FuzzyMode fzMode) {
this.fzMode = fzMode;
}
public FuzzyMode getFuzzyMode()
{
return this.fzMode;
}
public YesNo getCraftingMode() {
return this.cMode;
}
public void setFuzzyMode( final FuzzyMode fzMode )
{
this.fzMode = fzMode;
}
public void setCraftingMode(final YesNo cMode) {
this.cMode = cMode;
}
public YesNo getCraftingMode()
{
return this.cMode;
}
public RedstoneMode getRedStoneMode() {
return this.rsMode;
}
public void setCraftingMode( final YesNo cMode )
{
this.cMode = cMode;
}
public void setRedStoneMode(final RedstoneMode rsMode) {
this.rsMode = rsMode;
}
public RedstoneMode getRedStoneMode()
{
return this.rsMode;
}
public SchedulingMode getSchedulingMode() {
return this.schedulingMode;
}
public void setRedStoneMode( final RedstoneMode rsMode )
{
this.rsMode = rsMode;
}
private void setSchedulingMode(final SchedulingMode schedulingMode) {
this.schedulingMode = schedulingMode;
}
public SchedulingMode getSchedulingMode()
{
return this.schedulingMode;
}
private void setSchedulingMode( final SchedulingMode schedulingMode )
{
this.schedulingMode = schedulingMode;
}
protected IUpgradeableHost getUpgradeable()
{
return this.upgradeable;
}
protected IUpgradeableHost getUpgradeable() {
return this.upgradeable;
}
}
@@ -19,62 +19,54 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileVibrationChamber;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider
{
private final TileVibrationChamber vibrationChamber;
@GuiSync( 0 )
public int burnSpeed = 0;
@GuiSync( 1 )
public int remainingBurnTime = 0;
public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider {
private final TileVibrationChamber vibrationChamber;
@GuiSync(0)
public int burnSpeed = 0;
@GuiSync(1)
public int remainingBurnTime = 0;
public ContainerVibrationChamber( final InventoryPlayer ip, final TileVibrationChamber vibrationChamber )
{
super( ip, vibrationChamber, null );
this.vibrationChamber = vibrationChamber;
public ContainerVibrationChamber(final InventoryPlayer ip, final TileVibrationChamber vibrationChamber) {
super(ip, vibrationChamber, null);
this.vibrationChamber = vibrationChamber;
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this
.getInventoryPlayer() ) );
this.addSlotToContainer(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this
.getInventoryPlayer()));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() )
{
this.remainingBurnTime = this.vibrationChamber
.getMaxBurnTime() <= 0 ? 0 : (int) ( 100.0 * this.vibrationChamber.getBurnTime() / this.vibrationChamber.getMaxBurnTime() );
this.burnSpeed = this.remainingBurnTime <= 0 ? 0 : this.vibrationChamber.getBurnSpeed();
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
this.remainingBurnTime = this.vibrationChamber
.getMaxBurnTime() <= 0 ? 0 : (int) (100.0 * this.vibrationChamber.getBurnTime() / this.vibrationChamber.getMaxBurnTime());
this.burnSpeed = this.remainingBurnTime <= 0 ? 0 : this.vibrationChamber.getBurnSpeed();
}
super.detectAndSendChanges();
}
}
super.detectAndSendChanges();
}
@Override
public int getCurrentProgress()
{
return this.burnSpeed;
}
@Override
public int getCurrentProgress() {
return this.burnSpeed;
}
public int getRemainingBurnTime()
{
return this.remainingBurnTime;
}
public int getRemainingBurnTime() {
return this.remainingBurnTime;
}
@Override
public int getMaxProgress()
{
return TileVibrationChamber.MAX_BURN_SPEED;
}
@Override
public int getMaxProgress() {
return TileVibrationChamber.MAX_BURN_SPEED;
}
}
@@ -19,64 +19,56 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig;
import appeng.tile.networking.TileWireless;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerWireless extends AEBaseContainer
{
public class ContainerWireless extends AEBaseContainer {
private final TileWireless wirelessTerminal;
private final SlotRestrictedInput boosterSlot;
@GuiSync( 1 )
public long range = 0;
@GuiSync( 2 )
public long drain = 0;
private final TileWireless wirelessTerminal;
private final SlotRestrictedInput boosterSlot;
@GuiSync(1)
public long range = 0;
@GuiSync(2)
public long drain = 0;
public ContainerWireless( final InventoryPlayer ip, final TileWireless te )
{
super( ip, te, null );
this.wirelessTerminal = te;
public ContainerWireless(final InventoryPlayer ip, final TileWireless te) {
super(ip, te, null);
this.wirelessTerminal = te;
this.addSlotToContainer( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal
.getInternalInventory(), 0, 80, 47, this.getInventoryPlayer() ) );
this.addSlotToContainer(this.boosterSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal
.getInternalInventory(), 0, 80, 47, this.getInventoryPlayer()));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges()
{
final int boosters = this.boosterSlot.getStack().isEmpty() ? 0 : this.boosterSlot.getStack().getCount();
@Override
public void detectAndSendChanges() {
final int boosters = this.boosterSlot.getStack().isEmpty() ? 0 : this.boosterSlot.getStack().getCount();
this.setRange( (long) ( 10 * AEConfig.instance().wireless_getMaxRange( boosters ) ) );
this.setDrain( (long) ( 100 * AEConfig.instance().wireless_getPowerDrain( boosters ) ) );
this.setRange((long) (10 * AEConfig.instance().wireless_getMaxRange(boosters)));
this.setDrain((long) (100 * AEConfig.instance().wireless_getPowerDrain(boosters)));
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
public long getRange()
{
return this.range;
}
public long getRange() {
return this.range;
}
private void setRange( final long range )
{
this.range = range;
}
private void setRange(final long range) {
this.range = range;
}
public long getDrain()
{
return this.drain;
}
public long getDrain() {
return this.drain;
}
private void setDrain( final long drain )
{
this.drain = drain;
}
private void setDrain(final long drain) {
this.drain = drain;
}
}
@@ -19,42 +19,34 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerWirelessTerm extends ContainerMEPortableCell
{
public class ContainerWirelessTerm extends ContainerMEPortableCell {
private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
public ContainerWirelessTerm( final InventoryPlayer ip, final WirelessTerminalGuiObject gui )
{
super( ip, gui );
this.wirelessTerminalGUIObject = gui;
}
public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) {
super(ip, gui);
this.wirelessTerminalGUIObject = gui;
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if( !this.wirelessTerminalGUIObject.rangeCheck() )
{
if( Platform.isServer() && this.isValidContainer() )
{
this.getPlayerInv().player.sendMessage( PlayerMessages.OutOfRange.get() );
}
if (!this.wirelessTerminalGUIObject.rangeCheck()) {
if (Platform.isServer() && this.isValidContainer()) {
this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get());
}
this.setValidContainer( false );
}
else
{
this.setPowerMultiplier( AEConfig.instance().wireless_getDrainRate( this.wirelessTerminalGUIObject.getRange() ) );
}
}
this.setValidContainer(false);
} else {
this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange()));
}
}
}
@@ -19,55 +19,47 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import appeng.api.networking.crafting.ICraftingCPU;
import javax.annotation.Nonnull;
public class CraftingCPURecord implements Comparable<CraftingCPURecord>
{
private final String myName;
private final ICraftingCPU cpu;
private final long size;
private final int processors;
public class CraftingCPURecord implements Comparable<CraftingCPURecord> {
public CraftingCPURecord( final long size, final int coProcessors, final ICraftingCPU server )
{
this.size = size;
this.processors = coProcessors;
this.cpu = server;
this.myName = server.getName();
}
private final String myName;
private final ICraftingCPU cpu;
private final long size;
private final int processors;
@Override
public int compareTo( @Nonnull final CraftingCPURecord o )
{
final int a = Long.compare( o.getProcessors(), this.getProcessors() );
if( a != 0 )
{
return a;
}
return Long.compare( o.getSize(), this.getSize() );
}
public CraftingCPURecord(final long size, final int coProcessors, final ICraftingCPU server) {
this.size = size;
this.processors = coProcessors;
this.cpu = server;
this.myName = server.getName();
}
ICraftingCPU getCpu()
{
return this.cpu;
}
@Override
public int compareTo(@Nonnull final CraftingCPURecord o) {
final int a = Long.compare(o.getProcessors(), this.getProcessors());
if (a != 0) {
return a;
}
return Long.compare(o.getSize(), this.getSize());
}
String getName()
{
return this.myName;
}
ICraftingCPU getCpu() {
return this.cpu;
}
int getProcessors()
{
return this.processors;
}
String getName() {
return this.myName;
}
long getSize()
{
return this.size;
}
int getProcessors() {
return this.processors;
}
long getSize() {
return this.size;
}
}
@@ -23,8 +23,7 @@ public class CraftingCPUStatus implements Comparable<CraftingCPUStatus> {
private final long remainingItems;
private final IAEItemStack crafting;
public CraftingCPUStatus( )
{
public CraftingCPUStatus() {
this.serverCluster = null;
this.name = "ERROR";
this.serial = 0;
@@ -35,19 +34,15 @@ public class CraftingCPUStatus implements Comparable<CraftingCPUStatus> {
this.crafting = null;
}
public CraftingCPUStatus( ICraftingCPU cluster, int serial )
{
public CraftingCPUStatus(ICraftingCPU cluster, int serial) {
this.serverCluster = cluster;
this.name = cluster.getName();
this.serial = serial;
if (cluster.isBusy())
{
if (cluster.isBusy()) {
crafting = cluster.getFinalOutput();
totalItems = cluster.getStartItemCount();
remainingItems = cluster.getRemainingItemCount();
}
else
{
} else {
crafting = null;
totalItems = 0;
remainingItems = 0;
@@ -56,141 +51,114 @@ public class CraftingCPUStatus implements Comparable<CraftingCPUStatus> {
this.coprocessors = cluster.getCoProcessors();
}
public CraftingCPUStatus( NBTTagCompound i )
{
public CraftingCPUStatus(NBTTagCompound i) {
this.serverCluster = null;
this.name = i.getString( "name" );
this.serial = i.getInteger( "serial" );
this.name = i.getString("name");
this.serial = i.getInteger("serial");
this.storage = i.getLong("storage");
this.coprocessors = i.getLong("coprocessors");
this.totalItems = i.getLong("totalItems");
this.remainingItems = i.getLong("remainingItems");
this.crafting = i.hasKey( "crafting" ) ? AEItemStack.fromNBT( i.getCompoundTag( "crafting" ) ) : null;
this.crafting = i.hasKey("crafting") ? AEItemStack.fromNBT(i.getCompoundTag("crafting")) : null;
}
public CraftingCPUStatus(ByteBuf packet) throws IOException
{
this(readNBTFromPacket( packet ));
public CraftingCPUStatus(ByteBuf packet) throws IOException {
this(readNBTFromPacket(packet));
}
private static NBTTagCompound readNBTFromPacket(ByteBuf packet) throws IOException
{
private static NBTTagCompound readNBTFromPacket(ByteBuf packet) throws IOException {
final int size = packet.readInt();
final byte[] tagBytes = new byte[size];
packet.readBytes( tagBytes );
final ByteArrayInputStream di = new ByteArrayInputStream( tagBytes );
return CompressedStreamTools.read( new DataInputStream( di ));
packet.readBytes(tagBytes);
final ByteArrayInputStream di = new ByteArrayInputStream(tagBytes);
return CompressedStreamTools.read(new DataInputStream(di));
}
public void writeToNBT( NBTTagCompound i )
{
if (name != null && !name.isEmpty())
{
i.setString( "name", name );
public void writeToNBT(NBTTagCompound i) {
if (name != null && !name.isEmpty()) {
i.setString("name", name);
}
i.setInteger( "serial", serial );
i.setLong( "storage", storage );
i.setLong( "coprocessors", coprocessors );
i.setLong( "totalItems", totalItems );
i.setLong( "remainingItems", remainingItems );
if (crafting != null)
{
i.setInteger("serial", serial);
i.setLong("storage", storage);
i.setLong("coprocessors", coprocessors);
i.setLong("totalItems", totalItems);
i.setLong("remainingItems", remainingItems);
if (crafting != null) {
NBTTagCompound stack = new NBTTagCompound();
crafting.writeToNBT( stack );
i.setTag( "crafting", stack );
crafting.writeToNBT(stack);
i.setTag("crafting", stack);
}
}
public void writeToPacket( ByteBuf i ) throws IOException
{
public void writeToPacket(ByteBuf i) throws IOException {
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final DataOutputStream data = new DataOutputStream( bytes );
final DataOutputStream data = new DataOutputStream(bytes);
NBTTagCompound tag = new NBTTagCompound();
this.writeToNBT( tag );
CompressedStreamTools.write( tag, data );
this.writeToNBT(tag);
CompressedStreamTools.write(tag, data);
final byte[] tagBytes = bytes.toByteArray();
final int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
i.writeInt(size);
i.writeBytes(tagBytes);
}
@Nullable
public ICraftingCPU getServerCluster()
{
public ICraftingCPU getServerCluster() {
return serverCluster;
}
public String getName()
{
public String getName() {
return name;
}
public int getSerial()
{
public int getSerial() {
return serial;
}
public long getStorage()
{
public long getStorage() {
return storage;
}
public long getCoprocessors()
{
public long getCoprocessors() {
return coprocessors;
}
public long getTotalItems()
{
public long getTotalItems() {
return totalItems;
}
public long getRemainingItems()
{
public long getRemainingItems() {
return remainingItems;
}
public IAEItemStack getCrafting()
{
public IAEItemStack getCrafting() {
return crafting;
}
@Override
public int compareTo( CraftingCPUStatus o )
{
final int a = ItemSorters.compareLong( o.getCoprocessors(), this.getCoprocessors() );
if( a != 0 )
{
public int compareTo(CraftingCPUStatus o) {
final int a = ItemSorters.compareLong(o.getCoprocessors(), this.getCoprocessors());
if (a != 0) {
return a;
}
return ItemSorters.compareLong( o.getStorage(), this.getStorage() );
return ItemSorters.compareLong(o.getStorage(), this.getStorage());
}
public String formatStorage()
{
public String formatStorage() {
long val = getStorage();
if (val > 4_000_000_000_000L)
{
if (val > 4_000_000_000_000L) {
return String.format("%dT", val / 1024 / 1024 / 1024 / 1024);
}
else if (val > 4_000_000_000L)
{
} else if (val > 4_000_000_000L) {
return String.format("%dG", val / 1024 / 1024 / 1024);
}
else if (val > 4_000_000L)
{
} else if (val > 4_000_000L) {
return String.format("%dM", val / 1024 / 1024);
}
else if (val > 4_000L)
{
} else if (val > 4_000L) {
return String.format("%dk", val / 1024);
}
else
{
return Long.toString( val );
} else {
return Long.toString(val);
}
}
}