Add IChiselItem#canChisel for stacks in the GUI

This commit is contained in:
tterrag1098 committed 2015-01-14 21:33:43 -05:00
1 parent 38f78df16d
commit cec1dbc99c
4 files changed
+32 -3

No files matched your search

@@ -40,6 +40,25 @@ public interface IChiselItem extends IChiselMode {
*/
void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target);
/**
* Called to check if this {@link ItemStack} can be chiseled in this chisel. If not, there will be no possible variants displayed in the GUI.
* <p>
* It is not necessary to take into account whether this item <i>has</i> any variants, this method will only be called after that check.
*
* @param world
* {@link World} object
* @param inv
* The inventory this chisel is currently in
* @param slot
* The slot index of the chisel in the inventory
* @param chisel
* The {@link ItemStack} representing the chisel
* @param target
* The {@link ItemStack} representing the target item
* @return True if the current target can be chiseled into anything. False otherwise.
*/
boolean canChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target);
/**
* Allows you to control if your item can chisel this block in the world.
*
@@ -8,6 +8,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
public class InventoryChiselSelection implements IInventory {
@@ -119,6 +120,9 @@ public class InventoryChiselSelection implements IInventory {
if (Block.getBlockFromItem(item) == null)
return;
if (!((IChiselItem) chisel.getItem()).canChisel(container.playerInventory.player.worldObj, this, container.playerInventory.currentItem, chisel, chiseledItem))
return;
ArrayList<ItemStack> list = container.carving.getItems(chiseledItem);
activeVariations = 0;
@@ -17,6 +17,7 @@ import com.cricketcraft.chisel.api.ChiselMode;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.config.Configurations;
import com.cricketcraft.chisel.init.ChiselBlocks;
import com.cricketcraft.chisel.utils.GeneralClient;
public class ItemChisel extends Item implements IChiselItem {
@@ -82,12 +83,17 @@ public class ItemChisel extends Item implements IChiselItem {
public ChiselMode getChiselMode(ItemStack itemStack) {
return ChiselMode.SINGLE;
}
@Override
public boolean canOpenGui(World world, EntityPlayer player, ItemStack chisel) {
return true;
}
@Override
public boolean canChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target) {
return Block.getBlockFromItem(target.getItem()) != ChiselBlocks.marble;
}
@Override
public void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target) {
if (Configurations.allowChiselDamage) {
@@ -22,7 +22,7 @@ public class ChiselGuiHandler implements IGuiHandler {
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new ContainerChisel(player.inventory, new InventoryChiselSelection(null));
return new ContainerChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem()));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)
@@ -40,7 +40,7 @@ public class ChiselGuiHandler implements IGuiHandler {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new GuiChisel(player.inventory, new InventoryChiselSelection(null));
return new GuiChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem()));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)