mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-11 15:57:31 +00:00
feat(input slot): add item validation
Add Item validation to input slot, so that only chisellable items can be inserted. Prevents insertion of random items and abuse of Chisels as a single-slot backpack.
This commit is contained in:
2 files changed
+23
-16
No files matched your search
@@ -1,16 +1,15 @@
|
||||
package team.chisel.inventory;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.item.chisel.ItemChisel;
|
||||
import team.chisel.utils.General;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.item.chisel.ItemChisel;
|
||||
import team.chisel.utils.General;
|
||||
|
||||
public class ContainerChisel extends Container {
|
||||
|
||||
@@ -98,12 +97,10 @@ public class ContainerChisel extends Container {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (slotIdx < InventoryChiselSelection.normalSlots + 1 && itemstack1 != null) {
|
||||
entity.inventory.setItemStack(itemstack1.copy());
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
itemstack1 = entity.inventory.getItemStack();
|
||||
entity.inventory.setItemStack(null);
|
||||
}
|
||||
entity.inventory.setItemStack(itemstack1.copy());
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
itemstack1 = entity.inventory.getItemStack();
|
||||
entity.inventory.setItemStack(null);
|
||||
|
||||
if (!this.mergeItemStack(itemstack1, InventoryChiselSelection.normalSlots + 1, InventoryChiselSelection.normalSlots + 1 + 36, false)) {
|
||||
return null;
|
||||
@@ -112,7 +109,7 @@ public class ContainerChisel extends Container {
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.putStack(itemstack1);
|
||||
slot.onSlotChanged();
|
||||
@@ -131,6 +128,18 @@ public class ContainerChisel extends Container {
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
* Only Chiselable allowed
|
||||
*
|
||||
* @author Léa Gris
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
return ((Slot) this.inventorySlots.get(reversOrder ? toIndex - 1 : fromIndex)).isItemValid(par1ItemStack)
|
||||
&& super.mergeItemStack(par1ItemStack, fromIndex, toIndex, reversOrder);
|
||||
}
|
||||
|
||||
public void onChiselSlotChanged() {
|
||||
ItemStack stack = playerInventory.mainInventory[chiselSlot];
|
||||
if (stack == null || !stack.isItemEqual(chisel))
|
||||
|
||||
Reference in new issue
Block a user