mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 16:27:45 +00:00
Fix up issues with breaking chisels (Fixes #162)
This commit is contained in:
1 parent
4de7ef8190
commit
5188e39b57
8 files changed
+41
-28
No files matched your search
@@ -39,8 +39,9 @@ public interface IChiselItem {
|
||||
* The {@link ItemStack} representing the chisel
|
||||
* @param target
|
||||
* The {@link ItemStack} representing the target item
|
||||
* @return True if the chisel should be damaged. False otherwise.
|
||||
*/
|
||||
void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ICarvingVariation target);
|
||||
boolean onChisel(World world, IInventory inv, int slot, ItemStack chisel, ICarvingVariation 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.
|
||||
|
||||
@@ -209,7 +209,12 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
/** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */
|
||||
private void chiselItem(int chiseled) {
|
||||
if (!worldObj.isRemote) {
|
||||
((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], General.getVariation(inventory[TARGET]));
|
||||
if (((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], General.getVariation(inventory[TARGET]))) {
|
||||
inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() - 1);
|
||||
if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
|
||||
inventory[CHISEL] = null;
|
||||
}
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this, chiseled, true), worldObj.provider.dimensionId);
|
||||
} else {
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
|
||||
@@ -38,9 +38,6 @@ public class CarvableHelper {
|
||||
public static final int V4 = 7;
|
||||
public static final int CTMX = 8;
|
||||
|
||||
public CarvableHelper() {
|
||||
}
|
||||
|
||||
public ArrayList<CarvableVariation> variations = new ArrayList<CarvableVariation>();
|
||||
CarvableVariation[] map = new CarvableVariation[16];
|
||||
public boolean forbidChiseling = false;
|
||||
|
||||
@@ -60,7 +60,12 @@ public class SlotChiselSelection extends Slot {
|
||||
|
||||
selInventory.updateItems();
|
||||
|
||||
((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj, player.inventory, player.inventory.currentItem, container.chisel, General.getVariation(crafted));
|
||||
if (((IChiselItem) container.chisel.getItem()).onChisel(player.worldObj, player.inventory, player.inventory.currentItem, container.chisel, General.getVariation(crafted))) {
|
||||
container.chisel.damageItem(1, player);
|
||||
if (container.chisel.stackSize <= 0) {
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.worldObj.isRemote) {
|
||||
String sound = Carving.chisel.getVariationSound(crafted.getItem(), crafted.getItemDamage());
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -91,13 +90,6 @@ public final class ChiselController {
|
||||
} else {
|
||||
lastTickClick = event.world.getTotalWorldTime();
|
||||
}
|
||||
|
||||
if (!event.world.isRemote && event.entityPlayer.isSneaking()) {
|
||||
ChiselMode mode = General.getChiselMode(held);
|
||||
General.setChiselMode(held, ChiselMode.values()[(mode.ordinal() + 1) % 3]);
|
||||
event.entityPlayer.addChatMessage(new ChatComponentText(General.getChiselMode(held).toString()));
|
||||
break;
|
||||
}
|
||||
if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held)) {
|
||||
event.entityPlayer.openGui(Chisel.instance, 0, event.world, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.cricketcraft.chisel.item.chisel;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -93,6 +94,7 @@ public enum ChiselMode {
|
||||
private static void setVariation(EntityPlayer player, World world, int x, int y, int z, Block origBlock, int origMeta, ICarvingVariation v) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
ItemStack held = player.getCurrentEquippedItem();
|
||||
if (block == v.getBlock() && meta == v.getBlockMeta()) {
|
||||
return; // don't chisel to the same thing
|
||||
}
|
||||
@@ -100,9 +102,18 @@ public enum ChiselMode {
|
||||
return; // don't chisel if this doesn't match the target block (for the AOE modes)
|
||||
}
|
||||
|
||||
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v), (EntityPlayerMP) player);
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), v);
|
||||
if (held != null && held.getItem() instanceof IChiselItem) {
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
boolean breakChisel = false;
|
||||
if (((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), v)) {
|
||||
player.getCurrentEquippedItem().damageItem(1, player);
|
||||
if (player.getCurrentEquippedItem().stackSize <= 0) {
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
breakChisel = true;
|
||||
}
|
||||
}
|
||||
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v, breakChisel), (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
public ChiselMode next() {
|
||||
|
||||
@@ -7,7 +7,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -17,7 +16,6 @@ import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.config.Configurations;
|
||||
import com.cricketcraft.chisel.utils.GeneralClient;
|
||||
|
||||
public class ItemChisel extends Item implements IChiselItem {
|
||||
|
||||
@@ -88,13 +86,8 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ICarvingVariation target) {
|
||||
if (Configurations.allowChiselDamage) {
|
||||
chisel.setItemDamage(chisel.getItemDamage() + 1);
|
||||
if (chisel.getItemDamage() >= chisel.getMaxDamage()) {
|
||||
inv.decrStackSize(slot, 1);
|
||||
}
|
||||
}
|
||||
public boolean onChisel(World world, IInventory inv, int slot, ItemStack chisel, ICarvingVariation target) {
|
||||
return Configurations.allowChiselDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,9 +2,10 @@ package com.cricketcraft.chisel.network.message;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.client.GeneralChiselClient;
|
||||
import com.cricketcraft.chisel.item.chisel.ItemChisel;
|
||||
import com.cricketcraft.chisel.network.message.base.MessageCoords;
|
||||
@@ -21,11 +22,13 @@ public class MessageChiselSound extends MessageCoords {
|
||||
|
||||
private int block;
|
||||
private byte meta;
|
||||
private boolean breakChisel;
|
||||
|
||||
public MessageChiselSound(int x, int y, int z, ICarvingVariation v) {
|
||||
public MessageChiselSound(int x, int y, int z, ICarvingVariation v, boolean breakChisel) {
|
||||
super(x, y, z);
|
||||
this.block = Block.getIdFromBlock(v.getBlock());
|
||||
this.meta = (byte) v.getBlockMeta();
|
||||
this.breakChisel = breakChisel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,6 +36,7 @@ public class MessageChiselSound extends MessageCoords {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(block);
|
||||
buf.writeByte(meta);
|
||||
buf.writeBoolean(breakChisel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +44,7 @@ public class MessageChiselSound extends MessageCoords {
|
||||
super.fromBytes(buf);
|
||||
block = buf.readInt();
|
||||
meta = buf.readByte();
|
||||
breakChisel = buf.readBoolean();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<MessageChiselSound, IMessage> {
|
||||
@@ -48,6 +53,10 @@ public class MessageChiselSound extends MessageCoords {
|
||||
public IMessage onMessage(MessageChiselSound message, MessageContext ctx) {
|
||||
String sound = ItemChisel.carving.getVariationSound(Block.getBlockById(message.block), message.meta);
|
||||
GeneralChiselClient.spawnChiselEffect(message.x, message.y, message.z, sound);
|
||||
if (message.breakChisel) {
|
||||
EntityPlayer player = Chisel.proxy.getClientPlayer();
|
||||
player.renderBrokenItemStack(player.getCurrentEquippedItem());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user