Fix inscriber inventory filtering, and accidental overwriting of the output slot.
This commit is contained in:
@@ -23,6 +23,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -56,7 +58,6 @@ import appeng.util.Platform;
|
|||||||
import appeng.util.inv.InvOperation;
|
import appeng.util.inv.InvOperation;
|
||||||
import appeng.util.inv.filter.IAEItemFilter;
|
import appeng.util.inv.filter.IAEItemFilter;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICrankable, IGridTickable {
|
public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICrankable, IGridTickable {
|
||||||
private static final int POWER_MAXIMUM_AMOUNT = 1600;
|
private static final int POWER_MAXIMUM_AMOUNT = 1600;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.util.List;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -36,6 +38,7 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
import alexiil.mc.lib.attributes.Simulation;
|
import alexiil.mc.lib.attributes.Simulation;
|
||||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||||
|
import alexiil.mc.lib.attributes.item.LimitedFixedItemInv;
|
||||||
|
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.PowerMultiplier;
|
import appeng.api.config.PowerMultiplier;
|
||||||
@@ -65,8 +68,6 @@ import appeng.util.ConfigManager;
|
|||||||
import appeng.util.IConfigManagerHost;
|
import appeng.util.IConfigManagerHost;
|
||||||
import appeng.util.inv.InvOperation;
|
import appeng.util.inv.InvOperation;
|
||||||
import appeng.util.inv.WrapperChainedItemHandler;
|
import appeng.util.inv.WrapperChainedItemHandler;
|
||||||
import appeng.util.inv.WrapperFilteredItemHandler;
|
|
||||||
import appeng.util.inv.filter.IAEItemFilter;
|
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,15 +92,17 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
private final AppEngInternalInventory bottomItemHandler = new AppEngInternalInventory(this, 1, 1);
|
private final AppEngInternalInventory bottomItemHandler = new AppEngInternalInventory(this, 1, 1);
|
||||||
private final AppEngInternalInventory sideItemHandler = new AppEngInternalInventory(this, 2, 1);
|
private final AppEngInternalInventory sideItemHandler = new AppEngInternalInventory(this, 2, 1);
|
||||||
|
|
||||||
private final FixedItemInv topItemHandlerExtern;
|
private final LimitedFixedItemInv topItemHandlerExtern;
|
||||||
private final FixedItemInv bottomItemHandlerExtern;
|
private final LimitedFixedItemInv bottomItemHandlerExtern;
|
||||||
private final FixedItemInv sideItemHandlerExtern;
|
private final LimitedFixedItemInv sideItemHandlerExtern;
|
||||||
|
|
||||||
private InscriberRecipe cachedTask = null;
|
private InscriberRecipe cachedTask = null;
|
||||||
|
|
||||||
private final FixedItemInv inv = new WrapperChainedItemHandler(this.topItemHandler, this.bottomItemHandler,
|
private final FixedItemInv inv = new WrapperChainedItemHandler(this.topItemHandler, this.bottomItemHandler,
|
||||||
this.sideItemHandler);
|
this.sideItemHandler);
|
||||||
|
|
||||||
|
private final FixedItemInv externalInv;
|
||||||
|
|
||||||
public InscriberBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
public InscriberBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||||
super(tileEntityTypeIn);
|
super(tileEntityTypeIn);
|
||||||
|
|
||||||
@@ -113,10 +116,30 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
|
|
||||||
this.sideItemHandler.setMaxStackSize(1, 64);
|
this.sideItemHandler.setMaxStackSize(1, 64);
|
||||||
|
|
||||||
final IAEItemFilter filter = new ItemHandlerFilter();
|
this.topItemHandlerExtern = this.topItemHandler.createLimitedFixedInv();
|
||||||
this.topItemHandlerExtern = new WrapperFilteredItemHandler(this.topItemHandler, filter);
|
this.topItemHandlerExtern.getAllRule().filterInserts(this::canInsertIntoTopOrBottom)
|
||||||
this.bottomItemHandlerExtern = new WrapperFilteredItemHandler(this.bottomItemHandler, filter);
|
.filterExtracts(stack -> !isSmash());
|
||||||
this.sideItemHandlerExtern = new WrapperFilteredItemHandler(this.sideItemHandler, filter);
|
|
||||||
|
this.bottomItemHandlerExtern = this.bottomItemHandler.createLimitedFixedInv();
|
||||||
|
this.bottomItemHandlerExtern.getAllRule().filterInserts(this::canInsertIntoTopOrBottom)
|
||||||
|
.filterExtracts(stack -> !isSmash());
|
||||||
|
|
||||||
|
this.sideItemHandlerExtern = this.sideItemHandler.createLimitedFixedInv();
|
||||||
|
this.sideItemHandlerExtern.getRule(0).disallowExtraction().filterInserts(stack -> !isSmash());
|
||||||
|
this.sideItemHandlerExtern.getRule(1).filterExtracts(stack -> !isSmash()).disallowInsertion();
|
||||||
|
|
||||||
|
this.externalInv = new WrapperChainedItemHandler(this.topItemHandlerExtern, this.bottomItemHandlerExtern,
|
||||||
|
this.sideItemHandlerExtern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canInsertIntoTopOrBottom(ItemStack stack) {
|
||||||
|
if (isSmash()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Api.instance().definitions().materials().namePress().isSameAs(stack)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getUpgradeSlots() {
|
private int getUpgradeSlots() {
|
||||||
@@ -212,6 +235,12 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
return this.inv;
|
return this.inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public FixedItemInv getExternalInventory() {
|
||||||
|
return this.externalInv;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
|
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
|
||||||
final ItemStack removed, final ItemStack added) {
|
final ItemStack removed, final ItemStack added) {
|
||||||
@@ -276,7 +305,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
if (out != null) {
|
if (out != null) {
|
||||||
final ItemStack outputCopy = out.getOutput().copy();
|
final ItemStack outputCopy = out.getOutput().copy();
|
||||||
|
|
||||||
if (this.sideItemHandler.setInvStack(1, outputCopy, Simulation.ACTION)) {
|
if (this.sideItemHandler.getSlot(1).insert(outputCopy).isEmpty()) {
|
||||||
this.setProcessingTime(0);
|
this.setProcessingTime(0);
|
||||||
if (out.getProcessType() == InscriberProcessType.PRESS) {
|
if (out.getProcessType() == InscriberProcessType.PRESS) {
|
||||||
this.topItemHandler.setInvStack(0, ItemStack.EMPTY, Simulation.ACTION);
|
this.topItemHandler.setInvStack(0, ItemStack.EMPTY, Simulation.ACTION);
|
||||||
@@ -325,7 +354,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
final InscriberRecipe out = this.getTask();
|
final InscriberRecipe out = this.getTask();
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
final ItemStack outputCopy = out.getOutput().copy();
|
final ItemStack outputCopy = out.getOutput().copy();
|
||||||
if (this.sideItemHandler.setInvStack(1, outputCopy, Simulation.SIMULATE)) {
|
if (this.sideItemHandler.getSlot(1).wouldAccept(outputCopy)) {
|
||||||
this.setSmash(true);
|
this.setSmash(true);
|
||||||
this.finalStep = 0;
|
this.finalStep = 0;
|
||||||
this.markForUpdate();
|
this.markForUpdate();
|
||||||
@@ -403,42 +432,4 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
|||||||
this.processingTime = processingTime;
|
this.processingTime = processingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an item handler that exposes the inscribers inventory while providing
|
|
||||||
* simulation capabilities that do not reset the progress if there's already an
|
|
||||||
* item in a slot. Previously, the progress of the inscriber was reset when
|
|
||||||
* another mod attempted insertion of items when there were already items in the
|
|
||||||
* slot.
|
|
||||||
*/
|
|
||||||
private class ItemHandlerFilter implements IAEItemFilter {
|
|
||||||
@Override
|
|
||||||
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
|
|
||||||
if (InscriberBlockEntity.this.isSmash()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return inv == InscriberBlockEntity.this.topItemHandler || inv == InscriberBlockEntity.this.bottomItemHandler
|
|
||||||
|| slot == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
|
|
||||||
// output slot
|
|
||||||
if (slot == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (InscriberBlockEntity.this.isSmash()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inv == InscriberBlockEntity.this.topItemHandler || inv == InscriberBlockEntity.this.bottomItemHandler) {
|
|
||||||
if (Api.instance().definitions().materials().namePress().isSameAs(stack)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user