pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,15 +18,11 @@
package appeng.container.implementations;
import java.util.Iterator;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.util.EnumCycler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.*;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
@@ -44,242 +40,210 @@ import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.OptionalSlotRestrictedInput;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileCellWorkbench;
import appeng.util.EnumCycler;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperSupplierItemHandler;
import appeng.util.iterators.NullIterator;
public class ContainerCellWorkbench extends ContainerUpgradeable {
public class ContainerCellWorkbench extends ContainerUpgradeable
{
public static ContainerType<ContainerCellWorkbench> TYPE;
public static ContainerType<ContainerCellWorkbench> TYPE;
private static final ContainerHelper<ContainerCellWorkbench, TileCellWorkbench> helper = new ContainerHelper<>(
ContainerCellWorkbench::new, TileCellWorkbench.class);
private static final ContainerHelper<ContainerCellWorkbench, TileCellWorkbench> helper
= new ContainerHelper<>(ContainerCellWorkbench::new, TileCellWorkbench.class);
private final TileCellWorkbench workBench;
@GuiSync(2)
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
private int lastUpgrades = 0;
private final TileCellWorkbench workBench;
@GuiSync( 2 )
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
private int lastUpgrades = 0;
public ContainerCellWorkbench(int id, final PlayerInventory ip, final TileCellWorkbench te) {
super(TYPE, id, ip, te);
this.workBench = te;
}
public ContainerCellWorkbench(int id, final PlayerInventory ip, final TileCellWorkbench te )
{
super( TYPE, id, ip, te );
this.workBench = te;
}
public static ContainerCellWorkbench fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCellWorkbench fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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, EnumCycler.next(this.getWorkBenchCopyMode()));
}
public void nextWorkBenchCopyMode()
{
this.workBench.getConfigManager().putSetting( Settings.COPY_MODE, EnumCycler.next( 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.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8,
this.getPlayerInv()));
@Override
protected void setupConfig()
{
final IItemHandler cell = this.getUpgradeable().getInventoryByName( "cell" );
this.addSlot( 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.addSlot(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.addSlot( 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.addSlot(new OptionalSlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES,
upgradeInventory, this, iSLot, 187 + zz * 18, 8 + 18 * z, iSLot, this.getPlayerInventory()));
}
}
/*
* 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.addSlot(
new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgradeInventory, this, iSLot, 187 + zz * 18, 8 + 18 * z, iSLot, this
.getPlayerInventory() ) );
}
}
/*
* 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 ServerPlayerEntity) {
((ServerPlayerEntity) listener).isChangingQuantityOnly = false;
}
}
}
if( listener instanceof ServerPlayerEntity )
{
( (ServerPlayerEntity) 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;
}
}
@@ -18,44 +18,40 @@
package appeng.container.implementations;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileChest;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileChest;
public class ContainerChest extends AEBaseContainer
{
public class ContainerChest extends AEBaseContainer {
public static ContainerType<ContainerChest> TYPE;
public static ContainerType<ContainerChest> TYPE;
private static final ContainerHelper<ContainerChest, TileChest> helper
= new ContainerHelper<>(ContainerChest::new, TileChest.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerChest, TileChest> helper = new ContainerHelper<>(ContainerChest::new,
TileChest.class, SecurityPermissions.BUILD);
public ContainerChest( int id, final PlayerInventory ip, final TileChest chest )
{
super( TYPE, id, ip, chest, null );
public ContainerChest(int id, final PlayerInventory ip, final TileChest chest) {
super(TYPE, id, ip, chest, null);
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, chest.getInternalInventory(), 1, 80, 37, this
.getPlayerInventory() ) );
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS,
chest.getInternalInventory(), 1, 80, 37, this.getPlayerInventory()));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
public static ContainerChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
}
@@ -18,6 +18,11 @@
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
@@ -30,87 +35,74 @@ import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileCondenser;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
public class ContainerCondenser extends AEBaseContainer implements IProgressProvider {
public class ContainerCondenser extends AEBaseContainer implements IProgressProvider
{
public static ContainerType<ContainerCondenser> TYPE;
public static ContainerType<ContainerCondenser> TYPE;
private static final ContainerHelper<ContainerCondenser, TileCondenser> helper = new ContainerHelper<>(
ContainerCondenser::new, TileCondenser.class);
private static final ContainerHelper<ContainerCondenser, TileCondenser> helper
= new ContainerHelper<>(ContainerCondenser::new, TileCondenser.class);
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 TileCondenser condenser;
@GuiSync( 0 )
public long requiredEnergy = 0;
@GuiSync( 1 )
public long storedPower = 0;
@GuiSync( 2 )
public CondenserOutput output = CondenserOutput.TRASH;
public ContainerCondenser(int id, final PlayerInventory ip, final TileCondenser condenser) {
super(TYPE, id, ip, condenser, null);
this.condenser = condenser;
public ContainerCondenser(int id, final PlayerInventory ip, final TileCondenser condenser )
{
super( TYPE, id, ip, condenser, null );
this.condenser = condenser;
IItemHandler inv = condenser.getInternalInventory();
IItemHandler inv = condenser.getInternalInventory();
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip));
this.addSlot(new SlotOutput(inv, 1, 105, 52, -1));
this.addSlot(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip))
.setStackLimit(1));
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip ) );
this.addSlot( new SlotOutput( inv, 1, 105, 52, -1 ) );
this.addSlot(
( 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 );
}
public static ContainerCondenser fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCondenser fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
final double maxStorage = this.condenser.getStorage();
final double requiredEnergy = this.condenser.getRequiredPower();
@Override
public void detectAndSendChanges()
{
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 ) );
}
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;
}
}
@@ -18,10 +18,8 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -36,72 +34,64 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.SlotInaccessible;
import appeng.me.helpers.PlayerSource;
import appeng.tile.inventory.AppEngInternalInventory;
public class ContainerCraftAmount extends AEBaseContainer {
public class ContainerCraftAmount extends AEBaseContainer
{
public static ContainerType<ContainerCraftAmount> TYPE;
public static ContainerType<ContainerCraftAmount> TYPE;
private static final ContainerHelper<ContainerCraftAmount, ITerminalHost> helper = new ContainerHelper<>(
ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private static final ContainerHelper<ContainerCraftAmount, ITerminalHost> helper
= new ContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private final Slot craftingItem;
private IAEItemStack itemToCreate;
private final Slot craftingItem;
private IAEItemStack itemToCreate;
public ContainerCraftAmount(int id, PlayerInventory ip, final ITerminalHost te) {
super(TYPE, id, ip, te);
public ContainerCraftAmount(int id, PlayerInventory ip, final ITerminalHost te) {
super(TYPE, id, ip, te);
this.craftingItem = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
this.addSlot(this.getCraftingItem());
}
this.craftingItem = new SlotInaccessible( new AppEngInternalInventory( null, 1 ), 0, 34, 53 );
this.addSlot( this.getCraftingItem() );
}
public static ContainerCraftAmount fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCraftAmount fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@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;
}
}
@@ -18,6 +18,23 @@
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 com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -48,446 +65,356 @@ import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartTerminal;
import appeng.util.Platform;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.StringTextComponent;
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
{
public static ContainerType<ContainerCraftConfirm> TYPE;
private static final ContainerHelper<ContainerCraftConfirm, ITerminalHost> helper
= new ContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, PlayerInventory ip, ITerminalHost te) {
super(TYPE, id, 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().getString() );
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;
}
}
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 PlayerEntity )
{
NetworkHandler.instance().sendTo( a, (ServerPlayerEntity) g );
NetworkHandler.instance().sendTo( b, (ServerPlayerEntity) g );
if( c != null )
{
NetworkHandler.instance().sendTo( c, (ServerPlayerEntity) g );
}
}
}
}
catch( final IOException e )
{
// :P
}
}
catch( final Throwable e )
{
this.getPlayerInv().player.sendMessage( new StringTextComponent( "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().getString() );
this.setCpuAvailableBytes( this.cpus.get( this.getSelectedCpu() ).getSize() );
this.setCpuCoProcessors( this.cpus.get( this.getSelectedCpu() ).getProcessors() );
}
}
public void startJob()
{
ContainerType<?> originalGui = null;
final IActionHost ah = this.getActionHost();
if( ah instanceof WirelessTerminalGuiObject)
{
originalGui = ContainerWirelessTerm.TYPE;
}
if( ah instanceof PartTerminal)
{
originalGui = ContainerMEMonitorable.TYPE;
}
if( ah instanceof PartCraftingTerminal)
{
originalGui = ContainerCraftingTerm.TYPE;
}
if( ah instanceof PartPatternTerminal)
{
originalGui = ContainerPatternTerm.TYPE;
}
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.getLocator() != null )
{
ContainerOpener.openContainer(originalGui, getPlayerInventory().player, getLocator());
}
}
}
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 PlayerEntity par1PlayerEntity )
{
super.onContainerClosed( par1PlayerEntity );
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;
}
public class ContainerCraftConfirm extends AEBaseContainer {
public static ContainerType<ContainerCraftConfirm> TYPE;
private static final ContainerHelper<ContainerCraftConfirm, ITerminalHost> helper = new ContainerHelper<>(
ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, PlayerInventory ip, ITerminalHost te) {
super(TYPE, id, 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().getString());
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;
}
}
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 PlayerEntity) {
NetworkHandler.instance().sendTo(a, (ServerPlayerEntity) g);
NetworkHandler.instance().sendTo(b, (ServerPlayerEntity) g);
if (c != null) {
NetworkHandler.instance().sendTo(c, (ServerPlayerEntity) g);
}
}
}
} catch (final IOException e) {
// :P
}
} catch (final Throwable e) {
this.getPlayerInv().player.sendMessage(new StringTextComponent("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().getString());
this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize());
this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors());
}
}
public void startJob() {
ContainerType<?> originalGui = null;
final IActionHost ah = this.getActionHost();
if (ah instanceof WirelessTerminalGuiObject) {
originalGui = ContainerWirelessTerm.TYPE;
}
if (ah instanceof PartTerminal) {
originalGui = ContainerMEMonitorable.TYPE;
}
if (ah instanceof PartCraftingTerminal) {
originalGui = ContainerCraftingTerm.TYPE;
}
if (ah instanceof PartPatternTerminal) {
originalGui = ContainerPatternTerm.TYPE;
}
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.getLocator() != null) {
ContainerOpener.openContainer(originalGui, getPlayerInventory().player, getLocator());
}
}
}
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 PlayerEntity par1PlayerEntity) {
super.onContainerClosed(par1PlayerEntity);
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;
}
}
@@ -18,17 +18,18 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
@@ -40,7 +41,9 @@ import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketValueConfig;
@@ -49,249 +52,205 @@ import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent;
public class ContainerCraftingCPU extends AEBaseContainer
implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject {
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject
{
public static ContainerType<ContainerCraftingCPU> TYPE;
public static ContainerType<ContainerCraftingCPU> TYPE;
private static final ContainerHelper<ContainerCraftingCPU, TileCraftingTile> helper = new ContainerHelper<>(
ContainerCraftingCPU::new, TileCraftingTile.class, SecurityPermissions.CRAFT);
private static final ContainerHelper<ContainerCraftingCPU, TileCraftingTile> helper
= new ContainerHelper<>(ContainerCraftingCPU::new, TileCraftingTile.class, SecurityPermissions.CRAFT);
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
.createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private ITextComponent cpuName = null;
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private ITextComponent cpuName = null;
@GuiSync(0)
public long eta = -1;
@GuiSync( 0 )
public long eta = -1;
private ContainerCraftingCPU(int id, final PlayerInventory ip, final TileCraftingTile te) {
this(TYPE, id, ip, te);
}
private ContainerCraftingCPU(int id, final PlayerInventory ip, final TileCraftingTile te )
{
this( TYPE, id, ip, te );
}
public ContainerCraftingCPU(ContainerType<?> containerType, int id, final PlayerInventory ip, final Object te) {
super(containerType, id, ip, te);
final IActionHost host = (IActionHost) (te instanceof IActionHost ? te : null);
public ContainerCraftingCPU(ContainerType<?> containerType, int id, final PlayerInventory ip, final Object te )
{
super( containerType, id, 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 );
}
}
public static ContainerCraftingCPU fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCraftingCPU fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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 PlayerEntity) {
NetworkHandler.instance().sendTo(new PacketValueConfig("CraftingStatus", "Clear"),
(ServerPlayerEntity) g);
}
}
for( final Object g : this.listeners )
{
if( g instanceof PlayerEntity )
{
NetworkHandler.instance().sendTo( new PacketValueConfig( "CraftingStatus", "Clear" ), (ServerPlayerEntity) g );
}
}
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 = null;
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 = null;
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 PlayerEntity player) {
super.onContainerClosed(player);
if (this.getMonitor() != null) {
this.getMonitor().removeListener(this);
}
}
@Override
public void onContainerClosed( final PlayerEntity player )
{
super.onContainerClosed( player );
if( this.getMonitor() != null )
{
this.getMonitor().removeListener( this );
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer() && this.getMonitor() != null && !this.list.isEmpty()) {
try {
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);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() && this.getMonitor() != null && !this.list.isEmpty() )
{
try
{
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 );
}
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate((byte) 0);
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate((byte) 1);
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate((byte) 2);
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 PlayerEntity) {
if (!a.isEmpty()) {
NetworkHandler.instance().sendTo(a, (ServerPlayerEntity) g);
}
for( final Object g : this.listeners )
{
if( g instanceof PlayerEntity )
{
if( !a.isEmpty() )
{
NetworkHandler.instance().sendTo( a, (ServerPlayerEntity) g );
}
if (!b.isEmpty()) {
NetworkHandler.instance().sendTo(b, (ServerPlayerEntity) g);
}
if( !b.isEmpty() )
{
NetworkHandler.instance().sendTo( b, (ServerPlayerEntity) g );
}
if (!c.isEmpty()) {
NetworkHandler.instance().sendTo(c, (ServerPlayerEntity) g);
}
}
}
} catch (final IOException e) {
// :P
}
}
super.detectAndSendChanges();
}
if( !c.isEmpty() )
{
NetworkHandler.instance().sendTo( c, (ServerPlayerEntity) 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 ITextComponent getCustomInventoryName() {
return this.cpuName;
}
@Override
public ITextComponent getCustomInventoryName()
{
return this.cpuName;
}
@Override
public boolean hasCustomInventoryName() {
return this.cpuName != null;
}
@Override
public boolean hasCustomInventoryName()
{
return this.cpuName != null;
}
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;
}
}
@@ -18,181 +18,146 @@
package appeng.container.implementations;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import appeng.util.Platform;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.util.Platform;
public class ContainerCraftingStatus extends ContainerCraftingCPU
{
public class ContainerCraftingStatus extends ContainerCraftingCPU {
public static ContainerType<ContainerCraftingStatus> TYPE;
public static ContainerType<ContainerCraftingStatus> TYPE;
private static final ContainerHelper<ContainerCraftingStatus, ITerminalHost> helper
= new ContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private static final ContainerHelper<ContainerCraftingStatus, ITerminalHost> helper = new ContainerHelper<>(
ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final List<CraftingCPURecord> cpus = new ArrayList<>();
@GuiSync( 5 )
public int selectedCpu = -1;
@GuiSync( 6 )
public boolean noCPU = true;
@GuiSync( 7 )
public String myName = "";
private final List<CraftingCPURecord> cpus = new ArrayList<>();
@GuiSync(5)
public int selectedCpu = -1;
@GuiSync(6)
public boolean noCPU = true;
@GuiSync(7)
public String myName = "";
public ContainerCraftingStatus(int id, final PlayerInventory ip, final ITerminalHost te )
{
super( TYPE, id, ip, te );
}
public ContainerCraftingStatus(int id, final PlayerInventory ip, final ITerminalHost te) {
super(TYPE, id, ip, te);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() && this.getNetwork() != null )
{
final ICraftingGrid cc = this.getNetwork().getCache( ICraftingGrid.class );
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
@Override
public void detectAndSendChanges() {
if (Platform.isServer() && this.getNetwork() != null) {
final ICraftingGrid cc = this.getNetwork().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;
}
}
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;
}
}
final boolean matched = this.cpuMatches( c );
final boolean matched = this.cpuMatches(c);
if( matched )
{
matches++;
}
if (matched) {
matches++;
}
if( found == !matched )
{
changed = true;
}
}
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 ) );
}
}
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.sendCPUs();
}
this.noCPU = this.cpus.isEmpty();
}
this.noCPU = this.cpus.isEmpty();
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
private boolean cpuMatches( final ICraftingCPU c )
{
return c.isBusy();
}
private boolean cpuMatches(final ICraftingCPU c) {
return c.isBusy();
}
private void sendCPUs()
{
Collections.sort( this.cpus );
private void sendCPUs() {
Collections.sort(this.cpus);
if( this.selectedCpu >= this.cpus.size() )
{
this.selectedCpu = -1;
this.myName = "";
}
else if( this.selectedCpu != -1 )
{
this.myName = this.cpus.get( this.selectedCpu ).getName().getString();
}
if (this.selectedCpu >= this.cpus.size()) {
this.selectedCpu = -1;
this.myName = "";
} else if (this.selectedCpu != -1) {
this.myName = this.cpus.get(this.selectedCpu).getName().getString();
}
if( this.selectedCpu == -1 && this.cpus.size() > 0 )
{
this.selectedCpu = 0;
}
if (this.selectedCpu == -1 && this.cpus.size() > 0) {
this.selectedCpu = 0;
}
if( this.selectedCpu != -1 )
{
if( this.cpus.get( this.selectedCpu ).getCpu() != this.getMonitor() )
{
this.setCPU( this.cpus.get( this.selectedCpu ).getCpu() );
}
}
else
{
this.setCPU( null );
}
}
if (this.selectedCpu != -1) {
if (this.cpus.get(this.selectedCpu).getCpu() != this.getMonitor()) {
this.setCPU(this.cpus.get(this.selectedCpu).getCpu());
}
} else {
this.setCPU(null);
}
}
public void cycleCpu( final boolean next )
{
if( next )
{
this.selectedCpu++;
}
else
{
this.selectedCpu--;
}
public void cycleCpu(final boolean next) {
if (next) {
this.selectedCpu++;
} else {
this.selectedCpu--;
}
if( this.selectedCpu < -1 )
{
this.selectedCpu = this.cpus.size() - 1;
}
else if( this.selectedCpu >= this.cpus.size() )
{
this.selectedCpu = -1;
}
if (this.selectedCpu < -1) {
this.selectedCpu = this.cpus.size() - 1;
} else if (this.selectedCpu >= this.cpus.size()) {
this.selectedCpu = -1;
}
if( this.selectedCpu == -1 && this.cpus.size() > 0 )
{
this.selectedCpu = 0;
}
if (this.selectedCpu == -1 && this.cpus.size() > 0) {
this.selectedCpu = 0;
}
if( this.selectedCpu == -1 )
{
this.myName = "";
this.setCPU( null );
}
else
{
this.myName = this.cpus.get( this.selectedCpu ).getName().getString();
this.setCPU( this.cpus.get( this.selectedCpu ).getCpu() );
}
}
if (this.selectedCpu == -1) {
this.myName = "";
this.setCPU(null);
} else {
this.myName = this.cpus.get(this.selectedCpu).getName().getString();
this.setCPU(this.cpus.get(this.selectedCpu).getCpu());
}
}
}
@@ -18,13 +18,10 @@
package appeng.container.implementations;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
@@ -34,7 +31,9 @@ import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerLocator;
import appeng.container.ContainerNull;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotCraftingTerm;
@@ -45,115 +44,101 @@ import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperInvItemHandler;
public class ContainerCraftingTerm extends ContainerMEMonitorable
implements IAEAppEngInventory, IContainerCraftingPacket {
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket
{
public static ContainerType<ContainerCraftingTerm> TYPE;
public static ContainerType<ContainerCraftingTerm> TYPE;
private static final ContainerHelper<ContainerCraftingTerm, ITerminalHost> helper = new ContainerHelper<>(
ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private static final ContainerHelper<ContainerCraftingTerm, ITerminalHost> helper
= new ContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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<CraftingInventory> 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<CraftingInventory> currentRecipe;
public ContainerCraftingTerm(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
super(TYPE, id, ip, monitorable, false);
this.ct = (PartCraftingTerminal) monitorable;
public ContainerCraftingTerm(int id, final PlayerInventory ip, final ITerminalHost monitorable )
{
super( TYPE, id, 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.addSlot(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.addSlot( this.craftingSlots[x + y * 3] = new SlotCraftingMatrix( this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18 ) );
}
}
this.addSlot(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(),
this.getPowerSource(), monitorable, crafting, crafting, this.output, 131, -72 + 18, this));
this.addSlot( 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 CraftingInventory ic = new CraftingInventory(cn, 3, 3);
@Override
public void onCraftMatrixChanged( IInventory inventory )
{
final ContainerNull cn = new ContainerNull();
final CraftingInventory ic = new CraftingInventory( 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)) {
World world = this.getPlayerInv().player.world;
this.currentRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, ic, world).orElse(null);
}
if( this.currentRecipe == null || !this.currentRecipe.matches( ic, this.getPlayerInv().player.world ) )
{
World world = this.getPlayerInv().player.world;
this.currentRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, ic, world).orElse(null);
}
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.getPlayerInventory());
}
return this.ct.getInventoryByName(name);
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return new PlayerInvWrapper( this.getPlayerInventory() );
}
return this.ct.getInventoryByName( name );
}
@Override
public boolean useRealItems() {
return true;
}
@Override
public boolean useRealItems()
{
return true;
}
public IRecipe<CraftingInventory> getCurrentRecipe()
{
return this.currentRecipe;
}
public IRecipe<CraftingInventory> getCurrentRecipe() {
return this.currentRecipe;
}
}
@@ -18,49 +18,43 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileDrive;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileDrive;
public class ContainerDrive extends AEBaseContainer
{
public class ContainerDrive extends AEBaseContainer {
public static ContainerType<ContainerDrive> TYPE;
public static ContainerType<ContainerDrive> TYPE;
private static final ContainerHelper<ContainerDrive, TileDrive> helper
= new ContainerHelper<>(ContainerDrive::new, TileDrive.class);
private static final ContainerHelper<ContainerDrive, TileDrive> helper = new ContainerHelper<>(ContainerDrive::new,
TileDrive.class);
public static ContainerDrive fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerDrive fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public ContainerDrive(int id, final PlayerInventory ip, final TileDrive drive )
{
super( TYPE, id, ip, drive, null );
public ContainerDrive(int id, final PlayerInventory ip, final TileDrive drive) {
super(TYPE, id, ip, drive, null);
for( int y = 0; y < 5; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive
.getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getPlayerInventory() ) );
}
}
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 2; x++) {
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS,
drive.getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getPlayerInventory()));
}
}
this.bindPlayerInventory( ip, 0, 199 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 199 - /* height of player inventory */82);
}
}
@@ -18,9 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -32,124 +29,105 @@ import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartFormationPlane;
import appeng.util.Platform;
public class ContainerFormationPlane extends ContainerUpgradeable {
public class ContainerFormationPlane extends ContainerUpgradeable
{
public static ContainerType<ContainerFormationPlane> TYPE;
public static ContainerType<ContainerFormationPlane> TYPE;
private static final ContainerHelper<ContainerFormationPlane, PartFormationPlane> helper = new ContainerHelper<>(
ContainerFormationPlane::new, PartFormationPlane.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerFormationPlane, PartFormationPlane> helper
= new ContainerHelper<>(ContainerFormationPlane::new, PartFormationPlane.class, SecurityPermissions.BUILD);
public static ContainerFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@GuiSync(6)
public YesNo placeMode;
@GuiSync( 6 )
public YesNo placeMode;
public ContainerFormationPlane(int id, final PlayerInventory ip, final PartFormationPlane te) {
super(TYPE, id, ip, te);
}
public ContainerFormationPlane(int id, final PlayerInventory ip, final PartFormationPlane te )
{
super( TYPE, id, 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.addSlot(new SlotFakeTypeOnly(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlot(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.addSlot( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
}
else
{
this.addSlot( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getPlayerInventory() ) )
.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;
}
}
@@ -18,9 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -28,44 +25,47 @@ import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotInaccessible;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.grindstone.TileGrinder;
public class ContainerGrinder extends AEBaseContainer
{
public class ContainerGrinder extends AEBaseContainer {
public static ContainerType<ContainerGrinder> TYPE;
public static ContainerType<ContainerGrinder> TYPE;
private static final ContainerHelper<ContainerGrinder, TileGrinder> helper
= new ContainerHelper<>(ContainerGrinder::new, TileGrinder.class);
private static final ContainerHelper<ContainerGrinder, TileGrinder> helper = new ContainerHelper<>(
ContainerGrinder::new, TileGrinder.class);
public static ContainerGrinder fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerGrinder fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public ContainerGrinder(int id, final PlayerInventory ip, final TileGrinder grinder )
{
super( TYPE, id, ip, grinder, null );
public ContainerGrinder(int id, final PlayerInventory ip, final TileGrinder grinder) {
super(TYPE, id, ip, grinder, null);
IItemHandler inv = grinder.getInternalInventory();
IItemHandler inv = grinder.getInternalInventory();
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17, this.getPlayerInventory() ) );
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17, this.getPlayerInventory() ) );
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17, this.getPlayerInventory() ) );
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17,
this.getPlayerInventory()));
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17,
this.getPlayerInventory()));
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17,
this.getPlayerInventory()));
this.addSlot( new SlotInaccessible( inv, 6, 80, 40 ) );
this.addSlot(new SlotInaccessible(inv, 6, 80, 40));
this.addSlot( new SlotOutput( inv, 3, 112, 63, 2 * 16 + 15 ) );
this.addSlot( new SlotOutput( inv, 4, 112 + 18, 63, 2 * 16 + 15 ) );
this.addSlot( new SlotOutput( inv, 5, 112 + 36, 63, 2 * 16 + 15 ) );
this.addSlot(new SlotOutput(inv, 3, 112, 63, 2 * 16 + 15));
this.addSlot(new SlotOutput(inv, 4, 112 + 18, 63, 2 * 16 + 15));
this.addSlot(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);
}
}
@@ -1,18 +1,5 @@
package appeng.container.implementations;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.core.AELog;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
@@ -27,9 +14,23 @@ import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.core.AELog;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
/**
* Helper for containers that can be opened for a part <em>or</em> tile given that either
* implements a given interface.
* Helper for containers that can be opened for a part <em>or</em> tile given
* that either implements a given interface.
*
* @param <C>
*/
@@ -45,15 +46,16 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
this(factory, interfaceClass, null);
}
public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) {
public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass,
SecurityPermissions requiredPermission) {
this.requiredPermission = requiredPermission;
this.interfaceClass = interfaceClass;
this.factory = factory;
}
/**
* Opens a container that is based around a single tile entity.
* The tile entity's position is encoded in the packet buffer.
* Opens a container that is based around a single tile entity. The tile
* entity's position is encoded in the packet buffer.
*/
public C fromNetwork(int windowId, PlayerInventory inv, PacketBuffer packetBuf) {
I host = getHostFromLocator(inv.player, ContainerLocator.read(packetBuf));
@@ -82,15 +84,13 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
ITextComponent title = findContainerTitle(player.world, locator, accessInterface);
INamedContainerProvider container = new SimpleNamedContainerProvider(
(wnd, p, pl) -> {
C c = factory.create(wnd, p, accessInterface);
// Set the original locator on the opened server-side container for it to more
// easily remember how to re-open after being closed.
c.setLocator(locator);
return c;
}, title
);
INamedContainerProvider container = new SimpleNamedContainerProvider((wnd, p, pl) -> {
C c = factory.create(wnd, p, accessInterface);
// Set the original locator on the opened server-side container for it to more
// easily remember how to re-open after being closed.
c.setLocator(locator);
return c;
}, title);
NetworkHooks.openGui((ServerPlayerEntity) player, container, locator::write);
return true;
@@ -106,8 +106,10 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
}
// Use block name at position
// FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl
// FIXME: Should move this up, because at this point, it's hard to know where the terminal host came from (part or tile)
// FIXME: this is not right, we'd need to check the part's item stack, or custom
// naming interface impl
// FIXME: Should move this up, because at this point, it's hard to know where
// the terminal host came from (part or tile)
if (locator.hasBlockPos()) {
return world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
}
@@ -147,8 +149,8 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
if (interfaceClass.isInstance(part)) {
return interfaceClass.cast(part);
} else {
AELog.debug("Trying to open a container @ %s for a %s, but the container requires %s",
locator, part.getClass(), interfaceClass);
AELog.debug("Trying to open a container @ %s for a %s, but the container requires %s", locator,
part.getClass(), interfaceClass);
return null;
}
} else {
@@ -162,13 +164,12 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
ItemStack it = player.inventory.getStackInSlot(locator.getItemIndex());
if (it.isEmpty()) {
AELog.debug("Cannot open container for player %s since they no longer hold the item in slot %d",
player, locator.hasItemIndex());
AELog.debug("Cannot open container for player %s since they no longer hold the item in slot %d", player,
locator.hasItemIndex());
return null;
}
if ( it.getItem() instanceof IGuiItem )
{
if (it.getItem() instanceof IGuiItem) {
IGuiItem guiItem = (IGuiItem) it.getItem();
// Optionally contains the block the item was used on to open the container
BlockPos blockPos = locator.hasBlockPos() ? locator.getBlockPos() : null;
@@ -178,10 +179,9 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
}
}
if( interfaceClass.isAssignableFrom(WirelessTerminalGuiObject.class) )
{
final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
if ( wh != null) {
if (interfaceClass.isAssignableFrom(WirelessTerminalGuiObject.class)) {
final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(it);
if (wh != null) {
return interfaceClass.cast(new WirelessTerminalGuiObject(wh, it, player, locator.getItemIndex()));
}
}
@@ -196,8 +196,7 @@ public final class ContainerHelper<C extends AEBaseContainer, I> {
private boolean checkPermission(PlayerEntity player, Object accessInterface) {
if (requiredPermission != null)
{
if (requiredPermission != null) {
return Platform.checkPermissions(player, accessInterface, requiredPermission, true);
}
@@ -18,9 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -32,129 +29,114 @@ import appeng.api.config.OperationMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileIOPort;
import appeng.util.Platform;
public class ContainerIOPort extends ContainerUpgradeable {
public class ContainerIOPort extends ContainerUpgradeable
{
public static ContainerType<ContainerIOPort> TYPE;
public static ContainerType<ContainerIOPort> TYPE;
private static final ContainerHelper<ContainerIOPort, TileIOPort> helper = new ContainerHelper<>(
ContainerIOPort::new, TileIOPort.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerIOPort, TileIOPort> helper
= new ContainerHelper<>(ContainerIOPort::new, TileIOPort.class, SecurityPermissions.BUILD);
public static ContainerIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@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(int id, final PlayerInventory ip, final TileIOPort te) {
super(TYPE, id, ip, te);
}
public ContainerIOPort(int id, final PlayerInventory ip, final TileIOPort te )
{
super( TYPE, id, 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.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, cells,
x + y * 2, offX + x * 18, offY + y * 18, this.getPlayerInventory()));
}
}
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 2; x++ )
{
this.addSlot(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, cells, x + y * 2, offX + x * 18, offY + y * 18, this
.getPlayerInventory() ) );
}
}
offX = 122;
offY = 17;
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 2; x++) {
this.addSlot(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.addSlot(
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.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.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;
}
}
@@ -18,6 +18,13 @@
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
@@ -30,14 +37,6 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.InscriberRecipes;
import appeng.tile.misc.TileInscriber;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
/**
* @author AlgorithmX2
@@ -45,139 +44,128 @@ import net.minecraftforge.items.IItemHandler;
* @version rv2
* @since rv0
*/
public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider
{
public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider {
public static ContainerType<ContainerInscriber> TYPE;
public static ContainerType<ContainerInscriber> TYPE;
private static final ContainerHelper<ContainerInscriber, TileInscriber> helper
= new ContainerHelper<>(ContainerInscriber::new, TileInscriber.class);
private static final ContainerHelper<ContainerInscriber, TileInscriber> helper = new ContainerHelper<>(
ContainerInscriber::new, TileInscriber.class);
public static ContainerInscriber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerInscriber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final TileInscriber te )
{
super( TYPE, id, ip, te );
this.ti = te;
public ContainerInscriber(int id, final PlayerInventory ip, final TileInscriber te) {
super(TYPE, id, ip, te);
this.ti = te;
IItemHandler inv = te.getInternalInventory();
IItemHandler inv = te.getInternalInventory();
SlotRestrictedInput top = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0, 45, 16, this.getPlayerInventory());
top.setStackLimit(1);
this.top = this.addSlot(top);
SlotRestrictedInput bottom = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 1, 45, 62, this.getPlayerInventory());
bottom.setStackLimit(1);
this.bottom = this.addSlot(bottom);
SlotRestrictedInput middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv, 2, 63, 39, this.getPlayerInventory() );
middle.setStackLimit(1);
this.middle = this.addSlot(middle);
SlotRestrictedInput top = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0,
45, 16, this.getPlayerInventory());
top.setStackLimit(1);
this.top = this.addSlot(top);
SlotRestrictedInput bottom = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv,
1, 45, 62, this.getPlayerInventory());
bottom.setStackLimit(1);
this.bottom = this.addSlot(bottom);
SlotRestrictedInput middle = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv,
2, 63, 39, this.getPlayerInventory());
middle.setStackLimit(1);
this.middle = this.addSlot(middle);
this.addSlot( new SlotOutput( inv, 3, 113, 40, -1 ) );
}
this.addSlot(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);
}
return InscriberRecipes.findRecipe(ti.getWorld(), is, top, bot, false) != null;
}
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();
}
return InscriberRecipes.findRecipe(ti.getWorld(), is, top, bot, false) != null;
} 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
// test for a partial recipe match (ignoring the middle slot)
return InscriberRecipes.isValidOptionalIngredientCombination(ti.getWorld(), is, otherSlot);
}
return true;
}
// everything else
// test for a partial recipe match (ignoring the middle slot)
return InscriberRecipes.isValidOptionalIngredientCombination(ti.getWorld(), is, otherSlot);
}
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;
}
}
@@ -18,121 +18,105 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.util.IConfigManager;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotFake;
import appeng.container.slot.SlotNormal;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
public class ContainerInterface extends ContainerUpgradeable {
public class ContainerInterface extends ContainerUpgradeable
{
public static ContainerType<ContainerInterface> TYPE;
public static ContainerType<ContainerInterface> TYPE;
private static final ContainerHelper<ContainerInterface, IInterfaceHost> helper = new ContainerHelper<>(
ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerInterface, IInterfaceHost> helper
= new ContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD);
public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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;
public ContainerInterface(int id, final PlayerInventory ip, final IInterfaceHost te) {
super(TYPE, id, ip, te.getInterfaceDuality().getHost());
public ContainerInterface(int id, final PlayerInventory ip, final IInterfaceHost te )
{
super( TYPE, id, ip, te.getInterfaceDuality().getHost() );
this.myDuality = te.getInterfaceDuality();
this.myDuality = te.getInterfaceDuality();
for (int x = 0; x < DualityInterface.NUMBER_OF_PATTERN_SLOTS; x++) {
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN,
this.myDuality.getPatterns(), x, 8 + 18 * x, 90 + 7, this.getPlayerInventory()));
}
for( int x = 0; x < DualityInterface.NUMBER_OF_PATTERN_SLOTS; x++ )
{
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, this.myDuality
.getPatterns(), x, 8 + 18 * x, 90 + 7, this.getPlayerInventory() ) );
}
for (int x = 0; x < DualityInterface.NUMBER_OF_CONFIG_SLOTS; x++) {
this.addSlot(new SlotFake(this.myDuality.getConfig(), x, 8 + 18 * x, 35));
}
for( int x = 0; x < DualityInterface.NUMBER_OF_CONFIG_SLOTS; x++ )
{
this.addSlot( new SlotFake( this.myDuality.getConfig(), x, 8 + 18 * x, 35 ) );
}
for (int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++) {
this.addSlot(new SlotNormal(this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18));
}
}
for( int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++ )
{
this.addSlot( new SlotNormal( this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18 ) );
}
}
@Override
protected int getHeight() {
return 211;
}
@Override
protected int getHeight()
{
return 211;
}
@Override
protected void setupConfig() {
this.setupUpgrades();
}
@Override
protected void setupConfig()
{
this.setupUpgrades();
}
@Override
public int availableUpgrades() {
return 1;
}
@Override
public int availableUpgrades()
{
return 1;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
super.detectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
super.detectAndSendChanges();
}
@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;
}
}
@@ -18,29 +18,28 @@
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.SecurityPermissions;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.helpers.DualityInterface;
@@ -60,394 +59,325 @@ import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.WrapperRangeItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public final class ContainerInterfaceTerminal extends AEBaseContainer
{
public static ContainerType<ContainerInterfaceTerminal> TYPE;
private static final ContainerHelper<ContainerInterfaceTerminal, PartInterfaceTerminal> helper
= new ContainerHelper<>(ContainerInterfaceTerminal::new, PartInterfaceTerminal.class, SecurityPermissions.BUILD);
public static ContainerInterfaceTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
/**
* 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 CompoundNBT data = new CompoundNBT();
public ContainerInterfaceTerminal(int id, final PlayerInventory ip, final PartInterfaceTerminal anchor )
{
super( TYPE, id, ip, anchor );
if( Platform.isServer() )
{
this.grid = anchor.getActionableNode().getGrid();
}
this.bindPlayerInventory( ip, 0, 222 - /* height of player inventory */82 );
}
@Override
public void detectAndSendChanges()
{
if( Platform.isClient() )
{
return;
}
super.detectAndSendChanges();
if( this.grid == null )
{
return;
}
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 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;
}
}
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;
}
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;
}
}
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( !this.data.isEmpty() )
{
try
{
NetworkHandler.instance().sendTo( new PacketCompressedNBT( this.data ), (ServerPlayerEntity) this.getPlayerInv().player );
}
catch( final IOException e )
{
// :P
}
this.data = new CompoundNBT();
}
}
@Override
public void doAction( final ServerPlayerEntity 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 IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
switch( action )
{
case PICKUP_OR_SET_DOWN:
if( hasItemInHand )
{
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 );
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 ) ) );
}
break;
case SPLIT_OR_PLACE_SINGLE:
if( hasItemInHand )
{
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
if( !extra.isEmpty() )
{
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:
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player );
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) );
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 ) ) );
}
break;
case CREATIVE_DUPLICATE:
if( player.abilities.isCreativeMode && !hasItemInHand )
{
player.inventory.setItemStack( is.isEmpty() ? ItemStack.EMPTY : is.copy() );
}
break;
default:
return;
}
this.updateHeld( player );
}
}
private void regenList( final CompoundNBT 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().getString() ) );
}
}
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().getString() ) );
}
}
}
}
data.putBoolean("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() );
}
}
private boolean isDifferent( final ItemStack a, final ItemStack b )
{
if( a.isEmpty() && b.isEmpty() )
{
return false;
}
if( a.isEmpty() || b.isEmpty() )
{
return true;
}
return !ItemStack.areItemStacksEqual( a, b );
}
private void addItems( final CompoundNBT data, final InvTracker inv, final int offset, final int length )
{
final String name = '=' + Long.toString( inv.which, Character.MAX_RADIX );
final CompoundNBT tag = data.getCompound( name );
if( tag.isEmpty() )
{
tag.putLong( "sortBy", inv.sortBy );
tag.putString("un", inv.unlocalizedName);
}
for( int x = 0; x < length; x++ )
{
final CompoundNBT itemNBT = new CompoundNBT();
final ItemStack is = inv.server.getStackInSlot( x + offset );
// "update" client side.
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
if( !is.isEmpty() )
{
is.write(itemNBT);
}
tag.put( Integer.toString( x + offset ), itemNBT );
}
data.put( name, tag );
}
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;
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();
}
}
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;
}
}
public final class ContainerInterfaceTerminal extends AEBaseContainer {
public static ContainerType<ContainerInterfaceTerminal> TYPE;
private static final ContainerHelper<ContainerInterfaceTerminal, PartInterfaceTerminal> helper = new ContainerHelper<>(
ContainerInterfaceTerminal::new, PartInterfaceTerminal.class, SecurityPermissions.BUILD);
public static ContainerInterfaceTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
/**
* 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 CompoundNBT data = new CompoundNBT();
public ContainerInterfaceTerminal(int id, final PlayerInventory ip, final PartInterfaceTerminal anchor) {
super(TYPE, id, ip, anchor);
if (Platform.isServer()) {
this.grid = anchor.getActionableNode().getGrid();
}
this.bindPlayerInventory(ip, 0, 222 - /* height of player inventory */82);
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
super.detectAndSendChanges();
if (this.grid == null) {
return;
}
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 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;
}
}
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;
}
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;
}
}
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 (!this.data.isEmpty()) {
try {
NetworkHandler.instance().sendTo(new PacketCompressedNBT(this.data),
(ServerPlayerEntity) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
this.data = new CompoundNBT();
}
}
@Override
public void doAction(final ServerPlayerEntity 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 IItemHandler theSlot = new WrapperFilteredItemHandler(
new WrapperRangeItemHandler(inv.server, slot, slot + 1), new PatternSlotFilter());
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler(theSlot);
switch (action) {
case PICKUP_OR_SET_DOWN:
if (hasItemInHand) {
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);
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)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
if (hasItemInHand) {
ItemStack extra = playerHand.removeItems(1, ItemStack.EMPTY, null);
if (!extra.isEmpty()) {
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:
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player);
ItemHandlerUtil.setStackInSlot(theSlot, 0, playerInv.addItems(theSlot.getStackInSlot(0)));
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)));
}
break;
case CREATIVE_DUPLICATE:
if (player.abilities.isCreativeMode && !hasItemInHand) {
player.inventory.setItemStack(is.isEmpty() ? ItemStack.EMPTY : is.copy());
}
break;
default:
return;
}
this.updateHeld(player);
}
}
private void regenList(final CompoundNBT 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().getString()));
}
}
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().getString()));
}
}
}
}
data.putBoolean("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());
}
}
private boolean isDifferent(final ItemStack a, final ItemStack b) {
if (a.isEmpty() && b.isEmpty()) {
return false;
}
if (a.isEmpty() || b.isEmpty()) {
return true;
}
return !ItemStack.areItemStacksEqual(a, b);
}
private void addItems(final CompoundNBT data, final InvTracker inv, final int offset, final int length) {
final String name = '=' + Long.toString(inv.which, Character.MAX_RADIX);
final CompoundNBT tag = data.getCompound(name);
if (tag.isEmpty()) {
tag.putLong("sortBy", inv.sortBy);
tag.putString("un", inv.unlocalizedName);
}
for (int x = 0; x < length; x++) {
final CompoundNBT itemNBT = new CompoundNBT();
final ItemStack is = inv.server.getStackInSlot(x + offset);
// "update" client side.
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if (!is.isEmpty()) {
is.write(itemNBT);
}
tag.put(Integer.toString(x + offset), itemNBT);
}
data.put(name, tag);
}
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;
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();
}
}
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;
}
}
}
@@ -18,8 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -35,155 +33,133 @@ import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.container.ContainerLocator;
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
{
public static ContainerType<ContainerLevelEmitter> TYPE;
public static ContainerType<ContainerLevelEmitter> TYPE;
private static final ContainerHelper<ContainerLevelEmitter, PartLevelEmitter> helper = new ContainerHelper<>(
ContainerLevelEmitter::new, PartLevelEmitter.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerLevelEmitter, PartLevelEmitter> helper
= new ContainerHelper<>(ContainerLevelEmitter::new, PartLevelEmitter.class, SecurityPermissions.BUILD);
public static ContainerLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartLevelEmitter lvlEmitter;
private final PartLevelEmitter lvlEmitter;
@OnlyIn(Dist.CLIENT)
private TextFieldWidget textField;
@GuiSync(2)
public LevelType lvType;
@GuiSync(3)
public long EmitterValue = -1;
@GuiSync(4)
public YesNo cmType;
@OnlyIn( Dist.CLIENT )
private TextFieldWidget textField;
@GuiSync( 2 )
public LevelType lvType;
@GuiSync( 3 )
public long EmitterValue = -1;
@GuiSync( 4 )
public YesNo cmType;
public ContainerLevelEmitter(int id, final PlayerInventory ip, final PartLevelEmitter te) {
super(TYPE, id, ip, te);
this.lvlEmitter = te;
}
public ContainerLevelEmitter( int id, final PlayerInventory ip, final PartLevelEmitter te )
{
super( TYPE, id, ip, te );
this.lvlEmitter = te;
}
@OnlyIn(Dist.CLIENT)
public void setTextField(final TextFieldWidget level) {
this.textField = level;
this.textField.setText(String.valueOf(this.EmitterValue));
}
@OnlyIn( Dist.CLIENT )
public void setTextField( final TextFieldWidget level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
public void setLevel(final long l, final PlayerEntity player) {
this.lvlEmitter.setReportingValue(l);
this.EmitterValue = l;
}
public void setLevel( final long l, final PlayerEntity player )
{
this.lvlEmitter.setReportingValue( l );
this.EmitterValue = l;
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
if (this.availableUpgrades() > 0) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187,
8 + 18, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected void setupConfig()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 1 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 2 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 3 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
}
final IItemHandler inv = this.getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80 + 44;
this.addSlot(new SlotFakeTypeOnly(inv, 0, x, y));
}
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80 + 44;
this.addSlot( 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;
}
}
@@ -18,6 +18,13 @@
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
@@ -33,152 +40,125 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider {
public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider
{
public static ContainerType<ContainerMAC> TYPE;
public static ContainerType<ContainerMAC> TYPE;
private static final ContainerHelper<ContainerMAC, TileMolecularAssembler> helper = new ContainerHelper<>(
ContainerMAC::new, TileMolecularAssembler.class);
private static final ContainerHelper<ContainerMAC, TileMolecularAssembler> helper
= new ContainerHelper<>(ContainerMAC::new, TileMolecularAssembler.class);
public static ContainerMAC fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerMAC fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final TileMolecularAssembler te) {
super(TYPE, id, ip, te);
this.tma = te;
}
public ContainerMAC(int id, final PlayerInventory ip, final TileMolecularAssembler te )
{
super( TYPE, id, 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.addSlot(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.addSlot( s );
}
}
offX = 126;
offY = 16;
offX = 126;
offY = 16;
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10,
offX, offY, this.getPlayerInventory()));
this.addSlot(new SlotOutput(mac, 9, offX, offY + 32, -1));
this.addSlot(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10, offX, offY, this.getPlayerInventory() ) );
this.addSlot( new SlotOutput( mac, 9, offX, offY + 32, -1 ) );
offX = 122;
offY = 17;
offX = 122;
offY = 17;
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getPlayerInventory() ) )
.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;
}
}
@@ -18,17 +18,14 @@
package appeng.container.implementations;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
@@ -43,6 +40,7 @@ import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
@@ -65,6 +63,7 @@ import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
@@ -76,403 +75,320 @@ import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class ContainerMEMonitorable extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {
public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack>
{
public static ContainerType<ContainerMEMonitorable> TYPE;
public static ContainerType<ContainerMEMonitorable> TYPE;
private static final ContainerHelper<ContainerMEMonitorable, ITerminalHost> helper = new ContainerHelper<>(
ContainerMEMonitorable::new, ITerminalHost.class);
private static final ContainerHelper<ContainerMEMonitorable, ITerminalHost> helper
= new ContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class);
public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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;
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;
public ContainerMEMonitorable(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
this(TYPE, id, ip, monitorable, true);
}
public ContainerMEMonitorable( int id, final PlayerInventory ip, final ITerminalHost monitorable )
{
this( TYPE, id, ip, monitorable, true );
}
public ContainerMEMonitorable(ContainerType<?> containerType, int id, PlayerInventory ip,
final ITerminalHost monitorable, final boolean bindInventory) {
super(containerType, id, ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null,
monitorable instanceof IGuiItemObject ? (IGuiItemObject) monitorable : null);
public ContainerMEMonitorable(ContainerType<?> containerType, int id, PlayerInventory ip, final ITerminalHost monitorable, final boolean bindInventory ) {
super( containerType,
id,
ip,
monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null,
monitorable instanceof IGuiItemObject ? (IGuiItemObject) monitorable : null);
this.host = monitorable;
this.clientCM = new ConfigManager(this);
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);
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 (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
if( Platform.isServer() )
{
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (this.monitor != null) {
this.monitor.addListener(this, null);
this.monitor = monitorable.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( this.monitor != null )
{
this.monitor.addListener( this, null );
this.setCellInventory(this.monitor);
this.setCellInventory( this.monitor );
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( 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 (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;
}
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;
}
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,
this.getPlayerInventory());
this.cellView[y].setAllowEdit(this.canAccessViewCells);
this.addSlot(this.cellView[y]);
}
}
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, this.getPlayerInventory() );
this.cellView[y].setAllowEdit( this.canAccessViewCells );
this.addSlot( this.cellView[y] );
}
}
if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0);
}
}
if( bindInventory )
{
this.bindPlayerInventory( ip, 0, 0 );
}
}
public IGridNode getNetworkNode() {
return this.networkNode;
}
public IGridNode getNetworkNode()
{
return this.networkNode;
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.host
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))) {
this.setValidContainer(false);
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() )
{
if( this.monitor != this.host.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) )
{
this.setValidContainer( false );
}
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
for( final Settings set : this.serverCM.getSettings() )
{
final Enum<?> sideLocal = this.serverCM.getSetting( set );
final Enum<?> sideRemote = this.clientCM.getSetting( set );
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final IContainerListener crafter : this.listeners) {
if (crafter instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()),
(ServerPlayerEntity) crafter);
}
}
}
}
if( sideLocal != sideRemote )
{
this.clientCM.putSetting( set, sideLocal );
for( final IContainerListener crafter : this.listeners )
{
if( crafter instanceof ServerPlayerEntity )
{
NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter );
}
}
}
}
if (!this.items.isEmpty()) {
try {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
if( !this.items.isEmpty() )
{
try
{
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
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);
}
}
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 (!piu.isEmpty()) {
this.items.resetStatus();
if( !piu.isEmpty() )
{
this.items.resetStatus();
for (final Object c : this.listeners) {
if (c instanceof PlayerEntity) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
}
}
}
} catch (final IOException e) {
AELog.debug(e);
}
}
for( final Object c : this.listeners )
{
if( c instanceof PlayerEntity )
{
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
}
}
}
}
catch( final IOException e )
{
AELog.debug( e );
}
}
this.updatePowerStatus();
this.updatePowerStatus();
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);
}
}
}
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 );
}
}
}
super.detectAndSendChanges();
}
super.detectAndSendChanges();
}
}
}
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
}
}
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
}
}
@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);
}
}
}
@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.onUpdate(field, oldValue, newValue);
}
super.onUpdate( field, oldValue, newValue );
}
@Override
public void addListener(final IContainerListener c) {
super.addListener(c);
@Override
public void addListener( final IContainerListener c )
{
super.addListener( c );
this.queueInventory(c);
}
this.queueInventory( c );
}
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof PlayerEntity && this.monitor != null) {
try {
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
private void queueInventory( final IContainerListener c )
{
if( Platform.isServer() && c instanceof PlayerEntity && this.monitor != null )
{
try
{
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for (final IAEItemStack send : monitorCache) {
try {
piu.appendItem(send);
} catch (final BufferOverflowException boe) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
for( final IAEItemStack send : monitorCache )
{
try
{
piu.appendItem( send );
}
catch( final BufferOverflowException boe )
{
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
piu = new PacketMEInventoryUpdate();
piu.appendItem(send);
}
}
piu = new PacketMEInventoryUpdate();
piu.appendItem( send );
}
}
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
@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.monitor != null) {
this.monitor.removeListener(this);
}
}
if( this.listeners.isEmpty() && this.monitor != null )
{
this.monitor.removeListener( this );
}
}
@Override
public void onContainerClosed(final PlayerEntity player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
@Override
public void onContainerClosed( final PlayerEntity player )
{
super.onContainerClosed( player );
if( this.monitor != null )
{
this.monitor.removeListener( this );
}
}
@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 source) {
for (final IAEItemStack is : change) {
this.items.add(is);
}
}
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
{
for( final IAEItemStack is : change )
{
this.items.add( is );
}
}
@Override
public void onListUpdate() {
for (final IContainerListener c : this.listeners) {
this.queueInventory(c);
}
}
@Override
public void onListUpdate()
{
for( final IContainerListener c : this.listeners )
{
this.queueInventory( c );
}
}
@Override
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
@Override
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
@Override
public IConfigManager getConfigManager()
{
if( Platform.isServer() )
{
return this.serverCM;
}
return this.clientCM;
}
public ItemStack[] getViewCells() {
final ItemStack[] list = new ItemStack[this.cellView.length];
public ItemStack[] getViewCells()
{
final ItemStack[] list = new ItemStack[this.cellView.length];
for (int x = 0; x < this.cellView.length; x++) {
list[x] = this.cellView[x].getStack();
}
for( int x = 0; x < this.cellView.length; x++ )
{
list[x] = this.cellView[x].getStack();
}
return list;
}
return list;
}
public SlotRestrictedInput getCellViewSlot(final int index) {
return this.cellView[index];
}
public SlotRestrictedInput getCellViewSlot( final int index )
{
return this.cellView[index];
}
public boolean isPowered() {
return this.hasPower;
}
public boolean isPowered()
{
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
private void setPowered( final boolean isPowered )
{
this.hasPower = isPowered;
}
private IConfigManagerHost getGui() {
return this.gui;
}
private IConfigManagerHost getGui()
{
return this.gui;
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
}
@@ -18,103 +18,88 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.container.ContainerLocator;
import appeng.container.interfaces.IInventorySlotAware;
import net.minecraft.network.PacketBuffer;
public class ContainerMEPortableCell extends ContainerMEMonitorable {
public class ContainerMEPortableCell extends ContainerMEMonitorable
{
public static ContainerType<ContainerMEPortableCell> TYPE;
public static ContainerType<ContainerMEPortableCell> TYPE;
private static final ContainerHelper<ContainerMEPortableCell, IPortableCell> helper = new ContainerHelper<>(
ContainerMEPortableCell::new, IPortableCell.class);
private static final ContainerHelper<ContainerMEPortableCell, IPortableCell> helper
= new ContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class);
public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final IPortableCell monitorable) {
this(TYPE, id, ip, monitorable);
}
public ContainerMEPortableCell(int id, final PlayerInventory ip, final IPortableCell monitorable )
{
this(TYPE, id, ip, monitorable);
}
protected ContainerMEPortableCell(ContainerType<? extends ContainerMEPortableCell> type, int id,
final PlayerInventory ip, final IPortableCell monitorable) {
super(type, id, 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);
}
protected ContainerMEPortableCell(ContainerType<? extends ContainerMEPortableCell> type, int id, final PlayerInventory ip, final IPortableCell monitorable )
{
super( type, id, 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;
}
}
@@ -18,15 +18,14 @@
package appeng.container.implementations;
import java.io.IOException;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.INetworkTool;
@@ -40,168 +39,141 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import net.minecraft.network.PacketBuffer;
public class ContainerNetworkStatus extends AEBaseContainer {
public class ContainerNetworkStatus extends AEBaseContainer
{
public static ContainerType<ContainerNetworkStatus> TYPE;
public static ContainerType<ContainerNetworkStatus> TYPE;
private static final ContainerHelper<ContainerNetworkStatus, INetworkTool> helper = new ContainerHelper<>(
ContainerNetworkStatus::new, INetworkTool.class);
private static final ContainerHelper<ContainerNetworkStatus, INetworkTool> helper
= new ContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class);
public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@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(int id, PlayerInventory ip, final INetworkTool te) {
super(TYPE, id, ip, null, null);
final IGridHost host = te.getGridHost();
public ContainerNetworkStatus(int id, PlayerInventory ip, final INetworkTool te) {
super(TYPE, id, 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 PlayerEntity) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
}
}
} catch (final IOException e) {
// :P
}
}
super.detectAndSendChanges();
}
for( final Object c : this.listeners )
{
if( c instanceof PlayerEntity )
{
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) 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;
}
}
@@ -18,12 +18,6 @@
package appeng.container.implementations;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -31,94 +25,84 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
public class ContainerNetworkTool extends AEBaseContainer
{
public class ContainerNetworkTool extends AEBaseContainer {
public static ContainerType<ContainerNetworkTool> TYPE;
public static ContainerType<ContainerNetworkTool> TYPE;
private static final ContainerHelper<ContainerNetworkTool, INetworkTool> helper
= new ContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class);
private static final ContainerHelper<ContainerNetworkTool, INetworkTool> helper = new ContainerHelper<>(
ContainerNetworkTool::new, INetworkTool.class);
public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final INetworkTool toolInv;
private final INetworkTool toolInv;
@GuiSync( 1 )
public boolean facadeMode;
@GuiSync(1)
public boolean facadeMode;
public ContainerNetworkTool(int id, final PlayerInventory ip, final INetworkTool te )
{
super( TYPE, id, ip, null, null );
this.toolInv = te;
public ContainerNetworkTool(int id, final PlayerInventory ip, final INetworkTool te) {
super(TYPE, id, 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.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te
.getInventory(), y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getPlayerInventory() ) ) );
}
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, te.getInventory(),
y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getPlayerInventory())));
}
}
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
public void toggleFacadeMode()
{
public void toggleFacadeMode() {
final CompoundNBT data = this.toolInv.getItemStack().getOrCreateTag();
data.putBoolean("hideFacades", !data.getBoolean( "hideFacades" ));
this.detectAndSendChanges();
}
data.putBoolean("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() )
{
if (this.isValidContainer()) {
final CompoundNBT data = currentItem.getOrCreateTag();
this.setFacadeMode( data.getBoolean( "hideFacades" ) );
}
this.setFacadeMode(data.getBoolean("hideFacades"));
}
super.detectAndSendChanges();
}
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;
}
}
File diff suppressed because it is too large Load Diff
@@ -18,8 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -32,81 +30,72 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.config.SecurityPermissions;
import appeng.api.parts.IPart;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.helpers.IPriorityHost;
import appeng.util.Platform;
public class ContainerPriority extends AEBaseContainer {
public class ContainerPriority extends AEBaseContainer
{
public static ContainerType<ContainerPriority> TYPE;
public static ContainerType<ContainerPriority> TYPE;
private static final ContainerHelper<ContainerPriority, IPriorityHost> helper = new ContainerHelper<>(
ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerPriority, IPriorityHost> helper
= new ContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD);
public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final IPriorityHost priHost;
private final IPriorityHost priHost;
@OnlyIn(Dist.CLIENT)
private TextFieldWidget textField;
@GuiSync(2)
public long PriorityValue = -1;
@OnlyIn( Dist.CLIENT )
private TextFieldWidget textField;
@GuiSync( 2 )
public long PriorityValue = -1;
public ContainerPriority(int id, final PlayerInventory ip, final IPriorityHost te) {
super(TYPE, id, ip, (TileEntity) (te instanceof TileEntity ? te : null),
(IPart) (te instanceof IPart ? te : null));
this.priHost = te;
}
public ContainerPriority(int id, final PlayerInventory ip, final IPriorityHost te )
{
super( TYPE, id, ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) );
this.priHost = te;
}
@OnlyIn(Dist.CLIENT)
public void setTextField(final TextFieldWidget level) {
this.textField = level;
this.textField.setText(String.valueOf(this.PriorityValue));
}
@OnlyIn( Dist.CLIENT )
public void setTextField( final TextFieldWidget level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.PriorityValue ) );
}
public void setPriority(final int newValue, final PlayerEntity player) {
this.priHost.setPriority(newValue);
this.PriorityValue = newValue;
}
public void setPriority( final int newValue, final PlayerEntity 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;
}
}
@@ -18,44 +18,40 @@
package appeng.container.implementations;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.qnb.TileQuantumBridge;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.qnb.TileQuantumBridge;
public class ContainerQNB extends AEBaseContainer
{
public class ContainerQNB extends AEBaseContainer {
public static ContainerType<ContainerQNB> TYPE;
public static ContainerType<ContainerQNB> TYPE;
private static final ContainerHelper<ContainerQNB, TileQuantumBridge> helper
= new ContainerHelper<>(ContainerQNB::new, TileQuantumBridge.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerQNB, TileQuantumBridge> helper = new ContainerHelper<>(
ContainerQNB::new, TileQuantumBridge.class, SecurityPermissions.BUILD);
public static ContainerQNB fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerQNB fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public ContainerQNB(int id, final PlayerInventory ip, final TileQuantumBridge quantumBridge )
{
super( TYPE, id, ip, quantumBridge, null );
public ContainerQNB(int id, final PlayerInventory ip, final TileQuantumBridge quantumBridge) {
super(TYPE, id, ip, quantumBridge, null);
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge
.getInternalInventory(), 0, 80, 37, this.getPlayerInventory() ) ).setStackLimit( 1 ) );
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY,
quantumBridge.getInternalInventory(), 0, 80, 37, this.getPlayerInventory())).setStackLimit(1));
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
}
@@ -18,10 +18,8 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -34,159 +32,135 @@ import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.contents.QuartzKnifeObj;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
public class ContainerQuartzKnife extends AEBaseContainer {
public class ContainerQuartzKnife extends AEBaseContainer
{
public static ContainerType<ContainerQuartzKnife> TYPE;
public static ContainerType<ContainerQuartzKnife> TYPE;
private static final ContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper = new ContainerHelper<>(
ContainerQuartzKnife::new, QuartzKnifeObj.class);
private static final ContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper
= new ContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class);
public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final QuartzKnifeObj te) {
super(TYPE, id, ip, null, null);
this.toolInv = te;
public ContainerQuartzKnife(int id, final PlayerInventory ip, final QuartzKnifeObj te )
{
super( TYPE, id, ip, null, null );
this.toolInv = te;
this.addSlot(
new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip));
this.addSlot(new QuartzKniveSlot(this.inSlot, 0, 134, 44, -1));
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) );
this.addSlot( 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 PlayerEntity par1PlayerEntity) {
if (this.inSlot.getStackInSlot(0) != null) {
par1PlayerEntity.dropItem(this.inSlot.getStackInSlot(0), false);
}
}
@Override
public void onContainerClosed( final PlayerEntity par1PlayerEntity )
{
if( this.inSlot.getStackInSlot( 0 ) != null )
{
par1PlayerEntity.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 ->
{
if (SlotRestrictedInput.isMetalIngot(input)) {
if (ContainerQuartzKnife.this.myName.length() > 0) {
return AEApi.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack -> {
final CompoundNBT compound = namePressStack.getOrCreateTag();
compound.putString("InscribeName", ContainerQuartzKnife.this.myName);
compound.putString("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, p -> {
ContainerQuartzKnife.this.getPlayerInv()
.setInventorySlotContents( ContainerQuartzKnife.this.getPlayerInv().currentItem, ItemStack.EMPTY );
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( ContainerQuartzKnife.this.getPlayerInv().player, before, null ) );
} );
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, p -> {
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();
}
}
}
}
}
@@ -18,8 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -34,6 +32,7 @@ import appeng.api.features.INetworkEncodable;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
@@ -42,167 +41,142 @@ import appeng.tile.misc.TileSecurityStation;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory {
public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory
{
public static ContainerType<ContainerSecurityStation> TYPE;
public static ContainerType<ContainerSecurityStation> TYPE;
private static final ContainerHelper<ContainerSecurityStation, ITerminalHost> helper = new ContainerHelper<>(
ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY);
private static final ContainerHelper<ContainerSecurityStation, ITerminalHost> helper
= new ContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY);
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(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
super(TYPE, id, ip, monitorable, false);
public ContainerSecurityStation(int id, final PlayerInventory ip, final ITerminalHost monitorable )
{
super( TYPE, id, ip, monitorable, false );
this.securityBox = (TileSecurityStation) monitorable;
this.securityBox = (TileSecurityStation) monitorable;
this.addSlot(this.configSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD,
this.securityBox.getConfigSlot(), 0, 37, -33, ip));
this.addSlot( this.configSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD, this.securityBox
.getConfigSlot(), 0, 37, -33, ip ) );
this.addSlot(this.wirelessIn = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODABLE_ITEM,
this.wirelessEncoder, 0, 212, 10, ip));
this.addSlot(this.wirelessOut = new SlotOutput(this.wirelessEncoder, 1, 212, 68, -1));
this.addSlot(
this.wirelessIn = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODABLE_ITEM, this.wirelessEncoder, 0, 212, 10, ip ) );
this.addSlot( this.wirelessOut = new SlotOutput( this.wirelessEncoder, 1, 212, 68, -1 ) );
this.bindPlayerInventory(ip, 0, 0);
}
this.bindPlayerInventory( ip, 0, 0 );
}
public static ContainerSecurityStation fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerSecurityStation fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public void toggleSetting(final String value, final PlayerEntity player) {
try {
final SecurityPermissions permission = SecurityPermissions.valueOf(value);
public void toggleSetting( final String value, final PlayerEntity 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 PlayerEntity player) {
super.onContainerClosed(player);
@Override
public void onContainerClosed( final PlayerEntity 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;
}
}
@@ -18,60 +18,52 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import appeng.tile.storage.TileSkyChest;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotNormal;
import appeng.tile.storage.TileSkyChest;
public class ContainerSkyChest extends AEBaseContainer
{
public class ContainerSkyChest extends AEBaseContainer {
public static ContainerType<ContainerSkyChest> TYPE;
public static ContainerType<ContainerSkyChest> TYPE;
private static final ContainerHelper<ContainerSkyChest, TileSkyChest> helper
= new ContainerHelper<>(ContainerSkyChest::new, TileSkyChest.class);
private static final ContainerHelper<ContainerSkyChest, TileSkyChest> helper = new ContainerHelper<>(
ContainerSkyChest::new, TileSkyChest.class);
private final TileSkyChest chest;
private final TileSkyChest chest;
public ContainerSkyChest(int id, final PlayerInventory ip, final TileSkyChest chest) {
super(TYPE, id, ip, chest, null);
this.chest = chest;
public ContainerSkyChest(int id, final PlayerInventory ip, final TileSkyChest chest )
{
super( TYPE, id, ip, chest, null );
this.chest = chest;
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 9; x++) {
this.addSlot(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.addSlot( 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 );
}
public static ContainerSkyChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerSkyChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@Override
public void onContainerClosed( final PlayerEntity par1PlayerEntity )
{
super.onContainerClosed( par1PlayerEntity );
this.chest.closeInventory( par1PlayerEntity );
}
@Override
public void onContainerClosed(final PlayerEntity par1PlayerEntity) {
super.onContainerClosed(par1PlayerEntity);
this.chest.closeInventory(par1PlayerEntity);
}
}
@@ -18,11 +18,10 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
@@ -31,146 +30,127 @@ import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.spatial.TileSpatialIOPort;
import appeng.util.Platform;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
public class ContainerSpatialIOPort extends AEBaseContainer {
public class ContainerSpatialIOPort extends AEBaseContainer
{
public static ContainerType<ContainerSpatialIOPort> TYPE;
public static ContainerType<ContainerSpatialIOPort> TYPE;
private static final ContainerHelper<ContainerSpatialIOPort, TileSpatialIOPort> helper = new ContainerHelper<>(
ContainerSpatialIOPort::new, TileSpatialIOPort.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerSpatialIOPort, TileSpatialIOPort> helper
= new ContainerHelper<>(ContainerSpatialIOPort::new, TileSpatialIOPort.class, SecurityPermissions.BUILD);
@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(int id, final PlayerInventory ip, final TileSpatialIOPort spatialIOPort) {
super(TYPE, id, ip, spatialIOPort, null);
public ContainerSpatialIOPort(int id, final PlayerInventory ip, final TileSpatialIOPort spatialIOPort )
{
super( TYPE, id, ip, spatialIOPort, null );
if (Platform.isServer()) {
this.network = spatialIOPort.getGridNode(AEPartLocation.INTERNAL).getGrid();
}
if( Platform.isServer() )
{
this.network = spatialIOPort.getGridNode( AEPartLocation.INTERNAL ).getGrid();
}
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS,
spatialIOPort.getInternalInventory(), 0, 52, 48, this.getPlayerInventory()));
this.addSlot(new SlotOutput(spatialIOPort.getInternalInventory(), 1, 113, 48,
SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon));
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort
.getInternalInventory(), 0, 52, 48, this.getPlayerInventory() ) );
this.addSlot(
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 );
}
public static ContainerSpatialIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerSpatialIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@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;
}
}
@@ -18,10 +18,8 @@
package appeng.container.implementations;
import java.util.Iterator;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -40,6 +38,7 @@ import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
@@ -49,171 +48,143 @@ import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.iterators.NullIterator;
public class ContainerStorageBus extends ContainerUpgradeable {
public class ContainerStorageBus extends ContainerUpgradeable
{
public static ContainerType<ContainerStorageBus> TYPE;
public static ContainerType<ContainerStorageBus> TYPE;
private static final ContainerHelper<ContainerStorageBus, PartStorageBus> helper = new ContainerHelper<>(
ContainerStorageBus::new, PartStorageBus.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerStorageBus, PartStorageBus> helper
= new ContainerHelper<>(ContainerStorageBus::new, PartStorageBus.class, SecurityPermissions.BUILD);
public static ContainerStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final PartStorageBus te) {
super(TYPE, id, ip, te);
this.storageBus = te;
}
public ContainerStorageBus(int id, final PlayerInventory ip, final PartStorageBus te )
{
super( TYPE, id, 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.addSlot(new SlotFakeTypeOnly(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlot(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.addSlot( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
}
else
{
this.addSlot( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getPlayerInventory() ) )
.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;
}
}
@@ -18,8 +18,6 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
@@ -43,6 +41,7 @@ import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.parts.IPart;
import appeng.api.util.IConfigManager;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
@@ -54,300 +53,249 @@ 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
{
public static ContainerType<ContainerUpgradeable> TYPE;
public static ContainerType<ContainerUpgradeable> TYPE;
private static final ContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper = new ContainerHelper<>(
ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper
= new ContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
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(int id, final PlayerInventory ip, final IUpgradeableHost te) {
this(TYPE, id, ip, te);
}
public ContainerUpgradeable(int id, final PlayerInventory ip, final IUpgradeableHost te )
{
this(TYPE, id, ip, te);
}
public ContainerUpgradeable(ContainerType<?> containerType, int id, final PlayerInventory ip,
final IUpgradeableHost te) {
super(containerType, id, ip, (TileEntity) (te instanceof TileEntity ? te : null),
(IPart) (te instanceof IPart ? te : null));
this.upgradeable = te;
public ContainerUpgradeable(ContainerType<?> containerType, int id, final PlayerInventory ip, final IUpgradeableHost te )
{
super( containerType, id, 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, x, 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, x, 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.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES,
this.tbInventory.getInternalInventory(), u + v * 3, 186 + u * 18,
this.getHeight() - 82 + v * 18, this.getPlayerInventory())).setPlayerSide());
}
}
}
if( this.hasToolbox() )
{
for( int v = 0; v < 3; v++ )
{
for( int u = 0; u < 3; u++ )
{
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory
.getInternalInventory(), u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getPlayerInventory() ) ).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.addSlot(new SlotFakeTypeOnly(inv, 0, x, y));
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80;
this.addSlot( new SlotFakeTypeOnly( inv, 0, x, y ) );
if (this.supportCapacity()) {
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 1, x, y, -1, 0, 1));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 2, x, y, 1, 0, 1));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 3, x, y, 0, -1, 1));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 4, x, y, 0, 1, 1));
if( this.supportCapacity() )
{
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 5, x, y, -1, -1, 2));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 6, x, y, 1, -1, 2));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 7, x, y, -1, 1, 2));
this.addSlot(new OptionalSlotFakeTypeOnly(inv, this, 8, x, y, 1, 1, 2));
}
}
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
this.addSlot( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
this.addSlot( 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.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187,
8 + 18, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
}
}
protected void setupUpgrades()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 1 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 2 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
}
if( this.availableUpgrades() > 3 )
{
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.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;
}
if (idx == 2 && upgrades > 1) {
return true;
}
if( idx == 1 && upgrades > 0 )
{
return true;
}
if( idx == 2 && upgrades > 1 )
{
return true;
}
return false;
}
return false;
}
public FuzzyMode getFuzzyMode() {
return this.fzMode;
}
public FuzzyMode getFuzzyMode()
{
return this.fzMode;
}
public void setFuzzyMode(final FuzzyMode fzMode) {
this.fzMode = fzMode;
}
public void setFuzzyMode( final FuzzyMode fzMode )
{
this.fzMode = fzMode;
}
public YesNo getCraftingMode() {
return this.cMode;
}
public YesNo getCraftingMode()
{
return this.cMode;
}
public void setCraftingMode(final YesNo cMode) {
this.cMode = cMode;
}
public void setCraftingMode( final YesNo cMode )
{
this.cMode = cMode;
}
public RedstoneMode getRedStoneMode() {
return this.rsMode;
}
public RedstoneMode getRedStoneMode()
{
return this.rsMode;
}
public void setRedStoneMode(final RedstoneMode rsMode) {
this.rsMode = rsMode;
}
public void setRedStoneMode( final RedstoneMode rsMode )
{
this.rsMode = rsMode;
}
public SchedulingMode getSchedulingMode() {
return this.schedulingMode;
}
public SchedulingMode getSchedulingMode()
{
return this.schedulingMode;
}
private void setSchedulingMode(final SchedulingMode schedulingMode) {
this.schedulingMode = schedulingMode;
}
private void setSchedulingMode( final SchedulingMode schedulingMode )
{
this.schedulingMode = schedulingMode;
}
protected IUpgradeableHost getUpgradeable()
{
return this.upgradeable;
}
protected IUpgradeableHost getUpgradeable() {
return this.upgradeable;
}
}
@@ -18,82 +18,73 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileVibrationChamber;
import appeng.util.Platform;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider {
public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider
{
public static ContainerType<ContainerVibrationChamber> TYPE;
public static ContainerType<ContainerVibrationChamber> TYPE;
private static final ContainerHelper<ContainerVibrationChamber, TileVibrationChamber> helper = new ContainerHelper<>(
ContainerVibrationChamber::new, TileVibrationChamber.class);
private static final ContainerHelper<ContainerVibrationChamber, TileVibrationChamber> helper
= new ContainerHelper<>(ContainerVibrationChamber::new, TileVibrationChamber.class);
public static ContainerVibrationChamber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerVibrationChamber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final TileVibrationChamber vibrationChamber;
@GuiSync(0)
public int burnSpeed = 0;
@GuiSync(1)
public int remainingBurnTime = 0;
private final TileVibrationChamber vibrationChamber;
@GuiSync( 0 )
public int burnSpeed = 0;
@GuiSync( 1 )
public int remainingBurnTime = 0;
public ContainerVibrationChamber(int id, final PlayerInventory ip, final TileVibrationChamber vibrationChamber) {
super(TYPE, id, ip, vibrationChamber, null);
this.vibrationChamber = vibrationChamber;
public ContainerVibrationChamber(int id, final PlayerInventory ip, final TileVibrationChamber vibrationChamber )
{
super( TYPE, id, ip, vibrationChamber, null );
this.vibrationChamber = vibrationChamber;
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.FUEL,
vibrationChamber.getInternalInventory(), 0, 80, 37, this.getPlayerInventory()));
this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this
.getPlayerInventory() ) );
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;
}
}
@@ -18,82 +18,73 @@
package appeng.container.implementations;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
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.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig;
import appeng.tile.networking.TileWireless;
public class ContainerWireless extends AEBaseContainer
{
public class ContainerWireless extends AEBaseContainer {
public static ContainerType<ContainerWireless> TYPE;
public static ContainerType<ContainerWireless> TYPE;
private static final ContainerHelper<ContainerWireless, TileWireless> helper
= new ContainerHelper<>(ContainerWireless::new, TileWireless.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerWireless, TileWireless> helper = new ContainerHelper<>(
ContainerWireless::new, TileWireless.class, SecurityPermissions.BUILD);
public static ContainerWireless fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerWireless fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final SlotRestrictedInput boosterSlot;
@GuiSync( 1 )
public long range = 0;
@GuiSync( 2 )
public long drain = 0;
private final SlotRestrictedInput boosterSlot;
@GuiSync(1)
public long range = 0;
@GuiSync(2)
public long drain = 0;
public ContainerWireless(int id, final PlayerInventory ip, final TileWireless te )
{
super( TYPE, id, ip, te, null );
public ContainerWireless(int id, final PlayerInventory ip, final TileWireless te) {
super(TYPE, id, ip, te, null);
this.addSlot( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, te
.getInternalInventory(), 0, 80, 47, this.getPlayerInventory() ) );
this.addSlot(this.boosterSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER,
te.getInternalInventory(), 0, 80, 47, this.getPlayerInventory()));
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;
}
}
@@ -18,60 +18,52 @@
package appeng.container.implementations;
import appeng.container.ContainerLocator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.container.ContainerLocator;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
public class ContainerWirelessTerm extends ContainerMEPortableCell {
public class ContainerWirelessTerm extends ContainerMEPortableCell
{
public static ContainerType<ContainerWirelessTerm> TYPE;
public static ContainerType<ContainerWirelessTerm> TYPE;
private static final ContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper = new ContainerHelper<>(
ContainerWirelessTerm::new, WirelessTerminalGuiObject.class);
private static final ContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper
= new ContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class);
public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
public ContainerWirelessTerm(int id, final PlayerInventory ip, final WirelessTerminalGuiObject gui) {
super(TYPE, id, ip, gui);
this.wirelessTerminalGUIObject = gui;
}
public ContainerWirelessTerm(int id, final PlayerInventory ip, final WirelessTerminalGuiObject gui )
{
super( TYPE, id, 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()));
}
}
}
@@ -18,57 +18,48 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import appeng.api.networking.crafting.ICraftingCPU;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.util.text.ITextComponent;
import appeng.api.networking.crafting.ICraftingCPU;
public class CraftingCPURecord implements Comparable<CraftingCPURecord>
{
private final ITextComponent myName;
private final ICraftingCPU cpu;
private final long size;
private final int processors;
public class CraftingCPURecord implements Comparable<CraftingCPURecord> {
private final ITextComponent myName;
private final ICraftingCPU cpu;
private final long size;
private final int processors;
public CraftingCPURecord( final long size, final int coProcessors, final ICraftingCPU server )
{
this.size = size;
this.processors = coProcessors;
this.cpu = server;
this.myName = server.getName();
}
public CraftingCPURecord(final long size, final int coProcessors, final ICraftingCPU server) {
this.size = size;
this.processors = coProcessors;
this.cpu = server;
this.myName = server.getName();
}
@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() );
}
@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());
}
ICraftingCPU getCpu()
{
return this.cpu;
}
ICraftingCPU getCpu() {
return this.cpu;
}
ITextComponent getName()
{
return this.myName;
}
ITextComponent getName() {
return this.myName;
}
int getProcessors()
{
return this.processors;
}
int getProcessors() {
return this.processors;
}
long getSize()
{
return this.size;
}
long getSize() {
return this.size;
}
}