Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,232 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container;
import appeng.api.util.AEPartLocation;
import com.google.common.base.Preconditions;
import io.netty.handler.codec.DecoderException;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
* Describes how a container the player has opened was originally located. This
* can be one of three ways:
*
* <ul>
* <li>A block entity at a given block position.</li>
* <li>A part (i.e. cable bus part) at the side of a given block position.</li>
* <li>An item held by the player.</li>
* </ul>
*/
public final class ContainerLocator {
private enum Type {
/**
* An item used from the player's inventory.
*/
PLAYER_INVENTORY,
/**
* An item used from the player's inventory, but right-clicked on a block face,
* has block position and side in addition to the above.
*/
PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, BLOCK, PART
}
private final Type type;
private final int itemIndex;
private final Identifier worldId;
private final BlockPos blockPos;
private final AEPartLocation side;
private ContainerLocator(Type type, int itemIndex, World world, BlockPos blockPos, AEPartLocation side) {
this(type, itemIndex, world.getRegistryKey().getValue(), blockPos, side);
}
private ContainerLocator(Type type, int itemIndex, Identifier worldId, BlockPos blockPos, AEPartLocation side) {
this.type = type;
this.itemIndex = itemIndex;
this.worldId = worldId;
this.blockPos = blockPos;
this.side = side;
}
public static ContainerLocator forTileEntity(BlockEntity te) {
if (te.getWorld() == null) {
throw new IllegalArgumentException("Cannot open a block entity that is not in a world");
}
return new ContainerLocator(Type.BLOCK, -1, te.getWorld(), te.getPos(), null);
}
public static ContainerLocator forTileEntitySide(BlockEntity te, Direction side) {
if (te.getWorld() == null) {
throw new IllegalArgumentException("Cannot open a block entity that is not in a world");
}
return new ContainerLocator(Type.PART, -1, te.getWorld(), te.getPos(), AEPartLocation.fromFacing(side));
}
/**
* Construct a container locator for an item being used on a block. The item
* could still open a container for itself, but it might also open a special
* container for the block being right-clicked.
*/
public static ContainerLocator forItemUseContext(ItemUsageContext context) {
PlayerEntity player = context.getPlayer();
if (player == null) {
throw new IllegalArgumentException("Cannot open a container without a player");
}
int slot = getPlayerInventorySlotFromHand(player, context.getHand());
AEPartLocation side = AEPartLocation.fromFacing(context.getSide());
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, player.world, context.getBlockPos(),
side);
}
public static ContainerLocator forHand(PlayerEntity player, Hand hand) {
int slot = getPlayerInventorySlotFromHand(player, hand);
return new ContainerLocator(Type.PLAYER_INVENTORY, slot, (Identifier) null, null, null);
}
private static int getPlayerInventorySlotFromHand(PlayerEntity player, Hand hand) {
ItemStack is = player.getStackInHand(hand);
if (is.isEmpty()) {
throw new IllegalArgumentException("Cannot open an item-inventory with empty hands");
}
int invSize = player.inventory.size();
for (int i = 0; i < invSize; i++) {
if (player.inventory.getStack(i) == is) {
return i;
}
}
throw new IllegalArgumentException("Could not find item held in hand " + hand + " in player inventory");
}
// FIXME FABRIC public static ContainerLocator forPart(AEBasePart part) {
// FIXME FABRIC IPartHost host = part.getHost();
// FIXME FABRIC DimensionalCoord pos = host.getLocation();
// FIXME FABRIC return new ContainerLocator(Type.PART, -1, pos.getWorld().getDimension().getType().getId(), pos.getBlockPos(),
// FIXME FABRIC part.getSide());
// FIXME FABRIC }
public boolean hasItemIndex() {
return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
}
public int getItemIndex() {
Preconditions.checkState(hasItemIndex());
return itemIndex;
}
public Identifier getWorldId() {
return worldId;
}
public boolean hasBlockPos() {
return type == Type.BLOCK || type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
}
public BlockPos getBlockPos() {
Preconditions.checkState(hasBlockPos());
return blockPos;
}
public boolean hasSide() {
return type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
}
public AEPartLocation getSide() {
Preconditions.checkState(hasSide());
return side;
}
public void write(PacketByteBuf buf) {
switch (type) {
case PLAYER_INVENTORY:
buf.writeByte(0);
buf.writeInt(itemIndex);
break;
case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT:
buf.writeByte(1);
buf.writeInt(itemIndex);
buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal());
break;
case BLOCK:
buf.writeByte(2);
buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos);
break;
case PART:
buf.writeByte(3);
buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal());
break;
default:
throw new IllegalStateException("Unsupported ContainerLocator type: " + type);
}
}
public static ContainerLocator read(PacketByteBuf buf) {
byte type = buf.readByte();
switch (type) {
case 0:
return new ContainerLocator(Type.PLAYER_INVENTORY, buf.readInt(), (Identifier) null, null, null);
case 1:
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, buf.readInt(), buf.readIdentifier(),
buf.readBlockPos(), AEPartLocation.values()[buf.readByte()]);
case 2:
return new ContainerLocator(Type.BLOCK, -1, buf.readIdentifier(), buf.readBlockPos(), null);
case 3:
return new ContainerLocator(Type.PART, -1, buf.readIdentifier(), buf.readBlockPos(),
AEPartLocation.values()[buf.readByte()]);
default:
throw new DecoderException("ContainerLocator type out of range: " + type);
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder(type.name());
result.append('{');
if (hasItemIndex()) {
result.append("slot=").append(itemIndex).append(',');
}
if (hasBlockPos()) {
result.append("dim=").append(worldId).append(',');
result.append("pos=").append(blockPos).append(',');
}
if (hasSide()) {
result.append("side=").append(side).append(',');
}
if (result.charAt(result.length() - 1) == ',') {
result.setLength(result.length() - 1);
}
result.append('}');
return result.toString();
}
}
@@ -1,37 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
/*
* Totally useless container that does nothing.
*/
public class ContainerNull extends Container {
public ContainerNull() {
super(null, 0);
}
@Override
public boolean canInteractWith(final PlayerEntity PlayerEntity) {
return false;
}
}
@@ -1,42 +0,0 @@
package appeng.container;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import appeng.core.AELog;
/**
* Allows opening containers generically.
*/
public final class ContainerOpener {
private ContainerOpener() {
}
private static final Map<ScreenHandlerType<? extends AEBaseContainer>, Opener<?>> registry = new HashMap<>();
public static <T extends AEBaseContainer> void addOpener(ScreenHandlerType<T> type, Opener<T> opener) {
registry.put(type, opener);
}
public static boolean openContainer(ScreenHandlerType<?> type, PlayerEntity player, ContainerLocator locator) {
Opener<?> opener = registry.get(type);
if (opener == null) {
AELog.warn("Trying to open container for unknown container type {}", type);
return false;
}
return opener.open(player, locator);
}
@FunctionalInterface
public interface Opener<T extends AEBaseContainer> {
boolean open(PlayerEntity player, ContainerLocator locator);
}
}
@@ -1,186 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.guisync;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.util.Objects;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.text.Text;
import appeng.container.AEBaseContainer;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.ProgressBarPacket;
/**
* This class is responsible for synchronizing Container-fields from server to
* client.
*/
public class SyncData {
private final AEBaseContainer source;
private final Field field;
private final Class<?> fieldType;
private final int channel;
private final MethodHandle getter;
private final MethodHandle setter;
private Object clientVersion;
public SyncData(final AEBaseContainer container, final Field field, final GuiSync annotation) {
this.clientVersion = null;
this.source = container;
this.channel = annotation.value();
this.field = field;
this.fieldType = field.getType();
try {
this.getter = MethodHandles.publicLookup().unreflectGetter(field);
this.setter = MethodHandles.publicLookup().unreflectSetter(field);
} catch (IllegalAccessException e) {
throw new RuntimeException(
"Failed to get accessor for field " + field + ". Did you forget to make it public?");
}
}
public int getChannel() {
return this.channel;
}
public void tick(final IContainerListener c) {
try {
final Object val = this.getter.invoke(source);
if (!Objects.equals(val, this.clientVersion)) {
this.send(c, val);
}
} catch (Throwable e) {
AELog.debug(e);
}
}
private void send(final IContainerListener o, Object val) {
if (fieldType.isAssignableFrom(Text.class)) {
if (o instanceof ServerPlayerEntity) {
String json = "";
if (val != null) {
json = Text.Serializer.toJson((Text) val);
}
NetworkHandler.instance().sendTo(new ConfigValuePacket("SyncDat." + this.channel, json),
(ServerPlayerEntity) o);
}
}
// Types other than Text must be non-null
if (val == null) {
return;
}
if (fieldType.equals(String.class)) {
if (o instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new ConfigValuePacket("SyncDat." + this.channel, (String) val),
(ServerPlayerEntity) o);
}
} else if (this.fieldType.isEnum()) {
o.sendWindowProperty(this.source, this.channel, ((Enum<?>) val).ordinal());
} else if (val instanceof Long) {
if (o instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new ProgressBarPacket(this.channel, (Long) val),
(ServerPlayerEntity) o);
}
} else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) {
o.sendWindowProperty(this.source, this.channel, ((Boolean) val) ? 1 : 0);
} else if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) {
o.sendWindowProperty(this.source, this.channel, (Integer) val);
} else {
throw new IllegalStateException("Unknown field type: " + fieldType);
}
this.clientVersion = val;
}
public void update(Object val) {
try {
final Object oldValue = this.getter.invoke(source);
if (val instanceof String) {
if (this.fieldType.isAssignableFrom(Text.class)) {
String json = (String) val;
Text text = null;
if (!json.isEmpty()) {
text = Text.Serializer.fromJson((String) val);
}
this.updateTextComponent(text);
} else {
this.updateString((String) val);
}
} else {
this.updateValue(oldValue, (Long) val);
}
} catch (Throwable e) {
AELog.debug(e);
}
}
private void updateString(final String val) {
try {
this.setter.invoke(source, val);
} catch (Throwable e) {
AELog.debug(e);
}
}
private void updateTextComponent(final Text val) {
try {
this.setter.invoke(source, val);
} catch (Throwable e) {
AELog.debug(e);
}
}
private void updateValue(final Object oldValue, final long val) {
try {
if (this.fieldType.isEnum()) {
Object e = this.fieldType.getEnumConstants()[(int) val];
this.setter.invoke(source, e);
} else {
if (this.fieldType.equals(int.class)) {
this.setter.invoke(source, (int) val);
} else if (this.fieldType.equals(long.class)) {
this.setter.invoke(source, val);
} else if (this.fieldType.equals(boolean.class)) {
this.setter.invoke(source, val == 1);
} else if (this.fieldType.equals(Integer.class)) {
this.setter.invoke(source, (int) val);
} else if (this.fieldType.equals(Long.class)) {
this.setter.invoke(source, val);
} else if (this.fieldType.equals(Boolean.class)) {
this.setter.invoke(source, val == 1);
}
}
this.source.onUpdate(this.field.getName(), oldValue, this.getter.invoke(source));
} catch (Throwable e) {
AELog.debug(e);
}
}
}
@@ -1,240 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.util.Iterator;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.impl.EmptyFixedItemInv;
import appeng.api.AEApi;
import appeng.api.config.CopyMode;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.cells.ICellWorkbenchItem;
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.slot.FakeTypeOnlySlot;
import appeng.container.slot.OptionalRestrictedInputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.misc.CellWorkbenchBlockEntity;
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 CellWorkbenchContainer extends UpgradeableContainer {
public static ScreenHandlerType<CellWorkbenchContainer> TYPE;
private static final ContainerHelper<CellWorkbenchContainer, CellWorkbenchBlockEntity> helper = new ContainerHelper<>(
CellWorkbenchContainer::new, CellWorkbenchBlockEntity.class);
private final CellWorkbenchBlockEntity workBench;
@GuiSync(2)
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
private int lastUpgrades = 0;
public CellWorkbenchContainer(int id, final PlayerInventory ip, final CellWorkbenchBlockEntity te) {
super(TYPE, id, ip, te);
this.workBench = te;
}
public static CellWorkbenchContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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").getInvStack(0), valueOf);
}
}
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);
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig() {
final FixedItemInv cell = this.getUpgradeable().getInventoryByName("cell");
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8,
this.getPlayerInv()));
final FixedItemInv inv = this.getUpgradeable().getInventoryByName("config");
final WrapperSupplierItemHandler upgradeInventory = new WrapperSupplierItemHandler(
this::getCellUpgradeInventory);
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 FakeTypeOnlySlot(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 OptionalRestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES,
upgradeInventory, this, iSLot, 187 + zz * 18, 8 + 18 * z, iSLot, this.getPlayerInventory()));
}
}
}
@Override
public int availableUpgrades() {
final ItemStack is = this.workBench.getInventoryByName("cell").getInvStack(0);
if (this.prevStack != is) {
this.prevStack = is;
this.lastUpgrades = this.getCellUpgradeInventory().getSlotCount();
}
return this.lastUpgrades;
}
@Override
public void detectAndSendChanges() {
final ItemStack is = this.workBench.getInventoryByName("cell").getInvStack(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 OptionalRestrictedInputSlot) {
final OptionalRestrictedInputSlot sri = (OptionalRestrictedInputSlot) s;
listener.sendSlotContents(this, sri.slotNumber, sri.getStack());
}
}
if (listener instanceof ServerPlayerEntity) {
((ServerPlayerEntity) listener).isChangingQuantityOnly = false;
}
}
}
this.setCopyMode(this.getWorkBenchCopyMode());
this.setFuzzyMode(this.getWorkBenchFuzzyMode());
}
this.prevStack = is;
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
return idx < this.availableUpgrades();
}
public FixedItemInv getCellUpgradeInventory() {
final FixedItemInv upgradeInventory = this.workBench.getCellUpgradeInventory();
return upgradeInventory == null ? EmptyFixedItemInv.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());
}
super.onUpdate(field, oldValue, newValue);
}
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").getInvStack(0));
}
return FuzzyMode.IGNORE_ALL;
}
public void partition() {
final FixedItemInv inv = this.getUpgradeable().getInventoryByName("config");
final ItemStack is = this.getUpgradeable().getInventoryByName("cell").getInvStack(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);
Iterator<IAEStack> i = new NullIterator<>();
if (cellInv != null) {
final IItemList list = cellInv.getAvailableItems(channel.createList());
i = list.iterator();
}
for (int x = 0; x < inv.getSlotCount(); 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();
}
public CopyMode getCopyMode() {
return this.copyMode;
}
private void setCopyMode(final CopyMode copyMode) {
this.copyMode = copyMode;
}
}
@@ -1,56 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.storage.ChestBlockEntity;
public class ChestContainer extends AEBaseContainer {
public static ScreenHandlerType<ChestContainer> TYPE;
private static final ContainerHelper<ChestContainer, ChestBlockEntity> helper = new ContainerHelper<>(
ChestContainer::new, ChestBlockEntity.class, SecurityPermissions.BUILD);
public ChestContainer(int id, final PlayerInventory ip, final ChestBlockEntity chest) {
super(TYPE, id, ip, chest, null);
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.STORAGE_CELLS,
chest.getInternalInventory(), 1, 80, 37, this.getPlayerInventory()));
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
public static ChestContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
}
@@ -1,107 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.misc.CondenserBlockEntity;
import appeng.util.Platform;
public class CondenserContainer extends AEBaseContainer implements IProgressProvider {
public static ScreenHandlerType<CondenserContainer> TYPE;
private static final ContainerHelper<CondenserContainer, CondenserBlockEntity> helper = new ContainerHelper<>(
CondenserContainer::new, CondenserBlockEntity.class);
private final CondenserBlockEntity condenser;
@GuiSync(0)
public long requiredEnergy = 0;
@GuiSync(1)
public long storedPower = 0;
@GuiSync(2)
public CondenserOutput output = CondenserOutput.TRASH;
public CondenserContainer(int id, final PlayerInventory ip, final CondenserBlockEntity condenser) {
super(TYPE, id, ip, condenser, null);
this.condenser = condenser;
FixedItemInv inv = condenser.getInternalInventory();
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.TRASH, inv, 0, 51, 52, ip));
this.addSlot(new OutputSlot(inv, 1, 105, 52, -1));
this.addSlot(
(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip))
.setStackLimit(1));
this.bindPlayerInventory(ip, 0, 197 - /* height of player inventory */82);
}
public static CondenserContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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();
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();
}
@Override
public int getCurrentProgress() {
return (int) this.storedPower;
}
@Override
public int getMaxProgress() {
return (int) this.requiredEnergy;
}
public CondenserOutput getOutput() {
return this.output;
}
private void setOutput(final CondenserOutput output) {
this.output = output;
}
}
@@ -1,209 +0,0 @@
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
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.
*
* @param <C>
*/
public final class ContainerHelper<C extends AEBaseContainer, I> {
private final Class<I> interfaceClass;
private final ContainerFactory<C, I> factory;
private final SecurityPermissions requiredPermission;
public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass) {
this(factory, interfaceClass, null);
}
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 block entity. The tile
* entity's position is encoded in the packet buffer.
*/
public C fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf packetBuf) {
I host = getHostFromLocator(inv.player, ContainerLocator.read(packetBuf));
if (host != null) {
return factory.create(windowId, inv, host);
}
return null;
}
public boolean open(PlayerEntity player, ContainerLocator locator) {
if (!(player instanceof ServerPlayerEntity)) {
// Cannot open containers on the client or for non-players
// FIXME logging?
return false;
}
I accessInterface = getHostFromLocator(player, locator);
if (accessInterface == null) {
return false;
}
if (!checkPermission(player, accessInterface)) {
return false;
}
Text 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);
NetworkHooks.openGui((ServerPlayerEntity) player, container, locator::write);
return true;
}
private Text findContainerTitle(World world, ContainerLocator locator, I accessInterface) {
if (accessInterface instanceof ICustomNameObject) {
ICustomNameObject customNameObject = (ICustomNameObject) accessInterface;
if (customNameObject.hasCustomInventoryName()) {
return customNameObject.getCustomInventoryName();
}
}
// 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)
if (locator.hasBlockPos()) {
return new TranslatableText(
world.getBlockState(locator.getBlockPos()).getBlock().getTranslationKey());
}
return new LiteralText("Unknown");
}
private I getHostFromLocator(PlayerEntity player, ContainerLocator locator) {
if (locator.hasItemIndex()) {
return getHostFromPlayerInventory(player, locator);
}
if (!locator.hasBlockPos()) {
return null; // No block was clicked
}
BlockEntity tileEntity = player.world.getBlockEntity(locator.getBlockPos());
// The block entity itself can host a terminal (i.e. Chest!)
if (interfaceClass.isInstance(tileEntity)) {
return interfaceClass.cast(tileEntity);
}
if (!locator.hasSide()) {
return null;
}
if (tileEntity instanceof IPartHost) {
// But it could also be a part attached to the block entity
IPartHost partHost = (IPartHost) tileEntity;
IPart part = partHost.getPart(locator.getSide());
if (part == null) {
return null;
}
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);
return null;
}
} else {
// FIXME: Logging? Dont know how to obtain the terminal host
return null;
}
}
private I getHostFromPlayerInventory(PlayerEntity player, ContainerLocator locator) {
ItemStack it = player.inventory.getStack(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());
return null;
}
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;
IGuiItemObject guiObject = guiItem.getGuiObject(it, locator.getItemIndex(), player.world, blockPos);
if (interfaceClass.isInstance(guiObject)) {
return interfaceClass.cast(guiObject);
}
}
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()));
}
}
return null;
}
@FunctionalInterface
public interface ContainerFactory<C, I> {
C create(int windowId, PlayerInventory playerInv, I accessObj);
}
private boolean checkPermission(PlayerEntity player, Object accessInterface) {
if (requiredPermission != null) {
return Platform.checkPermissions(player, accessInterface, requiredPermission, true);
}
return true;
}
}
@@ -1,97 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.IActionHost;
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.InaccessibleSlot;
import appeng.me.helpers.PlayerSource;
import appeng.tile.inventory.AppEngInternalInventory;
public class CraftAmountContainer extends AEBaseContainer {
public static ScreenHandlerType<CraftAmountContainer> TYPE;
private static final ContainerHelper<CraftAmountContainer, ITerminalHost> helper = new ContainerHelper<>(
CraftAmountContainer::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private final Slot craftingItem;
private IAEItemStack itemToCreate;
public CraftAmountContainer(int id, PlayerInventory ip, final ITerminalHost te) {
super(TYPE, id, ip, te);
this.craftingItem = new InaccessibleSlot(new AppEngInternalInventory(null, 1), 0, 34, 53);
this.addSlot(this.getCraftingItem());
}
public static CraftAmountContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@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 World getWorld() {
return this.getPlayerInv().player.world;
}
public IActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget());
}
public Slot getCraftingItem() {
return this.craftingItem;
}
public IAEItemStack getItemToCraft() {
return this.itemToCreate;
}
public void setItemToCraft(@Nonnull final IAEItemStack itemToCreate) {
this.itemToCreate = itemToCreate;
}
}
@@ -1,424 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
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.ContainerOpener;
import appeng.container.guisync.GuiSync;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.MEInventoryUpdatePacket;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.PlayerSource;
import appeng.parts.reporting.CraftingTerminalPart;
import appeng.parts.reporting.PatternTerminalPart;
import appeng.parts.reporting.TerminalPart;
import appeng.util.Platform;
public class CraftConfirmContainer extends AEBaseContainer {
public static ScreenHandlerType<CraftConfirmContainer> TYPE;
private static final ContainerHelper<CraftConfirmContainer, ITerminalHost> helper = new ContainerHelper<>(
CraftConfirmContainer::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static CraftConfirmContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf 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 Text myName;
public CraftConfirmContainer(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(null);
} else {
CraftingCPURecord cpu = this.cpus.get(this.getSelectedCpu());
this.setName(cpu.getName());
this.setCpuAvailableBytes(cpu.getSize());
this.setCpuCoProcessors(cpu.getProcessors());
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for (final ICraftingCPU c : cpuSet) {
boolean found = false;
for (final CraftingCPURecord ccr : this.cpus) {
if (ccr.getCpu() == c) {
found = true;
break;
}
}
final boolean matched = this.cpuMatches(c);
if (matched) {
matches++;
}
if (found == !matched) {
changed = true;
}
}
if (changed || this.cpus.size() != matches) {
this.cpus.clear();
for (final ICraftingCPU c : cpuSet) {
if (this.cpuMatches(c)) {
this.cpus.add(new CraftingCPURecord(c.getAvailableStorage(), c.getCoProcessors(), c));
}
}
this.sendCPUs();
}
this.setNoCPU(this.cpus.isEmpty());
super.detectAndSendChanges();
if (this.getJob() != null && this.getJob().isDone()) {
try {
this.result = this.getJob().get();
if (!this.result.isSimulation()) {
this.setSimulation(false);
if (this.isAutoStart()) {
this.startJob();
return;
}
} else {
this.setSimulation(true);
}
try {
final MEInventoryUpdatePacket a = new MEInventoryUpdatePacket((byte) 0);
final MEInventoryUpdatePacket b = new MEInventoryUpdatePacket((byte) 1);
final MEInventoryUpdatePacket c = this.result.isSimulation() ? new MEInventoryUpdatePacket((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.sendSystemMessage(new LiteralText("Error: " + e.toString()), Util.NIL_UUID);
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(null);
} else if (this.getSelectedCpu() != -1) {
CraftingCPURecord cpu = this.cpus.get(this.getSelectedCpu());
this.setName(cpu.getName());
this.setCpuAvailableBytes(cpu.getSize());
this.setCpuCoProcessors(cpu.getProcessors());
}
}
public void startJob() {
ScreenHandlerType<?> originalGui = null;
final IActionHost ah = this.getActionHost();
if (ah instanceof WirelessTerminalGuiObject) {
originalGui = WirelessTermContainer.TYPE;
}
if (ah instanceof TerminalPart) {
originalGui = MEMonitorableContainer.TYPE;
}
if (ah instanceof CraftingTerminalPart) {
originalGui = CraftingTermContainer.TYPE;
}
if (ah instanceof PatternTerminalPart) {
originalGui = PatternTermContainer.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 Text getName() {
return this.myName;
}
private void setName(@Nullable final Text 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;
}
}
@@ -1,255 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
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.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.MEInventoryUpdatePacket;
import appeng.helpers.ICustomNameObject;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.CraftingBlockEntity;
import appeng.util.Platform;
public class CraftingCPUContainer extends AEBaseContainer
implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject {
public static ScreenHandlerType<CraftingCPUContainer> TYPE;
private static final ContainerHelper<CraftingCPUContainer, CraftingBlockEntity> helper = new ContainerHelper<>(
CraftingCPUContainer::new, CraftingBlockEntity.class, SecurityPermissions.CRAFT);
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
.createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private Text cpuName = null;
@GuiSync(0)
public long eta = -1;
private CraftingCPUContainer(int id, final PlayerInventory ip, final CraftingBlockEntity te) {
this(TYPE, id, ip, te);
}
public CraftingCPUContainer(ScreenHandlerType<?> 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 (te instanceof CraftingBlockEntity) {
this.setCPU((ICraftingCPU) ((IAEMultiBlock) te).getCluster());
}
if (this.getNetwork() == null && Platform.isServer()) {
this.setValidContainer(false);
}
}
public static CraftingCPUContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
protected void setCPU(final ICraftingCPU c) {
if (c == this.getMonitor()) {
return;
}
if (this.getMonitor() != null) {
this.getMonitor().removeListener(this);
}
for (final Object g : this.listeners) {
if (g instanceof PlayerEntity) {
NetworkHandler.instance().sendTo(new ConfigValuePacket("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);
}
}
public void cancelCrafting() {
if (this.getMonitor() != null) {
this.getMonitor().cancel();
}
this.setEstimatedTime(-1);
}
@Override
public void removeListener(final IContainerListener c) {
super.removeListener(c);
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 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 MEInventoryUpdatePacket a = new MEInventoryUpdatePacket((byte) 0);
final MEInventoryUpdatePacket b = new MEInventoryUpdatePacket((byte) 1);
final MEInventoryUpdatePacket c = new MEInventoryUpdatePacket((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));
}
this.list.resetStatus();
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 (!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 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 Text getCustomInventoryName() {
return this.cpuName;
}
@Override
public boolean hasCustomInventoryName() {
return this.cpuName != null;
}
public long getEstimatedTime() {
return this.eta;
}
private void setEstimatedTime(final long eta) {
this.eta = eta;
}
CraftingCPUCluster getMonitor() {
return this.monitor;
}
private void setMonitor(final CraftingCPUCluster monitor) {
this.monitor = monitor;
}
IGrid getNetwork() {
return this.network;
}
private void setNetwork(final IGrid network) {
this.network = network;
}
}
@@ -1,64 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import javax.annotation.Nonnull;
import net.minecraft.text.Text;
import appeng.api.networking.crafting.ICraftingCPU;
public class CraftingCPURecord implements Comparable<CraftingCPURecord> {
private final Text 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();
}
@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;
}
Text getName() {
return this.myName;
}
int getProcessors() {
return this.processors;
}
long getSize() {
return this.size;
}
}
@@ -1,164 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
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 CraftingStatusContainer extends CraftingCPUContainer {
public static ScreenHandlerType<CraftingStatusContainer> TYPE;
private static final ContainerHelper<CraftingStatusContainer, ITerminalHost> helper = new ContainerHelper<>(
CraftingStatusContainer::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static CraftingStatusContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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 Text myName;
public CraftingStatusContainer(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();
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.noCPU = this.cpus.isEmpty();
}
super.detectAndSendChanges();
}
private boolean cpuMatches(final ICraftingCPU c) {
return c.isBusy();
}
private void sendCPUs() {
Collections.sort(this.cpus);
if (this.selectedCpu >= this.cpus.size()) {
this.selectedCpu = -1;
this.myName = null;
} else if (this.selectedCpu != -1) {
this.myName = this.cpus.get(this.selectedCpu).getName();
}
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);
}
}
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.cpus.size() > 0) {
this.selectedCpu = 0;
}
if (this.selectedCpu == -1) {
this.myName = null;
this.setCPU(null);
} else {
this.myName = this.cpus.get(this.selectedCpu).getName();
this.setCPU(this.cpus.get(this.selectedCpu).getCpu());
}
}
}
@@ -1,144 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;
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.CraftingMatrixSlot;
import appeng.container.slot.CraftingTermSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.CraftingTerminalPart;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperInvItemHandler;
public class CraftingTermContainer extends MEMonitorableContainer
implements IAEAppEngInventory, IContainerCraftingPacket {
public static ScreenHandlerType<CraftingTermContainer> TYPE;
private static final ContainerHelper<CraftingTermContainer, ITerminalHost> helper = new ContainerHelper<>(
CraftingTermContainer::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static CraftingTermContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final CraftingTerminalPart ct;
private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1);
private final CraftingMatrixSlot[] craftingSlots = new CraftingMatrixSlot[9];
private final CraftingTermSlot outputSlot;
private Recipe<CraftingInventory> currentRecipe;
public CraftingTermContainer(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
super(TYPE, id, ip, monitorable, false);
this.ct = (CraftingTerminalPart) monitorable;
final FixedItemInv 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 CraftingMatrixSlot(this, crafting, x + y * 3,
37 + x * 18, -72 + y * 18));
}
}
this.addSlot(this.outputSlot = new CraftingTermSlot(this.getPlayerInv().player, this.getActionSource(),
this.getPowerSource(), monitorable, crafting, crafting, this.output, 131, -72 + 18, this));
this.bindPlayerInventory(ip, 0, 0);
this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting));
}
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged(Inventory inventory) {
final ContainerNull cn = new ContainerNull();
final CraftingInventory ic = new CraftingInventory(cn, 3, 3);
for (int x = 0; x < 9; x++) {
ic.setStack(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(RecipeType.CRAFTING, ic, world).orElse(null);
}
if (this.currentRecipe == null) {
this.outputSlot.putStack(ItemStack.EMPTY);
} else {
final ItemStack craftingResult = this.currentRecipe.craft(ic);
this.outputSlot.putStack(craftingResult);
}
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
final ItemStack removedStack, final ItemStack newStack) {
}
@Override
public FixedItemInv getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getPlayerInventory());
}
return this.ct.getInventoryByName(name);
}
@Override
public boolean useRealItems() {
return true;
}
public Recipe<CraftingInventory> getCurrentRecipe() {
return this.currentRecipe;
}
}
@@ -1,59 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.storage.DriveBlockEntity;
public class DriveContainer extends AEBaseContainer {
public static ScreenHandlerType<DriveContainer> TYPE;
private static final ContainerHelper<DriveContainer, DriveBlockEntity> helper = new ContainerHelper<>(
DriveContainer::new, DriveBlockEntity.class);
public static DriveContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public DriveContainer(int id, final PlayerInventory ip, final DriveBlockEntity drive) {
super(TYPE, id, ip, drive, null);
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 2; x++) {
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.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);
}
}
@@ -1,132 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.FakeTypeOnlySlot;
import appeng.container.slot.OptionalTypeOnlyFakeSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.parts.automation.FormationPlanePart;
import appeng.util.Platform;
public class FormationPlaneContainer extends UpgradeableContainer {
public static ScreenHandlerType<FormationPlaneContainer> TYPE;
private static final ContainerHelper<FormationPlaneContainer, FormationPlanePart> helper = new ContainerHelper<>(
FormationPlaneContainer::new, FormationPlanePart.class, SecurityPermissions.BUILD);
public static FormationPlaneContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@GuiSync(6)
public YesNo placeMode;
public FormationPlaneContainer(int id, final PlayerInventory ip, final FormationPlanePart te) {
super(TYPE, id, ip, te);
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final FixedItemInv 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 FakeTypeOnlySlot(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlot(new OptionalTypeOnlyFakeSlot(config, this, y * 9 + x, xo, yo, x, y, y - 2));
}
}
}
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades() {
return 5;
}
@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));
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
public YesNo getPlaceMode() {
return this.placeMode;
}
private void setPlaceMode(final YesNo placeMode) {
this.placeMode = placeMode;
}
}
@@ -1,70 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.InaccessibleSlot;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.grindstone.GrinderBlockEntity;
public class GrinderContainer extends AEBaseContainer {
public static ScreenHandlerType<GrinderContainer> TYPE;
private static final ContainerHelper<GrinderContainer, GrinderBlockEntity> helper = new ContainerHelper<>(
GrinderContainer::new, GrinderBlockEntity.class);
public static GrinderContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public GrinderContainer(int id, final PlayerInventory ip, final GrinderBlockEntity grinder) {
super(TYPE, id, ip, grinder, null);
FixedItemInv inv = grinder.getInternalInventory();
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ORE, inv, 0, 12, 17,
this.getPlayerInventory()));
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ORE, inv, 1, 12 + 18, 17,
this.getPlayerInventory()));
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ORE, inv, 2, 12 + 36, 17,
this.getPlayerInventory()));
this.addSlot(new InaccessibleSlot(inv, 6, 80, 40));
this.addSlot(new OutputSlot(inv, 3, 112, 63, 2 * 16 + 15));
this.addSlot(new OutputSlot(inv, 4, 112 + 18, 63, 2 * 16 + 15));
this.addSlot(new OutputSlot(inv, 5, 112 + 36, 63, 2 * 16 + 15));
this.bindPlayerInventory(ip, 0, 176 - /* height of player inventory */82);
}
}
@@ -1,141 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.FullnessMode;
import appeng.api.config.OperationMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.storage.IOPortBlockEntity;
import appeng.util.Platform;
public class IOPortContainer extends UpgradeableContainer {
public static ScreenHandlerType<IOPortContainer> TYPE;
private static final ContainerHelper<IOPortContainer, IOPortBlockEntity> helper = new ContainerHelper<>(
IOPortContainer::new, IOPortBlockEntity.class, SecurityPermissions.BUILD);
public static IOPortContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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;
public IOPortContainer(int id, final PlayerInventory ip, final IOPortBlockEntity te) {
super(TYPE, id, ip, te);
}
@Override
protected int getHeight() {
return 166;
}
@Override
protected void setupConfig() {
int offX = 19;
int offY = 17;
final FixedItemInv cells = this.getUpgradeable().getInventoryByName("cells");
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 2; x++) {
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.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 OutputSlot(cells, 6 + x + y * 2, offX + x * 18, offY + y * 18,
RestrictedInputSlot.PlacableItemType.STORAGE_CELLS.IIcon));
}
}
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 3;
}
@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));
}
this.standardDetectAndSendChanges();
}
public FullnessMode getFullMode() {
return this.fMode;
}
private void setFullMode(final FullnessMode fMode) {
this.fMode = fMode;
}
public OperationMode getOperationMode() {
return this.opMode;
}
private void setOperationMode(final OperationMode opMode) {
this.opMode = opMode;
}
}
@@ -1,170 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.misc.InscriberRecipes;
import appeng.tile.misc.InscriberBlockEntity;
import appeng.util.Platform;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public class InscriberContainer extends UpgradeableContainer implements IProgressProvider {
public static ScreenHandlerType<InscriberContainer> TYPE;
private static final ContainerHelper<InscriberContainer, InscriberBlockEntity> helper = new ContainerHelper<>(
InscriberContainer::new, InscriberBlockEntity.class);
public static InscriberContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final InscriberBlockEntity ti;
private final Slot top;
private final Slot middle;
private final Slot bottom;
@GuiSync(2)
public int maxProcessingTime = -1;
@GuiSync(3)
public int processingTime = -1;
public InscriberContainer(int id, final PlayerInventory ip, final InscriberBlockEntity te) {
super(TYPE, id, ip, te);
this.ti = te;
FixedItemInv inv = te.getInternalInventory();
RestrictedInputSlot top = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.INSCRIBER_PLATE, inv, 0,
45, 16, this.getPlayerInventory());
top.setStackLimit(1);
this.top = this.addSlot(top);
RestrictedInputSlot bottom = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.INSCRIBER_PLATE, inv,
1, 45, 62, this.getPlayerInventory());
bottom.setStackLimit(1);
this.bottom = this.addSlot(bottom);
RestrictedInputSlot middle = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.INSCRIBER_INPUT, inv,
2, 63, 39, this.getPlayerInventory());
middle.setStackLimit(1);
this.middle = this.addSlot(middle);
this.addSlot(new OutputSlot(inv, 3, 113, 40, -1));
}
@Override
protected int getHeight() {
return 176;
}
@Override
/**
* Overridden super.setupConfig to prevent setting up the fake slots
*/
protected void setupConfig() {
this.setupUpgrades();
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 3;
}
@Override
public void detectAndSendChanges() {
this.standardDetectAndSendChanges();
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().getInvStack(0);
final ItemStack bot = this.ti.getInternalInventory().getInvStack(1);
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();
}
// 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;
}
@Override
public int getCurrentProgress() {
return this.processingTime;
}
@Override
public int getMaxProgress() {
return this.maxProcessingTime;
}
}
@@ -1,122 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
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.FakeSlot;
import appeng.container.slot.NormalSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
public class InterfaceContainer extends UpgradeableContainer {
public static ScreenHandlerType<InterfaceContainer> TYPE;
private static final ContainerHelper<InterfaceContainer, IInterfaceHost> helper = new ContainerHelper<>(
InterfaceContainer::new, IInterfaceHost.class, SecurityPermissions.BUILD);
public static InterfaceContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final DualityInterface myDuality;
@GuiSync(3)
public YesNo bMode = YesNo.NO;
@GuiSync(4)
public YesNo iTermMode = YesNo.YES;
public InterfaceContainer(int id, final PlayerInventory ip, final IInterfaceHost te) {
super(TYPE, id, ip, te.getInterfaceDuality().getHost());
this.myDuality = te.getInterfaceDuality();
for (int x = 0; x < DualityInterface.NUMBER_OF_PATTERN_SLOTS; x++) {
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.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 FakeSlot(this.myDuality.getConfig(), x, 8 + 18 * x, 35));
}
for (int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++) {
this.addSlot(new NormalSlot(this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18));
}
}
@Override
protected int getHeight() {
return 211;
}
@Override
protected void setupConfig() {
this.setupUpgrades();
}
@Override
public int availableUpgrades() {
return 1;
}
@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));
}
public YesNo getBlockingMode() {
return this.bMode;
}
private void setBlockingMode(final YesNo bMode) {
this.bMode = bMode;
}
public YesNo getInterfaceTerminalMode() {
return this.iTermMode;
}
private void setInterfaceTerminalMode(final YesNo iTermMode) {
this.iTermMode = iTermMode;
}
}
@@ -1,383 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import alexiil.mc.lib.attributes.item.FixedItemInv;
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.CompressedNBTPacket;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction;
import appeng.items.misc.EncodedPatternItem;
import appeng.parts.misc.InterfacePart;
import appeng.parts.reporting.InterfaceTerminalPart;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.InterfaceBlockEntity;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorFixedInv;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public final class InterfaceTerminalContainer extends AEBaseContainer {
public static ScreenHandlerType<InterfaceTerminalContainer> TYPE;
private static final ContainerHelper<InterfaceTerminalContainer, InterfaceTerminalPart> helper = new ContainerHelper<>(
InterfaceTerminalContainer::new, InterfaceTerminalPart.class, SecurityPermissions.BUILD);
public static InterfaceTerminalContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf 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 CompoundTag data = new CompoundTag();
public InterfaceTerminalContainer(int id, final PlayerInventory ip, final InterfaceTerminalPart 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(InterfaceBlockEntity.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.name.equals(dual.getTermName())) {
missing = true;
}
}
total++;
}
}
for (final IGridNode gn : this.grid.getMachines(InterfacePart.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.name.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.getSlotCount(); x++) {
if (this.isDifferent(inv.server.getInvStack(x), inv.client.getInvStack(x))) {
this.addItems(this.data, inv, x, 1);
}
}
}
}
if (!this.data.isEmpty()) {
try {
NetworkHandler.instance().sendTo(new CompressedNBTPacket(this.data),
(ServerPlayerEntity) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
this.data = new CompoundTag();
}
}
@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.getInvStack(slot);
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
final InventoryAdaptor playerHand = new AdaptorFixedInv(new WrapperCursorItemHandler(player.inventory));
final FixedItemInv theSlot = new WrapperFilteredItemHandler(
inv.server.getSubInv(slot, slot + 1), new PatternSlotFilter());
final InventoryAdaptor interfaceSlot = new AdaptorFixedInv(theSlot);
switch (action) {
case PICKUP_OR_SET_DOWN:
if (hasItemInHand) {
ItemStack inSlot = theSlot.getInvStack(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.getInvStack(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.getInvStack(0)));
break;
case MOVE_REGION:
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor(player);
for (int x = 0; x < inv.server.getSlotCount(); x++) {
ItemHandlerUtil.setStackInSlot(inv.server, x,
playerInvAd.addItems(inv.server.getInvStack(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 CompoundTag 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(InterfaceBlockEntity.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new InvTracker(dual, dual.getPatterns(), dual.getTermName()));
}
}
for (final IGridNode gn : this.grid.getMachines(InterfacePart.class)) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
this.diList.put(ih, new InvTracker(dual, dual.getPatterns(), dual.getTermName()));
}
}
}
}
data.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.getSlotCount());
}
}
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.areEqual(a, b);
}
private void addItems(final CompoundTag data, final InvTracker inv, final int offset, final int length) {
final String name = '=' + Long.toString(inv.which, Character.MAX_RADIX);
final CompoundTag tag = data.getCompound(name);
if (tag.isEmpty()) {
tag.putLong("sortBy", inv.sortBy);
tag.putString("un", Text.Serializer.toJson(inv.name));
}
for (int x = 0; x < length; x++) {
final CompoundTag itemNBT = new CompoundTag();
final ItemStack is = inv.server.getInvStack(x + offset);
// "update" client side.
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if (!is.isEmpty()) {
is.toTag(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 Text name;
private final FixedItemInv client;
private final FixedItemInv server;
public InvTracker(final DualityInterface dual, final FixedItemInv patterns, final Text name) {
this.server = patterns;
this.client = new AppEngInternalInventory(null, this.server.getSlotCount());
this.name = name;
this.sortBy = dual.getSortValue();
}
}
private static class PatternSlotFilter implements IAEItemFilter {
@Override
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
return true;
}
@Override
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
return !stack.isEmpty() && stack.getItem() instanceof EncodedPatternItem;
}
}
}
@@ -1,165 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.FakeTypeOnlySlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.parts.automation.LevelEmitterPart;
import appeng.util.Platform;
public class LevelEmitterContainer extends UpgradeableContainer {
public static ScreenHandlerType<LevelEmitterContainer> TYPE;
private static final ContainerHelper<LevelEmitterContainer, LevelEmitterPart> helper = new ContainerHelper<>(
LevelEmitterContainer::new, LevelEmitterPart.class, SecurityPermissions.BUILD);
public static LevelEmitterContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final LevelEmitterPart lvlEmitter;
@Environment(EnvType.CLIENT)
private TextFieldWidget textField;
@GuiSync(2)
public LevelType lvType;
@GuiSync(3)
public long EmitterValue = -1;
@GuiSync(4)
public YesNo cmType;
public LevelEmitterContainer(int id, final PlayerInventory ip, final LevelEmitterPart te) {
super(TYPE, id, ip, te);
this.lvlEmitter = te;
}
@Environment(EnvType.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;
}
@Override
protected void setupConfig() {
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
if (this.availableUpgrades() > 0) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187,
8 + 18, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
}
final FixedItemInv inv = this.getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80 + 44;
this.addSlot(new FakeTypeOnlySlot(inv, 0, x, y));
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 1;
}
@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));
}
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 YesNo getCraftingMode() {
return this.cmType;
}
@Override
public void setCraftingMode(final YesNo cmType) {
this.cmType = cmType;
}
public LevelType getLevelMode() {
return this.lvType;
}
private void setLevelMode(final LevelType lvType) {
this.lvType = lvType;
}
}
@@ -1,394 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.block.entity.BlockEntity;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
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.RestrictedInputSlot;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.MEInventoryUpdatePacket;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class MEMonitorableContainer extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {
public static ScreenHandlerType<MEMonitorableContainer> TYPE;
private static final ContainerHelper<MEMonitorableContainer, ITerminalHost> helper = new ContainerHelper<>(
MEMonitorableContainer::new, ITerminalHost.class);
public static MEMonitorableContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final RestrictedInputSlot[] cellView = new RestrictedInputSlot[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 MEMonitorableContainer(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
this(TYPE, id, ip, monitorable, true);
}
public MEMonitorableContainer(ScreenHandlerType<?> containerType, int id, PlayerInventory ip,
final ITerminalHost monitorable, final boolean bindInventory) {
super(containerType, id, ip, monitorable instanceof BlockEntity ? (BlockEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null,
monitorable instanceof IGuiItemObject ? (IGuiItemObject) monitorable : null);
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);
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.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 (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 RestrictedInputSlot(RestrictedInputSlot.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);
}
}
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);
}
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 ConfigValuePacket(set.name(), sideLocal.name()),
(ServerPlayerEntity) crafter);
}
}
}
}
if (!this.items.isEmpty()) {
try {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final MEInventoryUpdatePacket piu = new MEInventoryUpdatePacket();
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();
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();
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();
}
}
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);
}
}
}
super.onUpdate(field, oldValue, newValue);
}
@Override
public void addListener(final IContainerListener c) {
super.addListener(c);
this.queueInventory(c);
}
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof PlayerEntity && this.monitor != null) {
try {
MEInventoryUpdatePacket piu = new MEInventoryUpdatePacket();
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);
piu = new MEInventoryUpdatePacket();
piu.appendItem(send);
}
}
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
@Override
public void removeListener(final IContainerListener c) {
super.removeListener(c);
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 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 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 IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
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();
}
return list;
}
public RestrictedInputSlot getCellViewSlot(final int index) {
return this.cellView[index];
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
}
@@ -1,105 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
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;
public class MEPortableCellContainer extends MEMonitorableContainer {
public static ScreenHandlerType<MEPortableCellContainer> TYPE;
private static final ContainerHelper<MEPortableCellContainer, IPortableCell> helper = new ContainerHelper<>(
MEPortableCellContainer::new, IPortableCell.class);
public static MEPortableCellContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private double powerMultiplier = 0.5;
private final IPortableCell civ;
private int ticks = 0;
private final int slot;
public MEPortableCellContainer(int id, final PlayerInventory ip, final IPortableCell monitorable) {
this(TYPE, id, ip, monitorable);
}
protected MEPortableCellContainer(ScreenHandlerType<? extends MEPortableCellContainer> 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().getStack(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().setStack(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();
}
private double getPowerMultiplier() {
return this.powerMultiplier;
}
void setPowerMultiplier(final double powerMultiplier) {
this.powerMultiplier = powerMultiplier;
}
}
@@ -1,184 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.MolecularAssemblerPatternSlot;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.items.misc.EncodedPatternItem;
import appeng.tile.crafting.MolecularAssemblerBlockEntity;
import appeng.util.Platform;
public class MolecularAssemblerContainer extends UpgradeableContainer implements IProgressProvider {
public static ScreenHandlerType<MolecularAssemblerContainer> TYPE;
private static final ContainerHelper<MolecularAssemblerContainer, MolecularAssemblerBlockEntity> helper = new ContainerHelper<>(
MolecularAssemblerContainer::new, MolecularAssemblerBlockEntity.class);
public static MolecularAssemblerContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private static final int MAX_CRAFT_PROGRESS = 100;
private final MolecularAssemblerBlockEntity tma;
@GuiSync(4)
public int craftProgress = 0;
private Slot encodedPatternSlot;
public MolecularAssemblerContainer(int id, final PlayerInventory ip, final MolecularAssemblerBlockEntity te) {
super(TYPE, id, ip, te);
this.tma = te;
}
public boolean isValidItemForSlot(final int slotIndex, final ItemStack i) {
final FixedItemInv mac = this.getUpgradeable().getInventoryByName(MolecularAssemblerBlockEntity.INVENTORY_MAIN);
final ItemStack is = mac.getInvStack(10);
if (is.isEmpty()) {
return false;
}
if (is.getItem() instanceof EncodedPatternItem) {
final World w = this.getBlockEntity().getWorld();
final EncodedPatternItem iep = (EncodedPatternItem) is.getItem();
final ICraftingPatternDetails ph = iep.getPatternForItem(is, w);
if (ph.isCraftable()) {
return ph.isValidItemForSlot(slotIndex, i, w);
}
}
return false;
}
@Override
protected int getHeight() {
return 197;
}
@Override
protected void setupConfig() {
int offX = 29;
int offY = 30;
final FixedItemInv mac = this.getUpgradeable().getInventoryByName(MolecularAssemblerBlockEntity.INVENTORY_MAIN);
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
final MolecularAssemblerPatternSlot s = new MolecularAssemblerPatternSlot(this, mac, x + y * 3,
offX + x * 18, offY + y * 18);
this.addSlot(s);
}
}
offX = 126;
offY = 16;
encodedPatternSlot = this
.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10,
offX, offY, this.getPlayerInventory()));
this.addSlot(new OutputSlot(mac, 9, offX, offY + 32, -1));
offX = 122;
offY = 17;
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.setRedStoneMode(
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED));
}
this.craftProgress = this.tma.getCraftingProgress();
this.standardDetectAndSendChanges();
}
@Override
public int getCurrentProgress() {
return this.craftProgress;
}
@Override
public int getMaxProgress() {
return MAX_CRAFT_PROGRESS;
}
@Override
public void onSlotChange(Slot s) {
// If the pattern changes, the crafting grid slots lose validity
if (s == encodedPatternSlot) {
for (Slot otherSlot : inventorySlots) {
if (otherSlot != s && otherSlot instanceof AppEngSlot) {
((AppEngSlot) otherSlot).setIsValid(AppEngSlot.CalculatedValidity.NotAvailable);
}
}
}
}
}
@@ -1,179 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.storage.channels.IItemStorageChannel;
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.MEInventoryUpdatePacket;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class NetworkStatusContainer extends AEBaseContainer {
public static ScreenHandlerType<NetworkStatusContainer> TYPE;
private static final ContainerHelper<NetworkStatusContainer, INetworkTool> helper = new ContainerHelper<>(
NetworkStatusContainer::new, INetworkTool.class);
public static NetworkStatusContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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;
public NetworkStatusContainer(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 (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();
}
}
}
@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()));
}
try {
final MEInventoryUpdatePacket piu = new MEInventoryUpdatePacket();
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 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;
}
private void setCurrentPower(final long currentPower) {
this.currentPower = currentPower;
}
public long getMaxPower() {
return this.maxPower;
}
private void setMaxPower(final long maxPower) {
this.maxPower = maxPower;
}
public long getAverageAddition() {
return this.avgAddition;
}
private void setAverageAddition(final long avgAddition) {
this.avgAddition = avgAddition;
}
public long getPowerUsage() {
return this.powerUsage;
}
private void setPowerUsage(final long powerUsage) {
this.powerUsage = powerUsage;
}
}
@@ -1,108 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.RestrictedInputSlot;
public class NetworkToolContainer extends AEBaseContainer {
public static ScreenHandlerType<NetworkToolContainer> TYPE;
private static final ContainerHelper<NetworkToolContainer, INetworkTool> helper = new ContainerHelper<>(
NetworkToolContainer::new, INetworkTool.class);
public static NetworkToolContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final INetworkTool toolInv;
@GuiSync(1)
public boolean facadeMode;
public NetworkToolContainer(int id, final PlayerInventory ip, final INetworkTool te) {
super(TYPE, id, ip, null, null);
this.toolInv = te;
this.lockPlayerInventorySlot(ip.currentItem);
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.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);
}
public void toggleFacadeMode() {
final CompoundTag data = this.toolInv.getItemStack().getOrCreateTag();
data.putBoolean("hideFacades", !data.getBoolean("hideFacades"));
this.detectAndSendChanges();
}
@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().setStack(this.getPlayerInv().currentItem,
this.toolInv.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
if (this.isValidContainer()) {
final CompoundTag data = currentItem.getOrCreateTag();
this.setFacadeMode(data.getBoolean("hideFacades"));
}
super.detectAndSendChanges();
}
public boolean isFacadeMode() {
return this.facadeMode;
}
private void setFacadeMode(final boolean facadeMode) {
this.facadeMode = facadeMode;
}
}
@@ -1,528 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.CraftResultInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.CraftingResultSlot;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
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.ContainerNull;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.FakeCraftingMatrixSlot;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalFakeSlot;
import appeng.container.slot.PatternOutputsSlot;
import appeng.container.slot.PatternTermSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.core.sync.packets.PatternSlotPacket;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ViewCellItem;
import appeng.me.helpers.MachineSource;
import appeng.parts.reporting.PatternTerminalPart;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorFixedInv;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.item.AEItemStack;
public class PatternTermContainer extends MEMonitorableContainer
implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
public static ScreenHandlerType<PatternTermContainer> TYPE;
private static final ContainerHelper<PatternTermContainer, ITerminalHost> helper = new ContainerHelper<>(
PatternTermContainer::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static PatternTermContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PatternTerminalPart patternTerminal;
private final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1);
private final FixedItemInv crafting;
private final FakeCraftingMatrixSlot[] craftingSlots = new FakeCraftingMatrixSlot[9];
private final OptionalFakeSlot[] outputSlots = new OptionalFakeSlot[3];
private final PatternTermSlot craftSlot;
private final RestrictedInputSlot patternSlotIN;
private final RestrictedInputSlot patternSlotOUT;
private Recipe<CraftingInventory> currentRecipe;
@GuiSync(97)
public boolean craftingMode = true;
@GuiSync(96)
public boolean substitute = false;
public PatternTermContainer(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
super(TYPE, id, ip, monitorable, false);
this.patternTerminal = (PatternTerminalPart) monitorable;
final FixedItemInv patternInv = this.getPatternTerminal().getInventoryByName("pattern");
final FixedItemInv output = this.getPatternTerminal().getInventoryByName("output");
this.crafting = this.getPatternTerminal().getInventoryByName("crafting");
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlot(this.craftingSlots[x + y * 3] = new FakeCraftingMatrixSlot(this.crafting, x + y * 3,
18 + x * 18, -76 + y * 18));
}
}
this.addSlot(this.craftSlot = new PatternTermSlot(ip.player, this.getActionSource(), this.getPowerSource(),
monitorable, this.crafting, patternInv, this.cOut, 110, -76 + 18, this, 2, this));
this.craftSlot.setIIcon(-1);
for (int y = 0; y < 3; y++) {
this.addSlot(this.outputSlots[y] = new PatternOutputsSlot(output, this, y, 110, -76 + y * 18, 0, 0, 1));
this.outputSlots[y].setRenderDisabled(false);
this.outputSlots[y].setIIcon(-1);
}
this.addSlot(this.patternSlotIN = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.BLANK_PATTERN,
patternInv, 0, 147, -72 - 9, this.getPlayerInventory()));
this.addSlot(this.patternSlotOUT = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ENCODED_PATTERN,
patternInv, 1, 147, -72 + 34, this.getPlayerInventory()));
this.patternSlotOUT.setStackLimit(1);
this.bindPlayerInventory(ip, 0, 0);
this.updateOrderOfOutputSlots();
}
private void updateOrderOfOutputSlots() {
if (!this.isCraftingMode()) {
this.craftSlot.xPos = -9000;
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = this.outputSlots[y].getX();
}
} else {
this.craftSlot.xPos = this.craftSlot.getX();
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = -9000;
}
}
}
@Override
public void putStackInSlot(int slotID, ItemStack stack) {
super.putStackInSlot(slotID, stack);
this.getAndUpdateOutput();
}
private ItemStack getAndUpdateOutput() {
final World world = this.getPlayerInv().player.world;
final CraftingInventory ic = new CraftingInventory(this, 3, 3);
for (int x = 0; x < ic.size(); x++) {
ic.setStack(x, this.crafting.getInvStack(x));
}
if (this.currentRecipe == null || !this.currentRecipe.matches(ic, world)) {
this.currentRecipe = world.getRecipeManager().getRecipe(RecipeType.CRAFTING, ic, world).orElse(null);
}
final ItemStack is;
if (this.currentRecipe == null) {
is = ItemStack.EMPTY;
} else {
is = this.currentRecipe.craft(ic);
}
this.cOut.setInvStack(0, is);
return is;
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
final ItemStack removedStack, final ItemStack newStack) {
}
public void encode() {
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (!output.isEmpty() && !this.isPattern(output)) {
return;
} // if nothing is there we should snag a new pattern.
else if (output.isEmpty()) {
output = this.patternSlotIN.getStack();
if (output.isEmpty() || !this.isPattern(output)) {
return; // no blanks.
}
// remove one, and clear the input slot.
output.setCount(output.getCount() - 1);
if (output.getCount() == 0) {
this.patternSlotIN.putStack(ItemStack.EMPTY);
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
output = maybePattern.get();
this.patternSlotOUT.putStack(output);
}
}
// encode the slot.
final CompoundTag encodedValue = new CompoundTag();
final ListTag tagIn = new ListTag();
final ListTag tagOut = new ListTag();
for (final ItemStack i : in) {
tagIn.add(this.createItemTag(i));
}
for (final ItemStack i : out) {
tagOut.add(this.createItemTag(i));
}
encodedValue.put("in", tagIn);
encodedValue.put("out", tagOut);
encodedValue.putBoolean("crafting", this.isCraftingMode());
encodedValue.putBoolean("substitute", this.isSubstitute());
output.setTag(encodedValue);
}
private ItemStack[] getInputs() {
final ItemStack[] input = new ItemStack[9];
boolean hasValue = false;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty()) {
hasValue = true;
}
}
if (hasValue) {
return input;
}
return null;
}
private ItemStack[] getOutputs() {
if (this.isCraftingMode()) {
final ItemStack out = this.getAndUpdateOutput();
if (!out.isEmpty() && out.getCount() > 0) {
return new ItemStack[] { out };
}
} else {
final List<ItemStack> list = new ArrayList<>(3);
boolean hasValue = false;
for (final OptionalFakeSlot outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() > 0) {
list.add(out);
hasValue = true;
}
}
if (hasValue) {
return list.toArray(new ItemStack[list.size()]);
}
}
return null;
}
private boolean isPattern(final ItemStack output) {
if (output.isEmpty()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return isPattern;
}
private INBT createItemTag(final ItemStack i) {
final CompoundTag c = new CompoundTag();
if (!i.isEmpty()) {
i.toTag(c);
}
return c;
}
@Override
public boolean isSlotEnabled(final int idx) {
if (idx == 1) {
return Platform.isServer() ? !this.getPatternTerminal().isCraftingRecipe() : !this.isCraftingMode();
} else if (idx == 2) {
return Platform.isServer() ? this.getPatternTerminal().isCraftingRecipe() : this.isCraftingMode();
} else {
return false;
}
}
public void craftOrGetItem(final PatternSlotPacket packetPatternSlot) {
if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) {
final IAEItemStack out = packetPatternSlot.slotItem.copy();
InventoryAdaptor inv = new AdaptorFixedInv(
new WrapperCursorItemHandler(this.getPlayerInv().player.inventory));
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(this.getPlayerInv().player);
if (packetPatternSlot.shift) {
inv = playerInv;
}
if (!inv.simulateAdd(out.createItemStack()).isEmpty()) {
return;
}
final IAEItemStack extracted = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(),
out, this.getActionSource());
final PlayerEntity p = this.getPlayerInv().player;
if (extracted != null) {
inv.addItems(extracted.createItemStack());
if (p instanceof ServerPlayerEntity) {
this.updateHeld((ServerPlayerEntity) p);
}
this.detectAndSendChanges();
return;
}
final CraftingInventory ic = new CraftingInventory(new ContainerNull(), 3, 3);
final CraftingInventory real = new CraftingInventory(new ContainerNull(), 3, 3);
for (int x = 0; x < 9; x++) {
ic.setStack(x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY
: packetPatternSlot.pattern[x].createItemStack());
}
final Recipe<CraftingInventory> r = p.world.getRecipeManager().getRecipe(RecipeType.CRAFTING, ic, p.world)
.orElse(null);
if (r == null) {
return;
}
final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal()
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IItemList<IAEItemStack> all = storage.getStorageList();
final ItemStack is = r.craft(ic);
for (int x = 0; x < ic.size(); x++) {
if (!ic.getStack(x).isEmpty()) {
final ItemStack pulled = Platform.extractItemsByRecipe(this.getPowerSource(),
this.getActionSource(), storage, p.world, r, is, ic, ic.getStack(x), x, all,
Actionable.MODULATE, ViewCellItem.createFilter(this.getViewCells()));
real.setStack(x, pulled);
}
}
final Recipe<CraftingInventory> rr = p.world.getRecipeManager()
.getRecipe(RecipeType.CRAFTING, real, p.world).orElse(null);
if (rr == r && Platform.itemComparisons().isSameItem(rr.craft(real), is)) {
final CraftResultInventory craftingResult = new CraftResultInventory();
craftingResult.setRecipeUsed(rr);
final CraftingResultSlot sc = new CraftingResultSlot(p, real, craftingResult, 0, 0, 0);
sc.onTake(p, is);
for (int x = 0; x < real.size(); x++) {
final ItemStack failed = playerInv.addItems(real.getStack(x));
if (!failed.isEmpty()) {
p.dropItem(failed, false);
}
}
inv.addItems(is);
if (p instanceof ServerPlayerEntity) {
this.updateHeld((ServerPlayerEntity) p);
}
this.detectAndSendChanges();
} else {
for (int x = 0; x < real.size(); x++) {
final ItemStack failed = real.getStack(x);
if (!failed.isEmpty()) {
this.getCellInventory().injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE,
new MachineSource(this.getPatternTerminal()));
}
}
}
}
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isServer()) {
if (this.isCraftingMode() != this.getPatternTerminal().isCraftingRecipe()) {
this.setCraftingMode(this.getPatternTerminal().isCraftingRecipe());
this.updateOrderOfOutputSlots();
}
this.substitute = this.patternTerminal.isSubstitution();
}
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
super.onUpdate(field, oldValue, newValue);
if (field.equals("craftingMode")) {
this.getAndUpdateOutput();
this.updateOrderOfOutputSlots();
}
}
@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
for (final Slot slot : this.inventorySlots) {
if (slot instanceof OptionalFakeSlot || slot instanceof FakeCraftingMatrixSlot) {
listener.sendSlotContents(this, slot.slotNumber, slot.getStack());
}
}
if (listener instanceof ServerPlayerEntity) {
((ServerPlayerEntity) listener).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
if (s == this.craftSlot && Platform.isClient()) {
this.getAndUpdateOutput();
}
}
public void clear() {
for (final Slot s : this.craftingSlots) {
s.putStack(ItemStack.EMPTY);
}
for (final Slot s : this.outputSlots) {
s.putStack(ItemStack.EMPTY);
}
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
@Override
public FixedItemInv getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getPlayerInventory());
}
return this.getPatternTerminal().getInventoryByName(name);
}
@Override
public boolean useRealItems() {
return false;
}
public void toggleSubstitute() {
this.substitute = !this.substitute;
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
public boolean isCraftingMode() {
return this.craftingMode;
}
private void setCraftingMode(final boolean craftingMode) {
this.craftingMode = craftingMode;
}
public PatternTerminalPart getPatternTerminal() {
return this.patternTerminal;
}
private boolean isSubstitute() {
return this.substitute;
}
public void setSubstitute(final boolean substitute) {
this.substitute = substitute;
}
}
@@ -1,101 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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 PriorityContainer extends AEBaseContainer {
public static ScreenHandlerType<PriorityContainer> TYPE;
private static final ContainerHelper<PriorityContainer, IPriorityHost> helper = new ContainerHelper<>(
PriorityContainer::new, IPriorityHost.class, SecurityPermissions.BUILD);
public static PriorityContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final IPriorityHost priHost;
@Environment(EnvType.CLIENT)
private TextFieldWidget textField;
@GuiSync(2)
public long PriorityValue = -1;
public PriorityContainer(int id, final PlayerInventory ip, final IPriorityHost te) {
super(TYPE, id, ip, (BlockEntity) (te instanceof BlockEntity ? te : null),
(IPart) (te instanceof IPart ? te : null));
this.priHost = te;
}
@Environment(EnvType.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;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
this.verifyPermissions(SecurityPermissions.BUILD, false);
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));
}
}
super.onUpdate(field, oldValue, newValue);
}
public IPriorityHost getPriorityHost() {
return this.priHost;
}
}
@@ -1,56 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.qnb.QuantumBridgeBlockEntity;
public class QNBContainer extends AEBaseContainer {
public static ScreenHandlerType<QNBContainer> TYPE;
private static final ContainerHelper<QNBContainer, QuantumBridgeBlockEntity> helper = new ContainerHelper<>(
QNBContainer::new, QuantumBridgeBlockEntity.class, SecurityPermissions.BUILD);
public static QNBContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public QNBContainer(int id, final PlayerInventory ip, final QuantumBridgeBlockEntity quantumBridge) {
super(TYPE, id, ip, quantumBridge, null);
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.QE_SINGULARITY,
quantumBridge.getInternalInventory(), 0, 80, 37, this.getPlayerInventory())).setStackLimit(1));
this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82);
}
}
@@ -1,167 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.items.contents.QuartzKnifeObj;
import appeng.items.materials.MaterialItem;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
public class QuartzKnifeContainer extends AEBaseContainer {
public static ScreenHandlerType<QuartzKnifeContainer> TYPE;
private static final ContainerHelper<QuartzKnifeContainer, QuartzKnifeObj> helper = new ContainerHelper<>(
QuartzKnifeContainer::new, QuartzKnifeObj.class);
public static QuartzKnifeContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final QuartzKnifeObj toolInv;
private final FixedItemInv inSlot = new AppEngInternalInventory(null, 1, 1);
private String myName = "";
public QuartzKnifeContainer(int id, final PlayerInventory ip, final QuartzKnifeObj te) {
super(TYPE, id, ip, null, null);
this.toolInv = te;
this.addSlot(
new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip));
this.addSlot(new QuartzKniveSlot(this.inSlot, 0, 134, 44, -1));
this.lockPlayerInventorySlot(ip.currentItem);
this.bindPlayerInventory(ip, 0, 184 - /* height of player inventory */82);
}
public void setName(final String value) {
this.myName = value;
}
@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().setStack(this.getPlayerInv().currentItem,
this.toolInv.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
super.detectAndSendChanges();
}
@Override
public void onContainerClosed(final PlayerEntity par1PlayerEntity) {
if (this.inSlot.getInvStack(0) != null) {
par1PlayerEntity.dropItem(this.inSlot.getInvStack(0), false);
}
}
private class QuartzKniveSlot extends OutputSlot {
QuartzKniveSlot(FixedItemInv a, int b, int c, int d, int i) {
super(a, b, c, d, i);
}
@Override
public ItemStack getStack() {
final FixedItemInv baseInv = this.getItemHandler();
final ItemStack input = baseInv.getInvStack(0);
if (input == ItemStack.EMPTY) {
return ItemStack.EMPTY;
}
if (RestrictedInputSlot.isMetalIngot(input)) {
if (QuartzKnifeContainer.this.myName.length() > 0) {
return AEApi.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack -> {
final CompoundTag compound = namePressStack.getOrCreateTag();
compound.putString(MaterialItem.TAG_INSCRIBE_NAME, QuartzKnifeContainer.this.myName);
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
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 = QuartzKnifeContainer.this.toolInv.getItemStack();
final ItemStack before = item.copy();
item.damage(1, QuartzKnifeContainer.this.getPlayerInv().player, p -> {
QuartzKnifeContainer.this.getPlayerInv().setStack(
QuartzKnifeContainer.this.getPlayerInv().currentItem, ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(
QuartzKnifeContainer.this.getPlayerInv().player, before, null));
});
QuartzKnifeContainer.this.detectAndSendChanges();
}
}
}
}
}
@@ -1,182 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
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.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.SecurityStationBlockEntity;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public class SecurityStationContainer extends MEMonitorableContainer implements IAEAppEngInventory {
public static ScreenHandlerType<SecurityStationContainer> TYPE;
private static final ContainerHelper<SecurityStationContainer, ITerminalHost> helper = new ContainerHelper<>(
SecurityStationContainer::new, ITerminalHost.class, SecurityPermissions.SECURITY);
private final RestrictedInputSlot configSlot;
private final AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory(this, 2);
private final RestrictedInputSlot wirelessIn;
private final OutputSlot wirelessOut;
private final SecurityStationBlockEntity securityBox;
@GuiSync(0)
public int permissionMode = 0;
public SecurityStationContainer(int id, final PlayerInventory ip, final ITerminalHost monitorable) {
super(TYPE, id, ip, monitorable, false);
this.securityBox = (SecurityStationBlockEntity) monitorable;
this.addSlot(this.configSlot = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.BIOMETRIC_CARD,
this.securityBox.getConfigSlot(), 0, 37, -33, ip));
this.addSlot(this.wirelessIn = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.ENCODABLE_ITEM,
this.wirelessEncoder, 0, 212, 10, ip));
this.addSlot(this.wirelessOut = new OutputSlot(this.wirelessEncoder, 1, 212, 68, -1));
this.bindPlayerInventory(ip, 0, 0);
}
public static SecurityStationContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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);
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);
this.setPermissionMode(0);
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()));
}
}
this.updatePowerStatus();
super.detectAndSendChanges();
}
@Override
public void onContainerClosed(final PlayerEntity player) {
super.onContainerClosed(player);
if (this.wirelessIn.getHasStack()) {
player.dropItem(this.wirelessIn.getStack(), false);
}
if (this.wirelessOut.getHasStack()) {
player.dropItem(this.wirelessOut.getStack(), false);
}
}
@Override
public void saveChanges() {
// :P
}
@Override
public void onChangeInventory(final FixedItemInv 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();
}
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()), "");
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());
}
}
}
}
}
public int getPermissionMode() {
return this.permissionMode;
}
private void setPermissionMode(final int permissionMode) {
this.permissionMode = permissionMode;
}
}
@@ -1,68 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.slot.NormalSlot;
import appeng.tile.storage.SkyChestBlockEntity;
public class SkyChestContainer extends AEBaseContainer {
public static ScreenHandlerType<SkyChestContainer> TYPE;
private static final ContainerHelper<SkyChestContainer, SkyChestBlockEntity> helper = new ContainerHelper<>(
SkyChestContainer::new, SkyChestBlockEntity.class);
private final SkyChestBlockEntity chest;
public SkyChestContainer(int id, final PlayerInventory ip, final SkyChestBlockEntity 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 NormalSlot(this.chest.getInternalInventory(), y * 9 + x, 8 + 18 * x, 24 + 18 * y));
}
}
this.chest.openInventory(ip.player);
this.bindPlayerInventory(ip, 0, 195 - /* height of player inventory */82);
}
public static SkyChestContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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);
}
}
@@ -1,155 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
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.slot.OutputSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.spatial.SpatialIOPortBlockEntity;
import appeng.util.Platform;
public class SpatialIOPortContainer extends AEBaseContainer {
public static ScreenHandlerType<SpatialIOPortContainer> TYPE;
private static final ContainerHelper<SpatialIOPortContainer, SpatialIOPortBlockEntity> helper = new ContainerHelper<>(
SpatialIOPortContainer::new, SpatialIOPortBlockEntity.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(31)
public int xSize;
@GuiSync(32)
public int ySize;
@GuiSync(33)
public int zSize;
public SpatialIOPortContainer(int id, final PlayerInventory ip, final SpatialIOPortBlockEntity spatialIOPort) {
super(TYPE, id, ip, spatialIOPort, null);
if (Platform.isServer()) {
this.network = spatialIOPort.getGridNode(AEPartLocation.INTERNAL).getGrid();
}
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.SPATIAL_STORAGE_CELLS,
spatialIOPort.getInternalInventory(), 0, 52, 48, this.getPlayerInventory()));
this.addSlot(new OutputSlot(spatialIOPort.getInternalInventory(), 1, 113, 48,
RestrictedInputSlot.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon));
this.bindPlayerInventory(ip, 0, 197 - /* height of player inventory */82);
}
public static SpatialIOPortContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
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 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;
}
}
}
}
super.detectAndSendChanges();
}
public long getCurrentPower() {
return this.currentPower;
}
private void setCurrentPower(final long currentPower) {
this.currentPower = currentPower;
}
public long getMaxPower() {
return this.maxPower;
}
private void setMaxPower(final long maxPower) {
this.maxPower = maxPower;
}
public long getRequiredPower() {
return this.reqPower;
}
private void setRequiredPower(final long reqPower) {
this.reqPower = reqPower;
}
public long getEfficency() {
return this.eff;
}
private void setEfficency(final long eff) {
this.eff = eff;
}
}
@@ -1,190 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import java.util.Iterator;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.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.FakeTypeOnlySlot;
import appeng.container.slot.OptionalTypeOnlyFakeSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.parts.misc.StorageBusPart;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.iterators.NullIterator;
public class StorageBusContainer extends UpgradeableContainer {
public static ScreenHandlerType<StorageBusContainer> TYPE;
private static final ContainerHelper<StorageBusContainer, StorageBusPart> helper = new ContainerHelper<>(
StorageBusContainer::new, StorageBusPart.class, SecurityPermissions.BUILD);
public static StorageBusContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final StorageBusPart storageBus;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public StorageBusContainer(int id, final PlayerInventory ip, final StorageBusPart te) {
super(TYPE, id, ip, te);
this.storageBus = te;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final FixedItemInv 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 FakeTypeOnlySlot(config, y * 9 + x, xo + x * 18, yo + y * 18));
} else {
this.addSlot(new OptionalTypeOnlyFakeSlot(config, this, y * 9 + x, xo, yo, x, y, y - 2));
}
}
}
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades() {
return 5;
}
@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));
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
public void clear() {
ItemHandlerUtil.clear(this.getUpgradeable().getInventoryByName("config"));
this.detectAndSendChanges();
}
public void partition() {
final FixedItemInv inv = this.getUpgradeable().getInventoryByName("config");
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();
}
for (int x = 0; x < inv.getSlotCount(); 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();
}
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
}
@@ -1,301 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.parts.IPart;
import appeng.api.util.IConfigManager;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.FakeTypeOnlySlot;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalFakeSlot;
import appeng.container.slot.OptionalTypeOnlyFakeSlot;
import appeng.container.slot.RestrictedInputSlot;
import appeng.items.contents.NetworkToolViewer;
import appeng.items.tools.NetworkToolItem;
import appeng.parts.automation.ExportBusPart;
import appeng.util.Platform;
public class UpgradeableContainer extends AEBaseContainer implements IOptionalSlotHost {
public static ScreenHandlerType<UpgradeableContainer> TYPE;
private static final ContainerHelper<UpgradeableContainer, IUpgradeableHost> helper = new ContainerHelper<>(
UpgradeableContainer::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
public static UpgradeableContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
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;
public UpgradeableContainer(int id, final PlayerInventory ip, final IUpgradeableHost te) {
this(TYPE, id, ip, te);
}
public UpgradeableContainer(ScreenHandlerType<?> containerType, int id, final PlayerInventory ip,
final IUpgradeableHost te) {
super(containerType, id, ip, (BlockEntity) (te instanceof BlockEntity ? te : null),
(IPart) (te instanceof IPart ? te : null));
this.upgradeable = te;
World w = null;
int xCoord = 0;
int yCoord = 0;
int zCoord = 0;
if (te instanceof BlockEntity) {
final BlockEntity myTile = (BlockEntity) te;
w = myTile.getWorld();
xCoord = myTile.getPos().getX();
yCoord = myTile.getPos().getY();
zCoord = myTile.getPos().getZ();
}
if (te instanceof IPart) {
final BlockEntity mk = te.getTile();
w = mk.getWorld();
xCoord = mk.getPos().getX();
yCoord = mk.getPos().getY();
zCoord = mk.getPos().getZ();
}
final Inventory pi = this.getPlayerInv();
for (int x = 0; x < pi.size(); x++) {
final ItemStack pii = pi.getStack(x);
if (!pii.isEmpty() && pii.getItem() instanceof NetworkToolItem) {
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 RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES,
this.tbInventory.getInternalInventory(), u + v * 3, 186 + u * 18,
this.getHeight() - 82 + v * 18, this.getPlayerInventory())).setPlayerSide());
}
}
}
this.setupConfig();
this.bindPlayerInventory(ip, 0, this.getHeight() - /* height of player inventory */82);
}
public boolean hasToolbox() {
return this.tbInventory != null;
}
protected int getHeight() {
return 184;
}
protected void setupConfig() {
this.setupUpgrades();
final FixedItemInv inv = this.getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80;
this.addSlot(new FakeTypeOnlySlot(inv, 0, x, y));
if (this.supportCapacity()) {
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 1, x, y, -1, 0, 1));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 2, x, y, 1, 0, 1));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 3, x, y, 0, -1, 1));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 4, x, y, 0, 1, 1));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 5, x, y, -1, -1, 2));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 6, x, y, 1, -1, 2));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 7, x, y, -1, 1, 2));
this.addSlot(new OptionalTypeOnlyFakeSlot(inv, this, 8, x, y, 1, 1, 2));
}
}
protected void setupUpgrades() {
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
if (this.availableUpgrades() > 0) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 1) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187,
8 + 18, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 2) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
}
if (this.availableUpgrades() > 3) {
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
}
}
protected boolean supportCapacity() {
return true;
}
public int availableUpgrades() {
return 4;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
final IConfigManager cm = this.getUpgradeable().getConfigManager();
this.loadSettingsFromHost(cm);
}
this.checkToolbox();
for (final Object o : this.inventorySlots) {
if (o instanceof OptionalFakeSlot) {
final OptionalFakeSlot fs = (OptionalFakeSlot) o;
if (!fs.isSlotEnabled() && !fs.getDisplayStack().isEmpty()) {
fs.clearStack();
}
}
}
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 ExportBusPart) {
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().getStack(this.tbSlot);
if (currentItem != this.tbInventory.getItemStack()) {
if (!currentItem.isEmpty()) {
if (ItemStack.areItemsEqual(this.tbInventory.getItemStack(), currentItem)) {
this.getPlayerInv().setStack(this.tbSlot, this.tbInventory.getItemStack());
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
}
}
protected void standardDetectAndSendChanges() {
super.detectAndSendChanges();
}
@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;
}
return false;
}
public FuzzyMode getFuzzyMode() {
return this.fzMode;
}
public void setFuzzyMode(final FuzzyMode fzMode) {
this.fzMode = fzMode;
}
public YesNo getCraftingMode() {
return this.cMode;
}
public void setCraftingMode(final YesNo cMode) {
this.cMode = cMode;
}
public RedstoneMode getRedStoneMode() {
return this.rsMode;
}
public void setRedStoneMode(final RedstoneMode rsMode) {
this.rsMode = rsMode;
}
public SchedulingMode getSchedulingMode() {
return this.schedulingMode;
}
private void setSchedulingMode(final SchedulingMode schedulingMode) {
this.schedulingMode = schedulingMode;
}
protected IUpgradeableHost getUpgradeable() {
return this.upgradeable;
}
}
@@ -1,90 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.RestrictedInputSlot;
import appeng.tile.misc.VibrationChamberBlockEntity;
import appeng.util.Platform;
public class VibrationChamberContainer extends AEBaseContainer implements IProgressProvider {
public static ScreenHandlerType<VibrationChamberContainer> TYPE;
private static final ContainerHelper<VibrationChamberContainer, VibrationChamberBlockEntity> helper = new ContainerHelper<>(
VibrationChamberContainer::new, VibrationChamberBlockEntity.class);
public static VibrationChamberContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final VibrationChamberBlockEntity vibrationChamber;
@GuiSync(0)
public int burnSpeed = 0;
@GuiSync(1)
public int remainingBurnTime = 0;
public VibrationChamberContainer(int id, final PlayerInventory ip,
final VibrationChamberBlockEntity vibrationChamber) {
super(TYPE, id, ip, vibrationChamber, null);
this.vibrationChamber = vibrationChamber;
this.addSlot(new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.FUEL,
vibrationChamber.getInternalInventory(), 0, 80, 37, this.getPlayerInventory()));
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();
}
super.detectAndSendChanges();
}
@Override
public int getCurrentProgress() {
return this.burnSpeed;
}
public int getRemainingBurnTime() {
return this.remainingBurnTime;
}
@Override
public int getMaxProgress() {
return VibrationChamberBlockEntity.MAX_BURN_SPEED;
}
}
@@ -1,89 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.RestrictedInputSlot;
import appeng.core.AEConfig;
import appeng.tile.networking.WirelessBlockEntity;
public class WirelessContainer extends AEBaseContainer {
public static ScreenHandlerType<WirelessContainer> TYPE;
private static final ContainerHelper<WirelessContainer, WirelessBlockEntity> helper = new ContainerHelper<>(
WirelessContainer::new, WirelessBlockEntity.class, SecurityPermissions.BUILD);
public static WirelessContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final RestrictedInputSlot boosterSlot;
@GuiSync(1)
public long range = 0;
@GuiSync(2)
public long drain = 0;
public WirelessContainer(int id, final PlayerInventory ip, final WirelessBlockEntity te) {
super(TYPE, id, ip, te, null);
this.addSlot(this.boosterSlot = new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.RANGE_BOOSTER,
te.getInternalInventory(), 0, 80, 47, this.getPlayerInventory()));
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();
this.setRange((long) (10 * AEConfig.instance().wireless_getMaxRange(boosters)));
this.setDrain((long) (100 * AEConfig.instance().wireless_getPowerDrain(boosters)));
super.detectAndSendChanges();
}
public long getRange() {
return this.range;
}
private void setRange(final long range) {
this.range = range;
}
public long getDrain() {
return this.drain;
}
private void setDrain(final long drain) {
this.drain = drain;
}
}
@@ -1,69 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.container.ContainerLocator;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
public class WirelessTermContainer extends MEPortableCellContainer {
public static ScreenHandlerType<WirelessTermContainer> TYPE;
private static final ContainerHelper<WirelessTermContainer, WirelessTerminalGuiObject> helper = new ContainerHelper<>(
WirelessTermContainer::new, WirelessTerminalGuiObject.class);
public static WirelessTermContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
public WirelessTermContainer(int id, final PlayerInventory ip, final WirelessTerminalGuiObject gui) {
super(TYPE, id, ip, gui);
this.wirelessTerminalGUIObject = gui;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (!this.wirelessTerminalGUIObject.rangeCheck()) {
if (Platform.isServer() && this.isValidContainer()) {
this.getPlayerInv().player.sendSystemMessage(PlayerMessages.OutOfRange.get(), Util.NIL_UUID);
}
this.setValidContainer(false);
} else {
this.setPowerMultiplier(
AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange()));
}
}
}
@@ -16,20 +16,20 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.guisync;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
package appeng.container.interfaces;
/**
* Annotates that this field should be synchronized between the server and
* client. Requires the field to be public.
* Any item providing a GUI and depending on an exact inventory slot.
*
* This interface is likely a volatile one until a general GUI refactoring
* occurred. Use it with care and expect changes.
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GuiSync {
int value();
public interface IInventorySlotAware {
/**
* This is needed to select the correct slot index.
*
* @return the inventory index of this portable cell.
*/
int getInventorySlot();
}
@@ -1,49 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.interfaces;
import appeng.client.gui.widgets.ProgressBar;
/**
* This interface provides the data for anything simulating a progress.
*
* Its main use is in combination with the {@link ProgressBar}, which ensures to
* scale it to a percentage of 0 to 100.
*/
public interface IProgressProvider {
/**
* The current value of the progress. It should cover a range from 0 to the max
* progress
*
* @return An int representing the current progress
*/
int getCurrentProgress();
/**
* The max value the progress.
*
* It is not limited to a value of 100 and can be scaled to fit the current
* needs. For example scaled down to decrease or scaled up to increase the
* precision.
*
* @return An int representing the max progress
*/
int getMaxProgress();
}
@@ -1,145 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
import net.minecraftforge.fml.hooks.BasicEventHooks;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperInvItemHandler;
public class AppEngCraftingSlot extends AppEngSlot {
/**
* The craft matrix inventory linked to this result slot.
*/
private final FixedItemInv craftMatrix;
/**
* The player that is using the GUI where this slot resides.
*/
private final PlayerEntity thePlayer;
/**
* The number of items that have been crafted so far. Gets passed to
* ItemStack.onCrafting before being reset.
*/
private int amountCrafted;
public AppEngCraftingSlot(final PlayerEntity par1PlayerEntity, final FixedItemInv par2IInventory,
final FixedItemInv par3IInventory, final int par4, final int par5, final int par6) {
super(par3IInventory, par4, par5, par6);
this.thePlayer = par1PlayerEntity;
this.craftMatrix = par2IInventory;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the
* armor slots.
*/
@Override
public boolean isItemValid(final ItemStack par1ItemStack) {
return false;
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not
* ore and wood. Typically increases an internal count then calls
* onCrafting(item).
*/
@Override
protected void onCrafting(final ItemStack par1ItemStack, final int par2) {
this.amountCrafted += par2;
this.onCrafting(par1ItemStack);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not
* ore and wood.
*/
@Override
protected void onCrafting(final ItemStack par1ItemStack) {
par1ItemStack.onCrafting(this.thePlayer.world, this.thePlayer, this.amountCrafted);
this.amountCrafted = 0;
}
@Override
public ItemStack onTake(final PlayerEntity playerIn, final ItemStack stack) {
BasicEventHooks.firePlayerCraftingEvent(playerIn, stack, new WrapperInvItemHandler(this.craftMatrix));
this.onCrafting(stack);
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn);
final CraftingInventory ic = new CraftingInventory(this.getContainer(), 3, 3);
for (int x = 0; x < this.craftMatrix.getSlotCount(); x++) {
ic.setStack(x, this.craftMatrix.getInvStack(x));
}
final DefaultedList<ItemStack> aitemstack = this.getRemainingItems(ic, playerIn.world);
ItemHandlerUtil.copy(ic, this.craftMatrix, false);
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
for (int i = 0; i < aitemstack.size(); ++i) {
final ItemStack itemstack1 = this.craftMatrix.getInvStack(i);
final ItemStack itemstack2 = aitemstack.get(i);
if (!itemstack1.isEmpty()) {
this.craftMatrix.extractItem(i, 1, false);
}
if (!itemstack2.isEmpty()) {
if (this.craftMatrix.getInvStack(i).isEmpty()) {
ItemHandlerUtil.setStackInSlot(this.craftMatrix, i, itemstack2);
} else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) {
this.thePlayer.dropItem(itemstack2, false);
}
}
}
return stack;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the
* second int arg. Returns the new stack.
*/
@Override
public ItemStack decrStackSize(final int par1) {
if (this.getHasStack()) {
this.amountCrafted += Math.min(par1, this.getStack().getCount());
}
return super.decrStackSize(par1);
}
// TODO: This is really hacky and NEEDS to be solved with a full container/gui
// refactoring.
protected DefaultedList<ItemStack> getRemainingItems(CraftingInventory ic, World world) {
return world.getRecipeManager().getRecipe(RecipeType.CRAFTING, ic, world)
.map(iCraftingRecipe -> iCraftingRecipe.getRemainingItems(ic))
.orElse(DefaultedList.withSize(9, ItemStack.EMPTY));
}
}
@@ -1,246 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import appeng.container.AEBaseContainer;
import appeng.util.helpers.ItemHandlerUtil;
public class AppEngSlot extends Slot {
private static Inventory emptyInventory = new Inventory(0);
private final FixedItemInv itemHandler;
private final int index;
private final int defX;
private final int defY;
private boolean isDraggable = true;
private boolean isPlayerSide = false;
private AEBaseContainer myContainer = null;
private int IIcon = -1;
private CalculatedValidity isValid;
private boolean isDisplay = false;
public AppEngSlot(final FixedItemInv inv, final int idx, final int x, final int y) {
super(emptyInventory, idx, x, y);
this.itemHandler = inv;
this.index = idx;
this.defX = x;
this.defY = y;
this.setIsValid(CalculatedValidity.NotAvailable);
}
public Slot setNotDraggable() {
this.setDraggable(false);
return this;
}
public Slot setPlayerSide() {
this.isPlayerSide = true;
return this;
}
public String getTooltip() {
return null;
}
public void clearStack() {
ItemHandlerUtil.setStackInSlot(this.itemHandler, this.index, ItemStack.EMPTY);
}
@Override
public boolean isItemValid(@Nonnull final ItemStack par1ItemStack) {
if (this.isSlotEnabled()) {
return this.itemHandler.isItemValid(this.index, par1ItemStack);
}
return false;
}
@Override
@Nonnull
public ItemStack getStack() {
if (!this.isSlotEnabled()) {
return ItemStack.EMPTY;
}
if (this.itemHandler.getSlotCount() <= this.getSlotIndex()) {
return ItemStack.EMPTY;
}
if (this.isDisplay()) {
this.setDisplay(false);
return this.getDisplayStack();
}
return this.itemHandler.getInvStack(this.index);
}
@Override
public void putStack(final ItemStack stack) {
if (this.isSlotEnabled()) {
ItemHandlerUtil.setStackInSlot(this.itemHandler, this.index, stack);
this.onSlotChanged();
}
}
private void notifyContainerSlotChanged() {
if (this.getContainer() != null) {
this.getContainer().onSlotChange(this);
}
}
public FixedItemInv getItemHandler() {
return this.itemHandler;
}
@Override
public void onSlotChanged() {
super.onSlotChanged();
this.setIsValid(CalculatedValidity.NotAvailable);
notifyContainerSlotChanged();
}
@Override
public int getSlotStackLimit() {
return this.itemHandler.getMaxAmount(this.index, ItemStack.EMPTY);
}
@Override
public int getItemStackLimit(@Nonnull ItemStack stack) {
return Math.min(this.getSlotStackLimit(), stack.getMaxCount());
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
if (this.isSlotEnabled()) {
return !this.itemHandler.extractItem(this.index, 1, true).isEmpty();
}
return false;
}
@Override
@Nonnull
public ItemStack decrStackSize(int amount) {
return this.itemHandler.extractItem(this.index, amount, false);
}
@Override
public boolean isSameInventory(Slot other) {
return other instanceof AppEngSlot && ((AppEngSlot) other).itemHandler == this.itemHandler;
}
@Override
@Environment(EnvType.CLIENT)
public boolean isEnabled() {
return this.isSlotEnabled();
}
public boolean isSlotEnabled() {
return true;
}
public ItemStack getDisplayStack() {
return this.itemHandler.getInvStack(this.index);
}
public float getOpacityOfIcon() {
return 0.4f;
}
public boolean renderIconWithItem() {
return false;
}
public int getIcon() {
return this.getIIcon();
}
public boolean isPlayerSide() {
return this.isPlayerSide;
}
public boolean shouldDisplay() {
return this.isSlotEnabled();
}
public int getX() {
return this.defX;
}
public int getY() {
return this.defY;
}
private int getIIcon() {
return this.IIcon;
}
public void setIIcon(final int iIcon) {
this.IIcon = iIcon;
}
private boolean isDisplay() {
return this.isDisplay;
}
public void setDisplay(final boolean isDisplay) {
this.isDisplay = isDisplay;
}
public boolean isDraggable() {
return this.isDraggable;
}
private void setDraggable(final boolean isDraggable) {
this.isDraggable = isDraggable;
}
void setPlayerSide(final boolean isPlayerSide) {
this.isPlayerSide = isPlayerSide;
}
public CalculatedValidity getIsValid() {
return this.isValid;
}
public void setIsValid(final CalculatedValidity isValid) {
this.isValid = isValid;
}
protected AEBaseContainer getContainer() {
return this.myContainer;
}
public void setContainer(final AEBaseContainer myContainer) {
this.myContainer = myContainer;
}
public enum CalculatedValidity {
NotAvailable, Valid, Invalid
}
}
@@ -1,62 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import appeng.container.AEBaseContainer;
import appeng.util.inv.WrapperInvItemHandler;
public class CraftingMatrixSlot extends AppEngSlot {
private final AEBaseContainer c;
private final Inventory wrappedInventory;
public CraftingMatrixSlot(final AEBaseContainer c, final FixedItemInv par1iInventory, final int par2,
final int par3, final int par4) {
super(par1iInventory, par2, par3, par4);
this.c = c;
this.wrappedInventory = new WrapperInvItemHandler(par1iInventory);
}
@Override
public void clearStack() {
super.clearStack();
this.c.onCraftMatrixChanged(this.wrappedInventory);
}
@Override
public void putStack(final ItemStack par1ItemStack) {
super.putStack(par1ItemStack);
this.c.onCraftMatrixChanged(this.wrappedInventory);
}
@Override
public boolean isPlayerSide() {
return true;
}
@Override
public ItemStack decrStackSize(final int par1) {
final ItemStack is = super.decrStackSize(par1);
this.c.onCraftMatrixChanged(this.wrappedInventory);
return is;
}
}
@@ -1,292 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.container.implementations.CraftingTermContainer;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction;
import appeng.items.storage.ViewCellItem;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorFixedInv;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
public class CraftingTermSlot extends AppEngCraftingSlot {
private final FixedItemInv craftInv;
private final FixedItemInv pattern;
private final IActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public CraftingTermSlot(final PlayerEntity player, final IActionSource mySrc, final IEnergySource energySrc,
final IStorageMonitorable storage, final FixedItemInv cMatrix, final FixedItemInv secondMatrix,
final FixedItemInv output, final int x, final int y, final IContainerCraftingPacket ccp) {
super(player, cMatrix, output, 0, x, y);
this.energySrc = energySrc;
this.storage = storage;
this.mySrc = mySrc;
this.pattern = cMatrix;
this.craftInv = secondMatrix;
this.container = ccp;
}
public FixedItemInv getCraftingMatrix() {
return this.craftInv;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
@Override
public ItemStack onTake(final PlayerEntity p, final ItemStack is) {
return is;
}
public void doClick(final InventoryAction action, final PlayerEntity who) {
if (this.getStack().isEmpty()) {
return;
}
if (Platform.isClient()) {
return;
}
final IMEMonitor<IAEItemStack> inv = this.storage
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final int howManyPerCraft = this.getStack().getCount();
int maxTimesToCraft = 0;
InventoryAdaptor ia = null;
if (action == InventoryAction.CRAFT_SHIFT) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor(who);
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxCount() / (double) howManyPerCraft);
} else if (action == InventoryAction.CRAFT_STACK) // craft into hand, full stack
{
ia = new AdaptorFixedInv(new WrapperCursorItemHandler(who.inventory));
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxCount() / (double) howManyPerCraft);
} else
// pick up what was crafted...
{
ia = new AdaptorFixedInv(new WrapperCursorItemHandler(who.inventory));
maxTimesToCraft = 1;
}
maxTimesToCraft = this.capCraftingAttempts(maxTimesToCraft);
if (ia == null) {
return;
}
final ItemStack rs = this.getStack().copy();
if (rs.isEmpty()) {
return;
}
for (int x = 0; x < maxTimesToCraft; x++) {
if (ia.simulateAdd(rs).isEmpty()) {
final IItemList<IAEItemStack> all = inv.getStorageList();
final ItemStack extra = ia.addItems(this.craftItem(who, rs, inv, all));
if (!extra.isEmpty()) {
final List<ItemStack> drops = new ArrayList<>();
drops.add(extra);
Platform.spawnDrops(who.world,
new BlockPos((int) who.getX(), (int) who.getY(), (int) who.getZ()), drops);
return;
}
}
}
}
// TODO: This is really hacky and NEEDS to be solved with a full container/gui
// refactoring.
protected Recipe<CraftingInventory> findRecipe(CraftingInventory ic, World world) {
if (this.container instanceof CraftingTermContainer) {
final CraftingTermContainer containerTerminal = (CraftingTermContainer) this.container;
final Recipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
if (recipe != null && recipe.matches(ic, world)) {
return containerTerminal.getCurrentRecipe();
}
}
return world.getRecipeManager().getRecipe(RecipeType.CRAFTING, ic, world).orElse(null);
}
// TODO: This is really hacky and NEEDS to be solved with a full container/gui
// refactoring.
@Override
protected DefaultedList<ItemStack> getRemainingItems(CraftingInventory ic, World world) {
if (this.container instanceof CraftingTermContainer) {
final CraftingTermContainer containerTerminal = (CraftingTermContainer) this.container;
final Recipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
if (recipe != null && recipe.matches(ic, world)) {
return containerTerminal.getCurrentRecipe().getRemainingItems(ic);
}
}
return super.getRemainingItems(ic, world);
}
private int capCraftingAttempts(final int maxTimesToCraft) {
return maxTimesToCraft;
}
private ItemStack craftItem(final PlayerEntity p, final ItemStack request, final IMEMonitor<IAEItemStack> inv,
final IItemList all) {
// update crafting matrix...
ItemStack is = this.getStack();
if (!is.isEmpty() && ItemStack.areItemsEqual(request, is)) {
final ItemStack[] set = new ItemStack[this.getPattern().getSlotCount()];
// Safeguard for empty slots in the inventory for now
Arrays.fill(set, ItemStack.EMPTY);
// add one of each item to the items on the board...
if (Platform.isServer()) {
final CraftingInventory ic = new CraftingInventory(new ContainerNull(), 3, 3);
for (int x = 0; x < 9; x++) {
ic.setStack(x, this.getPattern().getInvStack(x));
}
final Recipe<CraftingInventory> r = this.findRecipe(ic, p.world);
if (r == null) {
final Item target = request.getItem();
if (target.isDamageable() && target.isRepairable(request)) {
boolean isBad = false;
for (int x = 0; x < ic.size(); x++) {
final ItemStack pis = ic.getStack(x);
if (pis.isEmpty()) {
continue;
}
if (pis.getItem() != target) {
isBad = true;
}
}
if (!isBad) {
super.onTake(p, is);
// actually necessary to cleanup this case...
p.openContainer.onCraftMatrixChanged(new WrapperInvItemHandler(this.craftInv));
return request;
}
}
return ItemStack.EMPTY;
}
is = r.craft(ic);
if (inv != null) {
for (int x = 0; x < this.getPattern().getSlotCount(); x++) {
if (!this.getPattern().getInvStack(x).isEmpty()) {
set[x] = Platform.extractItemsByRecipe(this.energySrc, this.mySrc, inv, p.world, r, is, ic,
this.getPattern().getInvStack(x), x, all, Actionable.MODULATE,
ViewCellItem.createFilter(this.container.getViewCells()));
ic.setStack(x, set[x]);
}
}
}
}
if (this.preCraft(p, inv, set, is)) {
this.makeItem(p, is);
this.postCraft(p, inv, set, is);
}
p.openContainer.onCraftMatrixChanged(new WrapperInvItemHandler(this.craftInv));
return is;
}
return ItemStack.EMPTY;
}
private boolean preCraft(final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set,
final ItemStack result) {
return true;
}
private void makeItem(final PlayerEntity p, final ItemStack is) {
super.onTake(p, is);
}
private void postCraft(final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set,
final ItemStack result) {
final List<ItemStack> drops = new ArrayList<>();
// add one of each item to the items on the board...
if (Platform.isServer()) {
// set new items onto the crafting table...
for (int x = 0; x < this.craftInv.getSlotCount(); x++) {
if (this.craftInv.getInvStack(x).isEmpty()) {
ItemHandlerUtil.setStackInSlot(this.craftInv, x, set[x]);
} else if (!set[x].isEmpty()) {
// eek! put it back!
final IAEItemStack fail = inv.injectItems(AEItemStack.fromItemStack(set[x]), Actionable.MODULATE,
this.mySrc);
if (fail != null) {
drops.add(fail.createItemStack());
}
}
}
}
if (drops.size() > 0) {
Platform.spawnDrops(p.world, new BlockPos((int) p.getX(), (int) p.getY(), (int) p.getZ()), drops);
}
}
FixedItemInv getPattern() {
return this.pattern;
}
}
@@ -1,40 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class DisabledSlot extends AppEngSlot {
public DisabledSlot(final FixedItemInv par1iInventory, final int slotIndex, final int x, final int y) {
super(par1iInventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(final ItemStack par1ItemStack) {
return false;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
}
@@ -1,46 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class FakeBlacklistSlot extends FakeTypeOnlySlot {
public FakeBlacklistSlot(final FixedItemInv inv, final int idx, final int x, final int y) {
super(inv, idx, x, y);
}
@Override
public float getOpacityOfIcon() {
return 0.8f;
}
@Override
public boolean renderIconWithItem() {
return true;
}
@Override
public int getIcon() {
if (this.getHasStack()) {
return this.getStack().getCount() > 0 ? 16 + 14 : 14;
}
return -1;
}
}
@@ -1,28 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class FakeCraftingMatrixSlot extends FakeSlot {
public FakeCraftingMatrixSlot(final FixedItemInv inv, final int idx, final int x, final int y) {
super(inv, idx, x, y);
}
}
@@ -1,59 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
public class FakeSlot extends AppEngSlot {
public FakeSlot(final FixedItemInv inv, final int idx, final int x, final int y) {
super(inv, idx, x, y);
}
@Override
public ItemStack onTake(final PlayerEntity par1PlayerEntity, final ItemStack par2ItemStack) {
return par2ItemStack;
}
@Override
public ItemStack decrStackSize(final int par1) {
return ItemStack.EMPTY;
}
@Override
public boolean isItemValid(final ItemStack par1ItemStack) {
return false;
}
@Override
public void putStack(ItemStack is) {
if (!is.isEmpty()) {
is = is.copy();
}
super.putStack(is);
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
}
@@ -1,43 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.item.ItemStack;
public class FakeTypeOnlySlot extends FakeSlot {
public FakeTypeOnlySlot(final FixedItemInv inv, final int idx, final int x, final int y) {
super(inv, idx, x, y);
}
@Override
public void putStack(ItemStack is) {
if (!is.isEmpty()) {
is = is.copy();
if (is.getCount() > 1) {
is.setCount(1);
} else if (is.getCount() < -1) {
is.setCount(-1);
}
}
super.putStack(is);
}
}
@@ -1,34 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
/**
* @author BrockWS
* @version rv6 - 2/05/2018
* @since rv6 2/05/2018
*/
public interface IOptionalSlot {
default boolean isRenderDisabled() {
return false;
}
int getSourceX();
int getSourceY();
}
@@ -1,24 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
public interface IOptionalSlotHost {
boolean isSlotEnabled(int idx);
}
@@ -1,59 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class InaccessibleSlot extends AppEngSlot {
private ItemStack dspStack = ItemStack.EMPTY;
public InaccessibleSlot(final FixedItemInv i, final int slotIdx, final int x, final int y) {
super(i, slotIdx, x, y);
}
@Override
public boolean isItemValid(final ItemStack i) {
return false;
}
@Override
public void onSlotChanged() {
super.onSlotChanged();
this.dspStack = ItemStack.EMPTY;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
@Override
public ItemStack getDisplayStack() {
if (this.dspStack.isEmpty()) {
final ItemStack dsp = super.getDisplayStack();
if (!dsp.isEmpty()) {
this.dspStack = dsp.copy();
}
}
return this.dspStack;
}
}
@@ -1,40 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.container.implementations.MolecularAssemblerContainer;
public class MolecularAssemblerPatternSlot extends AppEngSlot {
private final MolecularAssemblerContainer mac;
public MolecularAssemblerPatternSlot(final MolecularAssemblerContainer mac, final FixedItemInv i, final int slotIdx,
final int x, final int y) {
super(i, slotIdx, x, y);
this.mac = mac;
}
@Override
public boolean isItemValid(final ItemStack i) {
return this.mac.isValidItemForSlot(this.getSlotIndex(), i);
}
}
@@ -1,28 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class NormalSlot extends AppEngSlot {
public NormalSlot(final FixedItemInv inv, final int slot, final int xPos, final int yPos) {
super(inv, slot, xPos, yPos);
}
}
@@ -1,84 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
// FIXME seems unused
public class NullSlot extends Slot {
public NullSlot() {
super(null, 0, 0, 0);
}
@Override
public void onSlotChange(final ItemStack par1ItemStack, final ItemStack par2ItemStack) {
}
@Override
public ItemStack onTake(final PlayerEntity par1PlayerEntity, final ItemStack par2ItemStack) {
return par2ItemStack;
}
@Override
public boolean isItemValid(final ItemStack par1ItemStack) {
return false;
}
@Override
@Nonnull
public ItemStack getStack() {
return ItemStack.EMPTY;
}
@Override
public void putStack(final ItemStack par1ItemStack) {
}
@Override
public void onSlotChanged() {
}
@Override
public int getSlotStackLimit() {
return 0;
}
@Override
public ItemStack decrStackSize(final int par1) {
return ItemStack.EMPTY;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
@Override
public int getSlotIndex() {
return 0;
}
}
@@ -1,82 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class OptionalFakeSlot extends FakeSlot implements IOptionalSlot {
private final int srcX;
private final int srcY;
private final int groupNum;
private final IOptionalSlotHost host;
private boolean renderDisabled = true;
public OptionalFakeSlot(final FixedItemInv inv, final IOptionalSlotHost containerBus, final int idx, final int x,
final int y, final int offX, final int offY, final int groupNum) {
super(inv, idx, x + offX * 18, y + offY * 18);
this.srcX = x;
this.srcY = y;
this.groupNum = groupNum;
this.host = containerBus;
}
@Override
@Nonnull
public ItemStack getStack() {
if (!this.isSlotEnabled()) {
if (!this.getDisplayStack().isEmpty()) {
this.clearStack();
}
}
return super.getStack();
}
@Override
public boolean isSlotEnabled() {
if (this.host == null) {
return false;
}
return this.host.isSlotEnabled(this.groupNum);
}
@Override
public boolean isRenderDisabled() {
return this.renderDisabled;
}
public void setRenderDisabled(final boolean renderDisabled) {
this.renderDisabled = renderDisabled;
}
@Override
public int getSourceX() {
return this.srcX;
}
@Override
public int getSourceY() {
return this.srcY;
}
}
@@ -1,53 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class OptionalNormalSlot extends AppEngSlot implements IOptionalSlot {
private final int groupNum;
private final IOptionalSlotHost host;
public OptionalNormalSlot(final FixedItemInv inv, final IOptionalSlotHost containerBus, final int slot,
final int xPos, final int yPos, final int groupNum) {
super(inv, slot, xPos, yPos);
this.groupNum = groupNum;
this.host = containerBus;
}
@Override
public boolean isSlotEnabled() {
if (this.host == null) {
return false;
}
return this.host.isSlotEnabled(this.groupNum);
}
@Override
public int getSourceX() {
return this.xPos;
}
@Override
public int getSourceY() {
return this.yPos;
}
}
@@ -1,44 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerInventory;
public class OptionalRestrictedInputSlot extends RestrictedInputSlot {
private final int groupNum;
private final IOptionalSlotHost host;
public OptionalRestrictedInputSlot(final PlacableItemType valid, final FixedItemInv i, final IOptionalSlotHost host,
final int slotIndex, final int x, final int y, final int grpNum, final PlayerInventory invPlayer) {
super(valid, i, slotIndex, x, y, invPlayer);
this.groupNum = grpNum;
this.host = host;
}
@Override
public boolean isSlotEnabled() {
if (this.host == null) {
return false;
}
return this.host.isSlotEnabled(this.groupNum);
}
}
@@ -1,44 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class OptionalTypeOnlyFakeSlot extends OptionalFakeSlot {
public OptionalTypeOnlyFakeSlot(final FixedItemInv inv, final IOptionalSlotHost containerBus, final int idx,
final int x, final int y, final int offX, final int offY, final int groupNum) {
super(inv, containerBus, idx, x, y, offX, offY, groupNum);
}
@Override
public void putStack(ItemStack is) {
if (!is.isEmpty()) {
is = is.copy();
if (is.getCount() > 1) {
is.setCount(1);
} else if (is.getCount() < -1) {
is.setCount(-1);
}
}
super.putStack(is);
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class OutputSlot extends AppEngSlot {
public OutputSlot(final FixedItemInv a, final int b, final int c, final int d, final int i) {
super(a, b, c, d);
this.setIIcon(i);
}
@Override
public boolean isItemValid(final ItemStack i) {
return false;
}
}
@@ -1,39 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class PatternOutputsSlot extends OptionalFakeSlot {
public PatternOutputsSlot(final FixedItemInv inv, final IOptionalSlotHost containerBus, final int idx, final int x,
final int y, final int offX, final int offY, final int groupNum) {
super(inv, containerBus, idx, x, y, offX, offY, groupNum);
}
@Override
public boolean isSlotEnabled() {
return true;
}
@Override
public boolean shouldDisplay() {
return super.isSlotEnabled();
}
}
@@ -1,74 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.core.sync.BasePacket;
import appeng.core.sync.packets.PatternSlotPacket;
import appeng.helpers.IContainerCraftingPacket;
public class PatternTermSlot extends CraftingTermSlot {
private final int groupNum;
private final IOptionalSlotHost host;
public PatternTermSlot(final PlayerEntity player, final IActionSource mySrc, final IEnergySource energySrc,
final IStorageMonitorable storage, final FixedItemInv cMatrix, final FixedItemInv secondMatrix,
final FixedItemInv output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber,
final IContainerCraftingPacket c) {
super(player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c);
this.host = h;
this.groupNum = groupNumber;
}
public BasePacket getRequest(final boolean shift) {
return new PatternSlotPacket(this.getPattern(),
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(this.getStack()),
shift);
}
@Override
public ItemStack getStack() {
if (!this.isSlotEnabled()) {
if (!this.getDisplayStack().isEmpty()) {
this.clearStack();
}
}
return super.getStack();
}
@Override
public boolean isSlotEnabled() {
if (this.host == null) {
return false;
}
return this.host.isSlotEnabled(this.groupNum);
}
}
@@ -1,29 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
public class PlayerHotBarSlot extends AppEngSlot {
public PlayerHotBarSlot(final FixedItemInv par1iInventory, final int par2, final int par3, final int par4) {
super(par1iInventory, par2, par3, par4);
this.setPlayerSide(true);
}
}
@@ -1,32 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import alexiil.mc.lib.attributes.item.FixedItemInv;
// there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot.
public class PlayerInvSlot extends AppEngSlot {
public PlayerInvSlot(final FixedItemInv par1iInventory, final int idx, final int x, final int y) {
super(par1iInventory, idx, x, y);
this.setPlayerSide(true);
}
}
@@ -1,290 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.container.slot;
import java.util.List;
import java.util.Set;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IItems;
import appeng.api.definitions.IMaterials;
import appeng.api.features.INetworkEncodable;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.implementations.items.IStorageComponent;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.cells.ICellWorkbenchItem;
import appeng.items.misc.EncodedPatternItem;
import appeng.recipes.handlers.GrinderRecipes;
import appeng.tile.misc.InscriberRecipes;
import appeng.util.Platform;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public class RestrictedInputSlot extends AppEngSlot {
private static final List<Identifier> METAL_INGOT_TAGS = ImmutableList.of(
new Identifier("forge:ingots/copper"), new Identifier("forge:ingots/tin"),
new Identifier("forge:ingots/iron"), new Identifier("forge:ingots/gold"),
new Identifier("forge:ingots/lead"), new Identifier("forge:ingots/bronze"),
new Identifier("forge:ingots/brass"), new Identifier("forge:ingots/nickel"),
new Identifier("forge:ingots/aluminium"));
private final PlacableItemType which;
private final PlayerInventory p;
private boolean allowEdit = true;
private int stackLimit = -1;
public RestrictedInputSlot(final PlacableItemType valid, final FixedItemInv i, final int slotIndex, final int x,
final int y, final PlayerInventory p) {
super(i, slotIndex, x, y);
this.which = valid;
this.setIIcon(valid.IIcon);
this.p = p;
}
@Override
public int getSlotStackLimit() {
if (this.stackLimit != -1) {
return this.stackLimit;
}
return super.getSlotStackLimit();
}
public boolean isValid(final ItemStack is, final World theWorld) {
if (this.which == PlacableItemType.VALID_ENCODED_PATTERN_W_OUTPUT) {
final ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem
? ((ICraftingPatternItem) is.getItem()).getPatternForItem(is, theWorld)
: null;
return ap != null;
}
return true;
}
public Slot setStackLimit(final int i) {
this.stackLimit = i;
return this;
}
@Override
public boolean isItemValid(final ItemStack i) {
if (!this.getContainer().isValidForSlot(this, i)) {
return false;
}
if (i.isEmpty()) {
return false;
}
if (i.getItem() == Items.AIR) {
return false;
}
if (!super.isItemValid(i)) {
return false;
}
if (!this.isAllowEdit()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
final IMaterials materials = definitions.materials();
final IItems items = definitions.items();
switch (this.which) {
case ENCODED_CRAFTING_PATTERN:
if (i.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem b = (ICraftingPatternItem) i.getItem();
final ICraftingPatternDetails de = b.getPatternForItem(i, this.p.player.world);
if (de != null) {
return de.isCraftable();
}
}
return false;
case VALID_ENCODED_PATTERN_W_OUTPUT:
case ENCODED_PATTERN_W_OUTPUT:
case ENCODED_PATTERN: {
if (i.getItem() instanceof ICraftingPatternItem) {
return true;
}
// ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem
// ?
// ((ICraftingPatternItem)
// i.getItem()).getPatternForItem( i ) : null;
return false;// pattern != null;
}
case BLANK_PATTERN:
return materials.blankPattern().isSameAs(i);
case PATTERN:
if (i.getItem() instanceof ICraftingPatternItem) {
return true;
}
return materials.blankPattern().isSameAs(i);
case INSCRIBER_PLATE:
if (materials.namePress().isSameAs(i)) {
return true;
}
return InscriberRecipes.isValidOptionalIngredient(p.player.world, i);
case INSCRIBER_INPUT:
return true;/*
* for (ItemStack is : Inscribe.inputs) if ( Platform.isSameItemPrecise( is, i )
* ) return true; return false;
*/
case METAL_INGOTS:
return isMetalIngot(i);
case VIEW_CELL:
return items.viewCell().isSameAs(i);
case ORE:
return GrinderRecipes.isValidIngredient(p.player.world, i);
case FUEL:
return ForgeHooks.getBurnTime(i) > 0;
case POWERED_TOOL:
return Platform.isChargeable(i);
case QE_SINGULARITY:
return materials.qESingularity().isSameAs(i);
case RANGE_BOOSTER:
return materials.wirelessBooster().isSameAs(i);
case SPATIAL_STORAGE_CELLS:
return i.getItem() instanceof ISpatialStorageCell
&& ((ISpatialStorageCell) i.getItem()).isSpatialStorage(i);
case STORAGE_CELLS:
return AEApi.instance().registries().cell().isCellHandled(i);
case WORKBENCH_CELL:
return i.getItem() instanceof ICellWorkbenchItem && ((ICellWorkbenchItem) i.getItem()).isEditable(i);
case STORAGE_COMPONENT:
return i.getItem() instanceof IStorageComponent
&& ((IStorageComponent) i.getItem()).isStorageComponent(i);
case TRASH:
if (AEApi.instance().registries().cell().isCellHandled(i)) {
return false;
}
return !(i.getItem() instanceof IStorageComponent
&& ((IStorageComponent) i.getItem()).isStorageComponent(i));
case ENCODABLE_ITEM:
return i.getItem() instanceof INetworkEncodable
|| AEApi.instance().registries().wireless().isWirelessTerminal(i);
case BIOMETRIC_CARD:
return i.getItem() instanceof IBiometricCard;
case UPGRADES:
return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType(i) != null;
default:
break;
}
return false;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return this.isAllowEdit();
}
@Override
public ItemStack getDisplayStack() {
if (Platform.isClient() && (this.which == PlacableItemType.ENCODED_PATTERN)) {
final ItemStack is = super.getStack();
if (!is.isEmpty() && is.getItem() instanceof EncodedPatternItem) {
final EncodedPatternItem iep = (EncodedPatternItem) is.getItem();
final ItemStack out = iep.getOutput(p.player.world, is);
if (!out.isEmpty()) {
return out;
}
}
}
return super.getStack();
}
public static boolean isMetalIngot(final ItemStack i) {
if (Platform.itemComparisons().isSameItem(i, new ItemStack(Items.IRON_INGOT))) {
return true;
}
Set<Identifier> itemTags = i.getItem().getTags();
for (Identifier tagName : METAL_INGOT_TAGS) {
if (itemTags.contains(tagName)) {
return true;
}
}
return false;
}
private boolean isAllowEdit() {
return this.allowEdit;
}
public void setAllowEdit(final boolean allowEdit) {
this.allowEdit = allowEdit;
}
public enum PlacableItemType {
STORAGE_CELLS(15), ORE(16 + 15), STORAGE_COMPONENT(3 * 16 + 15),
ENCODABLE_ITEM(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15),
ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15),
ENCODED_CRAFTING_PATTERN(7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), PATTERN(8 * 16 + 15),
BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15),
RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARITY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15),
FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15), WORKBENCH_CELL(15), BIOMETRIC_CARD(14 * 16 + 15),
VIEW_CELL(4 * 16 + 14),
INSCRIBER_PLATE(2 * 16 + 14), INSCRIBER_INPUT(3 * 16 + 14), METAL_INGOTS(3 * 16 + 14);
public final int IIcon;
PlacableItemType(final int o) {
this.IIcon = o;
}
}
}