properly fix #1157

This commit is contained in:
Shadows_of_Fire 2018-08-09 23:04:07 -04:00
parent 614d6e41c4
commit 33d9cb9fdb
30 changed files with 874 additions and 920 deletions

View file

@ -53,13 +53,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public ContainerBag(ItemStack sack, InventoryPlayer inventory, boolean isVoid) {
this.inventory = inventory;
this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid)) {
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if(isBlacklisted(stack)) return stack;
return super.insertItem(slot, stack, simulate);
};
};
this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid), (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE);
this.isVoid = isVoid;
this.sack = sack;
@ -74,8 +68,7 @@ public class ContainerBag extends Container implements IButtonReactor{
return ContainerBag.this.filter.check(stack);
}
});
}
else{
} else {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++) {
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) {
@ -96,8 +89,7 @@ public class ContainerBag extends Container implements IButtonReactor{
for (int i = 0; i < 9; i++) {
if (i == inventory.currentItem) {
this.addSlotToContainer(new SlotImmovable(inventory, i, 8 + i * 18, 152));
}
else{
} else {
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 152));
}
}
@ -140,20 +132,15 @@ public class ContainerBag extends Container implements IButtonReactor{
public void updateProgressBar(int id, int data) {
if (id == 0) {
this.filter.isWhitelist = data == 1;
}
else if(id == 1){
} else if (id == 1) {
this.filter.respectMeta = data == 1;
}
else if(id == 2){
} else if (id == 2) {
this.filter.respectNBT = data == 1;
}
else if(id == 3){
} else if (id == 3) {
this.filter.respectOredict = data;
}
else if(id == 4){
} else if (id == 4) {
this.autoInsert = data == 1;
}
else if(id == 5){
} else if (id == 5) {
this.filter.respectMod = data == 1;
}
}
@ -176,31 +163,20 @@ public class ContainerBag extends Container implements IButtonReactor{
//Shift from Inventory
if (this.isVoid || !this.filter.check(newStack) || !this.mergeItemStack(newStack, 4, 32, false)) {
if (slot >= inventoryStart && slot <= inventoryEnd) {
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return StackUtil.getEmpty();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return StackUtil.getEmpty();
}
if (!this.mergeItemStack(newStack, hotbarStart, hotbarEnd + 1, false)) { return StackUtil.getEmpty(); }
} else if (slot >= inventoryEnd + 1 && slot < hotbarEnd + 1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd + 1, false)) { return StackUtil.getEmpty(); }
}
//
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return StackUtil.getEmpty();
}
} else if (!this.mergeItemStack(newStack, inventoryStart, hotbarEnd + 1, false)) { return StackUtil.getEmpty(); }
if (!StackUtil.isValid(newStack)) {
theSlot.putStack(StackUtil.getEmpty());
}
else{
} else {
theSlot.onSlotChanged();
}
if(newStack.getCount() == currentStack.getCount()){
return StackUtil.getEmpty();
}
if (newStack.getCount() == currentStack.getCount()) { return StackUtil.getEmpty(); }
theSlot.onTake(player, newStack);
return currentStack;
@ -212,11 +188,9 @@ public class ContainerBag extends Container implements IButtonReactor{
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (SlotFilter.checkFilter(this, slotId, player)) {
return StackUtil.getEmpty();
}
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
} else if (clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem) {
return ItemStack.EMPTY;
}
else{
} else {
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
}
@ -242,8 +216,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (buttonID == 0) {
this.autoInsert = !this.autoInsert;
}
else{
} else {
this.filter.onButtonPressed(buttonID);
}
}
@ -262,8 +235,7 @@ public class ContainerBag extends Container implements IButtonReactor{
ActuallyAdditions.LOGGER.error("Invalid item in sack blacklist: " + s);
continue;
}
if(split.length == 1)
BLACKLIST.add(Pair.of(item, 0));
if (split.length == 1) BLACKLIST.add(Pair.of(item, 0));
else if (split.length == 2) {
BLACKLIST.add(Pair.of(item, Integer.parseInt(split[1])));
}

View file

@ -18,11 +18,11 @@ import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
@ -143,13 +143,8 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation) {
return StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
return true;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
}
@Override

View file

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import de.ellpeck.actuallyadditions.mod.items.ItemBattery;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
@ -144,13 +145,8 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
return true;
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation){
return stack.getItem() instanceof ItemBattery;
public IAcceptor getAcceptor(){
return (slot, stack, automation) -> stack.getItem() instanceof ItemBattery;
}
@Override

View file

@ -10,6 +10,12 @@
package de.ellpeck.actuallyadditions.mod.tile;
import java.util.ArrayList;
import java.util.List;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.IGrowable;
@ -23,9 +29,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.energy.IEnergyStorage;
import java.util.ArrayList;
import java.util.List;
public class TileEntityBioReactor extends TileEntityInventoryBase implements ISharingEnergyProvider {
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 0, 800);
@ -46,10 +49,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
Item item = stack.getItem();
if (isValid(item)) {
return true;
}
else if(item instanceof ItemBlock){
return isValid(Block.getBlockFromItem(item));
}
} else if (item instanceof ItemBlock) { return isValid(Block.getBlockFromItem(item)); }
}
return false;
}
@ -90,14 +90,12 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
this.maxBurnTime = 200 - (int) Math.pow(1.8, amount);
this.burnTime = this.maxBurnTime;
}
else{
} else {
this.burnTime = 0;
this.maxBurnTime = 0;
this.producePerTick = 0;
}
}
else{
} else {
this.burnTime--;
this.storage.receiveEnergyInternal(this.producePerTick, false);
}
@ -129,13 +127,13 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
}
@Override
public boolean canExtract(int index, ItemStack stack, boolean byAutomation){
return false;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> isValidItem(stack);
}
@Override
public boolean canInsert(int index, ItemStack stack, boolean fromAutomation){
return isValidItem(stack);
public IRemover getRemover() {
return ItemStackHandlerAA.REMOVE_FALSE;
}
@Override

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
@ -71,9 +72,8 @@ public class TileEntityBreaker extends TileEntityInventoryBase {
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean automation) {
if(isPlacer) return true;
else return !automation;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation;
}
private void doWork() {

View file

@ -13,6 +13,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.ItemStack;
@ -97,8 +99,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
this.markDirty();
}
}
}
else{
} else {
this.currentProcessTime = 0;
}
@ -111,8 +112,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation){
return (slot == 0 && isCanola(stack));
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> slot == 0 && isCanola(stack);
}
public static boolean isCanola(ItemStack stack) {
@ -120,8 +121,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
return !byAutomation;
public IRemover getRemover() {
return (slot, automation) -> !automation;
}
@Override

View file

@ -10,6 +10,8 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -105,14 +107,16 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation){
return TileEntityFurnace.getItemBurnTime(stack) > 0;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> TileEntityFurnace.getItemBurnTime(stack) > 0;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
if(!byAutomation) return true;
public IRemover getRemover() {
return (slot, automation) -> {
if (!automation) return true;
return TileEntityFurnace.getItemBurnTime(this.inv.getStackInSlot(0)) <= 0;
};
}
@Override

View file

@ -16,6 +16,8 @@ import de.ellpeck.actuallyadditions.mod.items.ItemCoffee;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.player.EntityPlayer;
@ -125,8 +127,13 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return (i >= 3 && ItemCoffee.getIngredientFromStack(stack) != null) || (i == SLOT_COFFEE_BEANS && stack.getItem() == InitItems.itemCoffeeBean) || (i == SLOT_INPUT && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CUP.ordinal());
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> (slot >= 3 && ItemCoffee.getIngredientFromStack(stack) != null) || (slot == SLOT_COFFEE_BEANS && stack.getItem() == InitItems.itemCoffeeBean) || (slot == SLOT_INPUT && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CUP.ordinal());
}
@Override
public IRemover getRemover() {
return (slot, automation) -> slot == SLOT_OUTPUT || (slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientFromStack(inv.getStackInSlot(slot)) == null);
}
public void storeCoffee() {
@ -169,18 +176,12 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
this.tank.drainInternal(WATER_USE, true);
}
}
}
else{
} else {
this.brewTime = 0;
}
}
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return slot == SLOT_OUTPUT || (slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientFromStack(stack) == null);
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (buttonID == 0 && this.brewTime <= 0) {

View file

@ -12,6 +12,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.state.IBlockState;
@ -90,13 +92,13 @@ public class TileEntityCompost extends TileEntityInventoryBase {
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation) {
return getRecipeForInput(stack) != null;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> getRecipeForInput(stack) != null;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
return getRecipeForInput(stack) == null;
public IRemover getRemover() {
return (slot, automation) -> getRecipeForInput(inv.getStackInSlot(slot)) == null;
}
public IBlockState getCurrentDisplay() {

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
@ -61,8 +62,7 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
if (this.currentTime <= 0) {
this.doWork();
}
}
else{
} else {
this.currentTime = 15;
}
}
@ -102,19 +102,14 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean automation){
return !automation;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation;
}
public int getEnergyScaled(int i) {
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return true;
}
@Override
public boolean isRedstoneToggle() {
return true;

View file

@ -17,6 +17,8 @@ import javax.annotation.Nullable;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -50,7 +52,8 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
}
public static boolean isPossibleInput(ItemStack stack) {
for(EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) if(r.getInput().apply(stack)) return true;
for (EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES)
if (r.getInput().apply(stack)) return true;
return false;
}
@ -153,13 +156,13 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
}
@Override
public boolean canInsert(int index, ItemStack stack, boolean automation) {
return !automation || !getRecipesForInput(stack).isEmpty();
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || isPossibleInput(stack);
}
@Override
public boolean canExtract(int index, ItemStack stack, boolean automation) {
return !automation || getRecipesForInput(stack).isEmpty();
public IRemover getRemover() {
return (slot, automation) -> !automation || !isPossibleInput(inv.getStackInSlot(0));
}
@Override

View file

@ -10,9 +10,10 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.CapabilityEnergy;
@ -73,13 +74,13 @@ public class TileEntityEnergizer extends TileEntityInventoryBase{
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || (i == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || (slot == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !EnchantmentHelper.hasBindingCurse(stack) && !automation || (slot == 1);
public IRemover getRemover() {
return (slot, automation) -> !EnchantmentHelper.hasBindingCurse(inv.getStackInSlot(slot)) && !automation || (slot == 1);
}
public int getEnergyScaled(int i) {

View file

@ -10,8 +10,9 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -74,19 +75,19 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || (i == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || (slot == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
}
@Override
public IRemover getRemover() {
return (slot, automation) -> !automation || slot == 1;
}
public int getEnergyScaled(int i) {
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || slot == 1;
}
@Override
public int getEnergyToSplitShare() {
return this.storage.getEnergyStored();

View file

@ -18,6 +18,8 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.state.IBlockState;
@ -138,13 +140,13 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation) {
return !automation || i < 6;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || slot < 6;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
return !automation || slot >= 6;
public IRemover getRemover() {
return (slot, automation) -> !automation || slot >= 6;
}
@Override

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import java.util.List;
import java.util.Optional;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.init.Items;
@ -85,8 +86,8 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation;
public IRemover getRemover() {
return (slot, automation) -> !automation;
}
private static void feedAnimal(EntityAnimal animal) {

View file

@ -13,6 +13,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.state.IBlockState;
@ -53,11 +55,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
ItemStack toSplit = StackUtil.getEmpty();
if (!StackUtil.isValid(first) && StackUtil.isValid(second) && second.getCount() > 1) {
toSplit = second;
}
else if(!StackUtil.isValid(second) && StackUtil.isValid(first) && first.getCount() > 1){
} else if (!StackUtil.isValid(second) && StackUtil.isValid(first) && first.getCount() > 1) {
toSplit = first;
}
else if(ItemUtil.canBeStacked(first, second)){
} else if (ItemUtil.canBeStacked(first, second)) {
if (first.getCount() < first.getMaxStackSize() || second.getCount() < second.getMaxStackSize()) {
if (!((first.getCount() <= second.getCount() + 1 && first.getCount() >= second.getCount() - 1) || (second.getCount() <= first.getCount() + 1 && second.getCount() >= first.getCount() - 1))) {
toSplit = first;
@ -120,8 +120,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
this.storage.extractEnergyInternal(ENERGY_USE, false);
}
smelted = true;
}
else{
} else {
this.firstSmeltTime = 0;
}
@ -135,8 +134,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
this.storage.extractEnergyInternal(ENERGY_USE, false);
}
smelted = true;
}
else{
} else {
this.secondSmeltTime = 0;
}
@ -159,17 +157,20 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || ((i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && StackUtil.isValid(FurnaceRecipes.instance().getSmeltingResult(stack)));
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || ((slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2) && StackUtil.isValid(FurnaceRecipes.instance().getSmeltingResult(stack)));
}
@Override
public IRemover getRemover() {
return (slot, automation) -> !automation || (slot == SLOT_OUTPUT_1 || slot == SLOT_OUTPUT_2);
}
public boolean canSmeltOn(int theInput, int theOutput) {
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
if (StackUtil.isValid(output)) {
if(!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || (this.inv.getStackInSlot(theOutput).isItemEqual(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize()-output.getCount())){
return true;
}
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || (this.inv.getStackInSlot(theOutput).isItemEqual(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize() - output.getCount())) { return true; }
}
}
@ -180,8 +181,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput))) {
this.inv.setStackInSlot(theOutput, output.copy());
}
else if(this.inv.getStackInSlot(theOutput).getItem() == output.getItem()){
} else if (this.inv.getStackInSlot(theOutput).getItem() == output.getItem()) {
this.inv.getStackInSlot(theOutput).grow(output.getCount());
}
@ -196,11 +196,6 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
return this.secondSmeltTime * i / SMELT_TIME;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || (slot == SLOT_OUTPUT_1 || slot == SLOT_OUTPUT_2);
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (buttonID == 0) {

View file

@ -10,12 +10,13 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.state.IBlockState;
@ -108,8 +109,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
this.storage.extractEnergyInternal(ENERGY_USE, false);
}
crushed = storage.getEnergyStored() >= ENERGY_USE;
}
else{
} else {
this.firstCrushTime = 0;
}
@ -127,8 +127,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
this.storage.extractEnergyInternal(ENERGY_USE, false);
}
crushed = storage.getEnergyStored() >= ENERGY_USE;
}
else{
} else {
this.secondCrushTime = 0;
}
}
@ -156,8 +155,13 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || ((i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && CrusherRecipeRegistry.getRecipeFromInput(stack) != null);
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || ((slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2) && CrusherRecipeRegistry.getRecipeFromInput(stack) != null);
}
@Override
public IRemover getRemover() {
return (slot, automation) -> !automation || (slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2);
}
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) {
@ -173,9 +177,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
if (StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD) {
outputTwo.setItemDamage(0);
}
if((!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput)) || (this.inv.getStackInSlot(theFirstOutput).isItemEqual(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize()-outputOne.getCount())) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput)) || (this.inv.getStackInSlot(theSecondOutput).isItemEqual(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize()-outputTwo.getCount())))){
return true;
}
if ((!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput)) || (this.inv.getStackInSlot(theFirstOutput).isItemEqual(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize() - outputOne.getCount())) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput)) || (this.inv.getStackInSlot(theSecondOutput).isItemEqual(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize() - outputTwo.getCount())))) { return true; }
}
}
return false;
@ -195,8 +197,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
}
if (!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput))) {
this.inv.setStackInSlot(theFirstOutput, outputOne.copy());
}
else if(this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()){
} else if (this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()) {
this.inv.setStackInSlot(theFirstOutput, StackUtil.grow(this.inv.getStackInSlot(theFirstOutput), outputOne.getCount()));
}
}
@ -210,8 +211,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
if (rand <= recipe.getSecondChance()) {
if (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))) {
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
}
else if(this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()){
} else if (this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()) {
this.inv.setStackInSlot(theSecondOutput, StackUtil.grow(this.inv.getStackInSlot(theSecondOutput), outputTwo.getCount()));
}
}
@ -232,11 +232,6 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
return this.secondCrushTime * i / this.getMaxCrushTime();
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || (slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2);
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (buttonID == 0) {

View file

@ -10,15 +10,20 @@
package de.ellpeck.actuallyadditions.mod.tile;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.cyclops.commoncapabilities.capability.itemhandler.SlotlessItemHandlerConfig;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
@ -26,10 +31,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.cyclops.commoncapabilities.capability.itemhandler.SlotlessItemHandlerConfig;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor {
@ -131,8 +132,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if (tile != null) {
for (EnumFacing facing : EnumFacing.values()) {
IItemHandler normal = null;
if(tile.getClass() == TileEntityFurnace.class)
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (tile.getClass() == TileEntityFurnace.class) normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
else if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
}
@ -227,14 +227,11 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if (this.sideToPut >= 6) {
this.sideToPut = -1;
}
else if(this.sideToPut < -1){
} else if (this.sideToPut < -1) {
this.sideToPut = 5;
}
else if(this.sideToPull >= 6){
} else if (this.sideToPull >= 6) {
this.sideToPull = -1;
}
else if(this.sideToPull < -1){
} else if (this.sideToPull < -1) {
this.sideToPull = 5;
}
@ -310,12 +307,12 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || i == 0;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || slot == 0;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || slot == 0;
public IRemover getRemover() {
return (slot, automation) -> !automation || slot == 0;
}
}

View file

@ -11,6 +11,8 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -67,12 +69,12 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
return this.inv;
}
public boolean canInsert(int slot, ItemStack stack, boolean automation) {
return true;
public IAcceptor getAcceptor() {
return ItemStackHandlerAA.ACCEPT_TRUE;
}
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
return true;
public IRemover getRemover() {
return ItemStackHandlerAA.REMOVE_TRUE;
}
public int getMaxStackSize(int slot) {
@ -112,13 +114,13 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
}
@Override
public boolean canAccept(int slot, ItemStack stack, boolean fromAutomation) {
return TileEntityInventoryBase.this.canInsert(slot, stack, fromAutomation);
public IAcceptor getAcceptor() {
return TileEntityInventoryBase.this.getAcceptor();
}
@Override
public boolean canRemove(int slot, boolean byAutomation) {
return TileEntityInventoryBase.this.canExtract(slot, this.getStackInSlot(slot), byAutomation);
public IRemover getRemover() {
return TileEntityInventoryBase.this.getRemover();
}
@Override

View file

@ -11,6 +11,8 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -39,14 +41,11 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
if (item != null) {
if (item.isRepairable() && item.getMaxDamage(stack) > 0) {
return true;
}
else{
} else {
String reg = item.getRegistryName().toString();
if (reg != null) {
for (String strg : ConfigStringListValues.REPAIRER_EXTRA_WHITELIST.getValue()) {
if(reg.equals(strg)){
return true;
}
if (reg.equals(strg)) { return true; }
}
}
}
@ -83,8 +82,7 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
this.inv.setStackInSlot(SLOT_OUTPUT, input.copy());
this.inv.setStackInSlot(SLOT_INPUT, StackUtil.getEmpty());
this.nextRepairTick = 0;
}
else{
} else {
if (this.storage.getEnergyStored() >= ENERGY_USE) {
this.nextRepairTick++;
this.storage.extractEnergyInternal(ENERGY_USE, false);
@ -102,8 +100,7 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
}
}
}
}
else{
} else {
this.nextRepairTick = 0;
}
@ -114,8 +111,8 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || i == SLOT_INPUT;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || slot == SLOT_INPUT;
}
@SideOnly(Side.CLIENT)
@ -124,15 +121,13 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
}
public int getItemDamageToScale(int i) {
if(StackUtil.isValid(this.inv.getStackInSlot(SLOT_INPUT))){
return (this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage()-this.inv.getStackInSlot(SLOT_INPUT).getItemDamage())*i/this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage();
}
if (StackUtil.isValid(this.inv.getStackInSlot(SLOT_INPUT))) { return (this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage() - this.inv.getStackInSlot(SLOT_INPUT).getItemDamage()) * i / this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage(); }
return 0;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || slot == SLOT_OUTPUT;
public IRemover getRemover() {
return (slot, automation) -> !automation || slot == SLOT_OUTPUT;
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
@ -195,13 +196,8 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation) {
return !fromAutomation;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
return true;
public IAcceptor getAcceptor() {
return (stack, slot, automation) -> !automation;
}
@Override

View file

@ -10,6 +10,10 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
public class TileEntityPhantomBreaker extends TileEntityPhantomPlacer {
public TileEntityPhantomBreaker() {
@ -17,4 +21,14 @@ public class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
this.isBreaker = true;
}
@Override
public IAcceptor getAcceptor() {
return ItemStackHandlerAA.ACCEPT_FALSE;
}
@Override
public IRemover getRemover() {
return ItemStackHandlerAA.REMOVE_TRUE;
}
}

View file

@ -11,7 +11,8 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
@ -25,8 +26,8 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || this.isBoundThingInRange();
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || this.isBoundThingInRange();
}
@Override
@ -35,9 +36,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
if (tile != null) {
for (EnumFacing facing : EnumFacing.values()) {
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
return true;
}
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) { return true; }
}
}
}
@ -50,7 +49,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || this.isBoundThingInRange();
public IRemover getRemover() {
return (slot, automation) -> !automation || this.isBoundThingInRange();
}
}

View file

@ -13,6 +13,9 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
@ -94,8 +97,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
if (this.currentTime <= 0) {
this.doWork();
}
}
else{
} else {
this.currentTime = 30;
}
}
@ -106,8 +108,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.sendUpdate();
}
}
else{
} else {
if (this.boundPosition != null) {
this.renderParticles();
}
@ -141,8 +142,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.markDirty();
}
}
}
else{
} else {
int theSlot = StackUtil.findFirstFilled(this.inv);
if (theSlot == -1) return;
inv.setStackInSlot(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, inv.getStackInSlot(theSlot)));
@ -190,13 +190,13 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean automation){
return !automation || !this.isBreaker;
public IAcceptor getAcceptor() {
return ItemStackHandlerAA.ACCEPT_TRUE;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean automation){
return !automation || this.isBreaker;
public IRemover getRemover() {
return ItemStackHandlerAA.REMOVE_FALSE;
}
@Override
@ -213,8 +213,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
public void onButtonPressed(int buttonID, EntityPlayer player) {
if (this.side + 1 >= EnumFacing.values().length) {
this.side = 0;
}
else{
} else {
this.side++;
}

View file

@ -10,6 +10,9 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
public class TileEntityPlacer extends TileEntityBreaker {
public TileEntityPlacer() {
@ -17,4 +20,9 @@ public class TileEntityPlacer extends TileEntityBreaker{
this.isPlacer = true;
}
@Override
public IAcceptor getAcceptor() {
return ItemStackHandlerAA.ACCEPT_TRUE;
}
}

View file

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -87,13 +88,8 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
}
@Override
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation) {
return !fromAutomation;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
return true;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation;
}
@Override

View file

@ -10,10 +10,13 @@
package de.ellpeck.actuallyadditions.mod.tile;
import java.util.List;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemSolidifiedExperience;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
@ -22,8 +25,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import java.util.List;
public class TileEntityXPSolidifier extends TileEntityInventoryBase implements IButtonReactor {
private static final int[] XP_MAP = new int[256];
@ -162,13 +163,8 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
}
@Override
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation) {
return slot == 1 && stack.getItem() == InitItems.itemSolidifiedExperience;
}
@Override
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
return true;
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> slot == 1 && stack.getItem() == InitItems.itemSolidifiedExperience;
}
@Override

View file

@ -104,6 +104,7 @@ public final class AwfulUtil{
error += ("\n" + i++ + ": " + (k == null ? "null" : (k.getClass().getSimpleName() + " <- CLASS | INSTANCE -> " + k.toString() + ", ")));
}
error += "\n" + "The current side is: " + FMLCommonHandler.instance().getEffectiveSide();
error += "\n" + "Report this to https://github.com/Ellpeck/ActuallyAdditions/issues";
throw new IllegalStateException(error);
}
}

View file

@ -20,8 +20,32 @@ import net.minecraftforge.items.ItemStackHandler;
*/
public class ItemStackHandlerAA extends ItemStackHandler {
public ItemStackHandlerAA(int slots) {
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 ItemStackHandlerAA(NonNullList<ItemStack> stacks, IAcceptor acceptor, IRemover remover) {
super(stacks);
this.acceptor = acceptor;
this.remover = remover;
}
public ItemStackHandlerAA(int slots, IAcceptor acceptor, IRemover remover) {
super(slots);
this.acceptor = acceptor;
this.remover = remover;
}
public ItemStackHandlerAA(NonNullList<ItemStack> stacks) {
this(stacks, ACCEPT_TRUE, REMOVE_TRUE);
}
public ItemStackHandlerAA(int slots) {
this(slots, ACCEPT_TRUE, REMOVE_TRUE);
}
public NonNullList<ItemStack> getItems() {
@ -48,11 +72,33 @@ public class ItemStackHandlerAA extends ItemStackHandler {
return super.extractItem(slot, amount, simulate);
}
public boolean canAccept(int slot, ItemStack stack, boolean fromAutomation) {
return true;
public final boolean canAccept(int slot, ItemStack stack, boolean automation) {
IAcceptor acceptor = getAcceptor();
try {
return acceptor.canAccept(slot, stack, automation);
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
}
public boolean canRemove(int slot, boolean byAutomation) {
return true;
public final boolean canRemove(int slot, boolean automation) {
return getRemover().canRemove(slot, automation);
}
public IAcceptor getAcceptor() {
return acceptor;
}
public IRemover getRemover() {
return remover;
}
public static interface IAcceptor {
boolean canAccept(int slot, ItemStack stack, boolean automation);
}
public static interface IRemover {
boolean canRemove(int slot, boolean automation);
}
}

View file

@ -10,7 +10,6 @@
package de.ellpeck.actuallyadditions.mod.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -23,7 +22,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
public final class StackUtil {
@ -67,42 +65,6 @@ public final class StackUtil {
return true;
}
/**
* Checks if all provided itemstacks will fit in the handler. If you have an AA item handler, use the more sensitive below methods.
* @param inv The Item handler
* @param stacks The stacks to add
* @return If all stacks fit fully. If even one item would not fit, the method returns false.
*/
public static boolean canAddAll(IItemHandler inv, List<ItemStack> stacks) {
int slotMax = inv.getSlots();
int counter = 0;
for (ItemStack s : stacks = merge(stacks)) {
for (int i = 0; i < slotMax; i++) {
s = inv.insertItem(i, s, true);
if (s.isEmpty()) break;
}
if (s.isEmpty()) counter++;
}
return counter == stacks.size();
}
/**
* Adds all itemstacks in a list to an item handler. If you have an AA item handler, use the more sensitive below methods.
* @param inv The Item handler
* @param stacks The stacks to add
*/
public static void addAll(IItemHandler inv, List<ItemStack> stacks) {
int slotMax = inv.getSlots();
for (ItemStack s : stacks) {
for (int i = 0; i < slotMax; i++) {
s = inv.insertItem(i, s, false);
if (s.isEmpty()) break;
}
}
}
/**
* Checks if all provided itemstacks will fit in the AA handler. Use addAll below to actually add the stacks. This is strictly a check function.
* @param inv The AA Item handler
@ -111,13 +73,11 @@ public final class StackUtil {
* @return If all stacks fit fully. If even one item would not fit, the method returns false.
*/
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, boolean fromAutomation) {
int slotMax = inv.getSlots();
int counter = 0;
for (ItemStack s : stacks = merge(stacks)) {
for (int i = 0; i < slotMax; i++) {
s = inv.insertItem(i, s, true, fromAutomation);
ItemStackHandlerAA dummy = testDummy(inv, 0, inv.getSlots());
for (ItemStack s : stacks) {
for (int i = 0; i < dummy.getSlots(); i++) {
s = dummy.insertItem(i, s, false, fromAutomation);
if (s.isEmpty()) break;
}
if (s.isEmpty()) counter++;
@ -152,10 +112,10 @@ public final class StackUtil {
*/
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, int slot, int endSlot, boolean fromAutomation) {
int counter = 0;
for (ItemStack s : stacks = merge(stacks)) {
for (int i = slot; i < endSlot; i++) {
s = inv.insertItem(i, s, true, fromAutomation);
ItemStackHandlerAA dummy = testDummy(inv, slot, endSlot);
for (ItemStack s : stacks) {
for (int i = 0; i < dummy.getSlots(); i++) {
s = dummy.insertItem(i, s, false, fromAutomation);
if (s.isEmpty()) break;
}
if (s.isEmpty()) counter++;
@ -249,31 +209,14 @@ public final class StackUtil {
}
/**
* Combines every stack in the given list into larger stacks when possible.
* Constructs a clone of the given item handler, from the given slots. The new item handler will have the provided slot as slot 0.
* This is used for testing the ability to add all itemstacks, and should not be used for anything else.
*/
public static List<ItemStack> merge(List<ItemStack> stacks) {
if (stacks.isEmpty()) return stacks;
ItemStack[] array = stacks.toArray(new ItemStack[0]);
List<ItemStack> list = new ArrayList<>();
while (!array[array.length - 1].isEmpty()) {
ItemStack merged = ItemStack.EMPTY;
for (int i = 0; i < array.length; i++) {
ItemStack stack = array[i];
if (merged.isEmpty()) {
merged = stack.copy();
array[i] = ItemStack.EMPTY;
} else if (ItemHandlerHelper.canItemStacksStack(merged, stack)) {
merged.grow(stack.getCount());
array[i] = ItemStack.EMPTY;
} else break;
}
list.add(merged);
merged = ItemStack.EMPTY;
}
return list;
public static ItemStackHandlerAA testDummy(ItemStackHandlerAA inv, int slot, int endSlot) {
NonNullList<ItemStack> stacks = NonNullList.withSize(endSlot - slot, getEmpty());
for (int i = slot; i < endSlot; i++)
stacks.set(i - slot, inv.getStackInSlot(i).copy());
return new ItemStackHandlerAA(stacks, inv.getAcceptor(), inv.getRemover());
}
}