Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //EnderBeeconTileEntity
- public AutomationSensitiveItemStackHandler h = new EnderBeeconTileEntity.TileStackHandler(2, getAcceptor(), getRemover());
- public AutomationSensitiveItemStackHandler.IAcceptor getAcceptor() {
- return (slot, stack, automation) -> !automation || slot == 0;
- }
- public AutomationSensitiveItemStackHandler.IRemover getRemover() {
- return (slot, automation) -> !automation || slot == 1;
- }
- protected class TileStackHandler extends AutomationSensitiveItemStackHandler {
- protected TileStackHandler(int slots, IAcceptor acceptor, IRemover remover) {
- super(slots, acceptor, remover);
- }
- @Override
- protected void onContentsChanged(int slot) {
- super.onContentsChanged(slot);
- markDirty();
- }
- }
- // EnderBeeconContainer
- this.addSlot(new SlotItemHandlerUnconditioned(enderBeeconTileEntity.h, EnderBeeconTileEntity.HONEY_BOTTLE_INPUT, 184, 34) {
- public boolean isItemValid(ItemStack stack) {
- if (stack.getItem() instanceof BucketItem) {
- BucketItem bucket = (BucketItem) stack.getItem();
- return bucket.getFluid().isIn(enderBeeconTileEntity.honeyFluidTag);
- } else {
- return stack.getItem().isIn(enderBeeconTileEntity.honeyBottleTag);
- }
- }
- });
- /** * @author Shadows
- * Taken from Actually Additions owned by Ellpeck
- */
- public class AutomationSensitiveItemStackHandler extends ItemStackHandler {
- public static final IAcceptor ACCEPT_TRUE = (a, b, c) -> true;
- public static final IRemover REMOVE_TRUE = (a, b) -> true;
- public static final IAcceptor ACCEPT_FALSE = (a, b, c) -> false;
- public static final IRemover REMOVE_FALSE = (a, b) -> false;
- IAcceptor acceptor;
- IRemover remover;
- public AutomationSensitiveItemStackHandler(NonNullList<ItemStack> stacks, IAcceptor acceptor, IRemover remover) {
- super(stacks);
- this.acceptor = acceptor;
- this.remover = remover;
- }
- public AutomationSensitiveItemStackHandler(int slots, IAcceptor acceptor, IRemover remover) {
- super(slots);
- this.acceptor = acceptor;
- this.remover = remover;
- }
- public AutomationSensitiveItemStackHandler(NonNullList<ItemStack> stacks) {
- this(stacks, ACCEPT_TRUE, REMOVE_TRUE);
- }
- public AutomationSensitiveItemStackHandler(int slots) {
- this(slots, ACCEPT_TRUE, REMOVE_TRUE);
- }
- public NonNullList<ItemStack> getItems() {
- return this.stacks;
- }
- @Nonnull
- @Override
- public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
- return this.insertItem(slot, stack, simulate, true);
- }
- public ItemStack insertItem(int slot, ItemStack stack, boolean simulate, boolean fromAutomation) {
- if (this.canAccept(slot, stack, fromAutomation)) return super.insertItem(slot, stack, simulate);
- return stack;
- }
- public void deserializeNBTWithoutCheckingSize(CompoundNBT nbt)
- {
- ListNBT tagList = nbt.getList("Items", Constants.NBT.TAG_COMPOUND);
- for (int i = 0; i < tagList.size(); i++)
- {
- CompoundNBT itemTags = tagList.getCompound(i);
- int slot = itemTags.getInt("Slot");
- if (slot >= 0 && slot < stacks.size())
- {
- stacks.set(slot, ItemStack.read(itemTags));
- }
- }
- onLoad();
- }
- @Nonnull
- @Override
- public ItemStack extractItem(int slot, int amount, boolean simulate) {
- return this.extractItem(slot, amount, simulate, true);
- }
- public ItemStack extractItem(int slot, int amount, boolean simulate, boolean byAutomation) {
- if (!this.canRemove(slot, byAutomation)) return ItemStack.EMPTY;
- return super.extractItem(slot, amount, simulate);
- }
- public final boolean canAccept(int slot, ItemStack stack, boolean automation) {
- return this.getAcceptor().canAccept(slot, stack, automation);
- }
- public final boolean canRemove(int slot, boolean automation) {
- return this.getRemover().canRemove(slot, automation);
- }
- public IAcceptor getAcceptor() {
- return this.acceptor;
- }
- public IRemover getRemover() {
- return this.remover;
- }
- public interface IAcceptor {
- boolean canAccept(int slot, ItemStack stack, boolean automation);
- }
- public interface IRemover {
- boolean canRemove(int slot, boolean automation);
- }
- }
Add Comment
Please, Sign In to add comment