Fix more bugs
This commit is contained in:
@@ -11,6 +11,8 @@ import net.minecraft.inventory.Slot;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public abstract class ContainerBase extends Container {
|
public abstract class ContainerBase extends Container {
|
||||||
private TileBase tile;
|
private TileBase tile;
|
||||||
private EntityPlayer player;
|
private EntityPlayer player;
|
||||||
@@ -58,7 +60,7 @@ public abstract class ContainerBase extends Container {
|
|||||||
Slot slot = id >= 0 ? getSlot(id) : null;
|
Slot slot = id >= 0 ? getSlot(id) : null;
|
||||||
|
|
||||||
if (slot instanceof SlotFilter) {
|
if (slot instanceof SlotFilter) {
|
||||||
if (((SlotFilter) slot).isWithSize()) {
|
if (((SlotFilter) slot).allowsSize()) {
|
||||||
if (clickType == ClickType.QUICK_MOVE) {
|
if (clickType == ClickType.QUICK_MOVE) {
|
||||||
slot.putStack(ItemStack.EMPTY);
|
slot.putStack(ItemStack.EMPTY);
|
||||||
} else if (!player.inventory.getItemStack().isEmpty()) {
|
} else if (!player.inventory.getItemStack().isEmpty()) {
|
||||||
@@ -106,14 +108,14 @@ public abstract class ContainerBase extends Container {
|
|||||||
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
|
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
|
||||||
for (int i = begin; i < end; ++i) {
|
for (int i = begin; i < end; ++i) {
|
||||||
if (API.instance().getComparer().isEqualNoQuantity(getStackFromSlot(getSlot(i)), stack)) {
|
if (API.instance().getComparer().isEqualNoQuantity(getStackFromSlot(getSlot(i)), stack)) {
|
||||||
return null;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = begin; i < end; ++i) {
|
for (int i = begin; i < end; ++i) {
|
||||||
Slot slot = getSlot(i);
|
Slot slot = getSlot(i);
|
||||||
|
|
||||||
if (getStackFromSlot(slot) == null && slot.isItemValid(stack)) {
|
if (getStackFromSlot(slot).isEmpty() && slot.isItemValid(stack)) {
|
||||||
slot.putStack(ItemHandlerHelper.copyStackWithSize(stack, 1));
|
slot.putStack(ItemHandlerHelper.copyStackWithSize(stack, 1));
|
||||||
slot.onSlotChanged();
|
slot.onSlotChanged();
|
||||||
|
|
||||||
@@ -124,6 +126,7 @@ public abstract class ContainerBase extends Container {
|
|||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
private ItemStack getStackFromSlot(Slot slot) {
|
private ItemStack getStackFromSlot(Slot slot) {
|
||||||
ItemStack stackInSlot = slot.getStack();
|
ItemStack stackInSlot = slot.getStack();
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class ContainerInterface extends ContainerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
addSlotToContainer(new SlotFilter(tile.getExportSpecimenItems(), i, 8 + (18 * i), 54, SlotFilter.SPECIMEN_SIZE));
|
addSlotToContainer(new SlotFilter(tile.getExportSpecimenItems(), i, 8 + (18 * i), 54, SlotFilter.FILTER_ALLOW_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class ContainerProcessingPatternEncoder extends ContainerBase {
|
|||||||
int y = 20;
|
int y = 20;
|
||||||
|
|
||||||
for (int i = 0; i < 9 * 2; ++i) {
|
for (int i = 0; i < 9 * 2; ++i) {
|
||||||
addSlotToContainer(new SlotFilter(encoder.getConfiguration(), i, x, y, SlotFilter.SPECIMEN_SIZE));
|
addSlotToContainer(new SlotFilter(encoder.getConfiguration(), i, x, y, SlotFilter.FILTER_ALLOW_SIZE));
|
||||||
|
|
||||||
x += 18;
|
x += 18;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import javax.annotation.Nonnull;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class SlotFilter extends SlotItemHandler {
|
public class SlotFilter extends SlotItemHandler {
|
||||||
public static final int SPECIMEN_SIZE = 1;
|
public static final int FILTER_ALLOW_SIZE = 1;
|
||||||
public static final int SPECIMEN_BLOCK = 2;
|
public static final int FILTER_ALLOW_BLOCKS = 2;
|
||||||
|
|
||||||
private int flags = 0;
|
private int flags = 0;
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public class SlotFilter extends SlotItemHandler {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(@Nonnull ItemStack stack) {
|
public boolean isItemValid(@Nonnull ItemStack stack) {
|
||||||
if (super.isItemValid(stack)) {
|
if (super.isItemValid(stack)) {
|
||||||
if (isBlockOnly()) {
|
if (allowsBlocks()) {
|
||||||
return stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable || stack.getItem() instanceof ItemSkull;
|
return stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable || stack.getItem() instanceof ItemSkull;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,19 +50,19 @@ public class SlotFilter extends SlotItemHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putStack(@Nonnull ItemStack stack) {
|
public void putStack(@Nonnull ItemStack stack) {
|
||||||
if (!stack.isEmpty() && !isWithSize()) {
|
if (!stack.isEmpty() && !allowsSize()) {
|
||||||
stack.setCount(1);
|
stack.setCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.putStack(stack);
|
super.putStack(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithSize() {
|
public boolean allowsSize() {
|
||||||
return (flags & SPECIMEN_SIZE) == SPECIMEN_SIZE;
|
return (flags & FILTER_ALLOW_SIZE) == FILTER_ALLOW_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlockOnly() {
|
public boolean allowsBlocks() {
|
||||||
return (flags & SPECIMEN_BLOCK) == SPECIMEN_BLOCK;
|
return (flags & FILTER_ALLOW_BLOCKS) == FILTER_ALLOW_BLOCKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBlockState getBlockState(IBlockAccess world, BlockPos pos, ItemStack stack) {
|
public static IBlockState getBlockState(IBlockAccess world, BlockPos pos, ItemStack stack) {
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ public class SlotFilterType extends SlotFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithSize() {
|
public boolean allowsSize() {
|
||||||
return super.isWithSize() && type.getType() != IType.FLUIDS;
|
return super.allowsSize() && type.getType() != IType.FLUIDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBlockOnly() {
|
public boolean allowsBlocks() {
|
||||||
return super.isBlockOnly() && type.getType() == IType.ITEMS;
|
return super.allowsBlocks() && type.getType() == IType.ITEMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user