2015-08-18 20:40:55 -04:00
|
|
|
package team.chisel.inventory;
|
2014-12-14 20:05:39 +00:00
|
|
|
|
2020-11-24 08:06:51 +03:00
|
|
|
import java.util.ArrayList;
|
2015-05-29 15:52:03 -04:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2015-08-18 20:40:55 -04:00
|
|
|
import com.cricketcraft.chisel.api.IChiselItem;
|
|
|
|
|
|
|
|
|
|
import team.chisel.item.chisel.ItemChisel;
|
|
|
|
|
import team.chisel.utils.General;
|
2014-04-21 19:13:15 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-02-06 21:03:17 -05:00
|
|
|
import net.minecraft.item.ItemTool;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public class InventoryChiselSelection implements IInventory {
|
|
|
|
|
|
2020-11-24 08:06:51 +03:00
|
|
|
ItemStack chisel;
|
2015-01-12 20:42:32 -05:00
|
|
|
public final static int normalSlots = 60;
|
2015-01-07 19:50:18 -05:00
|
|
|
ContainerChisel container;
|
|
|
|
|
ItemStack[] inventory;
|
2020-11-24 08:06:51 +03:00
|
|
|
private int currentScroll = 0;
|
|
|
|
|
private int maxScroll = 0;
|
2015-01-07 19:50:18 -05:00
|
|
|
|
|
|
|
|
public InventoryChiselSelection(ItemStack c) {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
inventory = new ItemStack[normalSlots + 1];
|
|
|
|
|
chisel = c;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 08:06:51 +03:00
|
|
|
public void setCurrentScroll(int currentScroll) {
|
2020-11-24 08:21:52 +03:00
|
|
|
if (this.currentScroll != currentScroll) {
|
|
|
|
|
this.currentScroll = currentScroll;
|
|
|
|
|
updateItems();
|
|
|
|
|
}
|
2020-11-24 08:06:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCurrentScroll() {
|
|
|
|
|
return currentScroll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxScroll() {
|
|
|
|
|
return maxScroll;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public void onInventoryUpdate(int slot) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSizeInventory() {
|
|
|
|
|
return normalSlots + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlot(int var1) {
|
|
|
|
|
return inventory[var1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateInventoryState(int slot) {
|
|
|
|
|
onInventoryUpdate(slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack decrStackSize(int slot, int amount) {
|
|
|
|
|
if (this.inventory[slot] != null) {
|
|
|
|
|
ItemStack stack;
|
|
|
|
|
if (this.inventory[slot].stackSize <= amount) {
|
|
|
|
|
stack = this.inventory[slot];
|
|
|
|
|
this.inventory[slot] = null;
|
|
|
|
|
updateInventoryState(slot);
|
|
|
|
|
return stack;
|
|
|
|
|
} else {
|
|
|
|
|
stack = this.inventory[slot].splitStack(amount);
|
|
|
|
|
|
|
|
|
|
if (this.inventory[slot].stackSize == 0)
|
|
|
|
|
this.inventory[slot] = null;
|
|
|
|
|
|
|
|
|
|
updateInventoryState(slot);
|
|
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getInventoryName() {
|
|
|
|
|
return "container.chisel";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasCustomInventoryName() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
|
return 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void markDirty() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearItems() {
|
|
|
|
|
for (int i = 0; i < normalSlots; i++) {
|
|
|
|
|
inventory[i] = null;
|
|
|
|
|
}
|
2020-11-24 08:06:51 +03:00
|
|
|
maxScroll = 0;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ItemStack getStackInSpecialSlot() {
|
|
|
|
|
return inventory[normalSlots];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateItems() {
|
|
|
|
|
ItemStack chiseledItem = inventory[normalSlots];
|
|
|
|
|
clearItems();
|
|
|
|
|
|
|
|
|
|
if (chiseledItem == null) {
|
|
|
|
|
container.onChiselSlotChanged();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item item = chiseledItem.getItem();
|
|
|
|
|
if (item == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Block.getBlockFromItem(item) == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-01-20 18:26:14 -05:00
|
|
|
if (!((IChiselItem) chisel.getItem()).canChisel(container.playerInventory.player.worldObj, chisel, General.getVariation(chiseledItem)))
|
2015-01-14 21:33:43 -05:00
|
|
|
return;
|
|
|
|
|
|
2020-11-24 08:06:51 +03:00
|
|
|
List<ItemStack> list2 = container.carving.getItemsForChiseling(chiseledItem);
|
|
|
|
|
// DEBUG! REMOVE:
|
|
|
|
|
List<ItemStack> list = new ArrayList<>(list2);
|
|
|
|
|
list.addAll(list2);
|
|
|
|
|
if (list.size() > 61) {
|
|
|
|
|
list = list.subList(0, 61);
|
|
|
|
|
}
|
|
|
|
|
maxScroll = list.size();
|
|
|
|
|
int activeVariations = 0;
|
|
|
|
|
while (activeVariations < normalSlots && activeVariations + currentScroll < list.size()) {
|
|
|
|
|
if (Block.blockRegistry.getNameForObject(Block.getBlockFromItem(list.get(activeVariations + currentScroll).getItem())) != null) {
|
|
|
|
|
inventory[activeVariations] = list.get(activeVariations + currentScroll);
|
2015-06-20 22:16:00 -04:00
|
|
|
activeVariations++;
|
|
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container.onChiselSlotChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
|
|
|
|
ItemStack stack = getStackInSlot(slot);
|
|
|
|
|
|
|
|
|
|
if (stack == null)
|
|
|
|
|
return null;
|
|
|
|
|
inventory[slot] = null;
|
|
|
|
|
|
|
|
|
|
updateInventoryState(slot);
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
|
|
|
|
inventory[slot] = stack;
|
|
|
|
|
updateInventoryState(slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void openInventory() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void closeInventory() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
2015-08-06 00:00:22 -04:00
|
|
|
// Really didn't think people would chisel a shovel
|
2015-02-06 21:03:17 -05:00
|
|
|
if (stack.getItem() instanceof ItemTool) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
return !(stack != null && (stack.getItem() instanceof ItemChisel)) && i == normalSlots;
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|