mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-16 10:45:02 +00:00
Fix left-click chiseling.
Remove chisel harvest levels. Both chisels in 1 ID
This commit is contained in:
1 parent
7a869bd522
commit
364eecdb12
12 files changed
+231
-153
No files matched your search
@@ -132,6 +132,7 @@ public class Chisel
|
||||
Configurations.config.load();
|
||||
Configurations.refreshConfig();
|
||||
|
||||
PacketHandler.init();
|
||||
ModTabs.load();
|
||||
ModBlocks.load();
|
||||
ModItems.load();
|
||||
@@ -213,52 +214,4 @@ public class Chisel
|
||||
Configurations.refreshConfig();
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onLeftClickBlock(PlayerInteractEvent event)
|
||||
{
|
||||
ItemStack held = event.entityPlayer.getCurrentEquippedItem();
|
||||
int slot = event.entityPlayer.inventory.currentItem;
|
||||
Carving carving = new Carving();
|
||||
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && held != null && held.getItem().equals(Configurations.featureEnabled("diamondChisel") ? ModItems.diamondChisel : ModItems.chisel))
|
||||
{
|
||||
int x = event.x, y = event.y, z = event.z;
|
||||
Block block = event.world.getBlock(x, y, z);
|
||||
int metadata = event.world.getBlockMetadata(x, y, z);
|
||||
CarvingVariation[] variations = carving.getVariations(block, metadata);
|
||||
|
||||
if (variations != null)
|
||||
{
|
||||
ItemStack target = new ItemStack(block, metadata);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
for (CarvingVariation v : variations)
|
||||
{
|
||||
if (v.block == Block.getBlockFromItem(target.getItem()) && v.meta == target.getItemDamage())
|
||||
{
|
||||
event.world.setBlock(x, y, z, v.block);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < variations.length; i++)
|
||||
{
|
||||
CarvingVariation v = variations[i];
|
||||
if (v.block == block && v.meta == metadata)
|
||||
{
|
||||
variations = ArrayUtils.remove(variations, i--);
|
||||
}
|
||||
}
|
||||
|
||||
int index = event.world.rand.nextInt(variations.length);
|
||||
CarvingVariation newVar = variations[index];
|
||||
event.world.setBlock(x, y, z, newVar.block);
|
||||
GeneralClient.playChiselSound(event.world, x, y, z, MOD_ID + ":chisel.fallback");
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,11 +92,13 @@ public class Crafting {
|
||||
|
||||
if (Configurations.chiselRecipe) {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.chisel, 1), new Object[]{" YY", " YY", "X ", 'X', Items.stick, 'Y', Items.iron_ingot}));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.diamondChisel, 1), new Object[]{" YY", " YY", "x ", 'x', "stickWood", 'Y', "ingotIron"}));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.chisel, 1, 1), new Object[]{" YY", " YY", "x ", 'x', "stickWood", 'Y', "ingotIron"}));
|
||||
} else {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.chisel, 1), new Object[]{" Y", "X ", 'X', Items.stick, 'Y', Items.iron_ingot}));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.diamondChisel, 1), new Object[]{" y", "x ", 'x', "stickWood", 'y', "ingotIron"}));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.chisel, 1, 1), new Object[]{" y", "x ", 'x', "stickWood", 'y', "ingotIron"}));
|
||||
}
|
||||
// Getting the proper diamond chisel from the deprecated one
|
||||
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.chisel, 1, 1), new ItemStack(ModItems.diamondChisel));
|
||||
|
||||
if (Configurations.featureEnabled("ballOfMoss"))
|
||||
GameRegistry.addRecipe(new ItemStack(ModItems.itemBallOMoss, 1), new Object[]{"XYX", "YXY", "XYX", 'X', Blocks.vine, 'Y', Items.stick});
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cricketcraft.chisel;
|
||||
|
||||
import com.cricketcraft.chisel.item.ItemChisel;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class PacketHandler
|
||||
{
|
||||
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(Chisel.MOD_ID);
|
||||
|
||||
public static void init()
|
||||
{
|
||||
INSTANCE.registerMessage(ItemChisel.PlaySoundHandler.class, ItemChisel.PacketPlaySound.class, 0, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.cricketcraft.chisel;
|
||||
|
||||
public class Packets// extends MessageHandlerBase
|
||||
{
|
||||
|
||||
//TODO packet
|
||||
public static final int CHISELED = 1;
|
||||
/*
|
||||
|
||||
public void onChiseled(Packet stream, EntityPlayer player) throws IOException
|
||||
{
|
||||
final int x = stream.readInt();
|
||||
final int y = stream.readInt();
|
||||
final int z = stream.readInt();
|
||||
|
||||
switch(FMLCommonHandler.instance().getEffectiveSide())
|
||||
{
|
||||
case SERVER:
|
||||
Packet packet = Chisel.packet.create(CHISELED).writeInt(x).writeInt(y).writeInt(z);
|
||||
Chisel.packet.sendToAllAround(packet, new TargetPoint(player.dimension, x, y, z, 30.0f));
|
||||
break;
|
||||
case CLIENT:
|
||||
Block block = player.worldObj.getBlock(x, y, z);
|
||||
int blockMeta = player.worldObj.getBlockMetadata(x, y, z);
|
||||
GeneralChiselClient.spawnChiselEffect(x, y, z, Carving.chisel.getVariationSound(block, blockMeta));
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Packet packet, INetHandler handler,
|
||||
EntityPlayer player, int command) throws IOException
|
||||
{
|
||||
switch(command)
|
||||
{
|
||||
case CHISELED:
|
||||
onChiseled(packet, player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
@@ -31,7 +31,6 @@ public class BlockCarvable extends Block implements ICarvable {
|
||||
setResistance(10.0F);
|
||||
setHardness(2.0F);
|
||||
setCreativeTab(ModTabs.tabOtherChiselBlocks);
|
||||
setHarvestLevel("chisel", 0);
|
||||
}
|
||||
|
||||
public BlockCarvable setStained(boolean a) {
|
||||
|
||||
@@ -28,7 +28,6 @@ public class BlockCarvableSand extends BlockSand implements ICarvable {
|
||||
super();
|
||||
carverHelper = new CarvableHelper();
|
||||
setCreativeTab(ModTabs.tabOtherChiselBlocks);
|
||||
setHarvestLevel("chisel", 0);
|
||||
}
|
||||
|
||||
public BlockCarvableSand setStained(boolean a) {
|
||||
|
||||
@@ -309,7 +309,6 @@ public class CarvableHelper
|
||||
if(block instanceof BlockMarbleSlab && ((BlockMarbleSlab) block).isBottom)
|
||||
{
|
||||
BlockMarbleSlab slab = (BlockMarbleSlab) block;
|
||||
slab.top.setHarvestLevel("chisel", 0, variation.metadata);
|
||||
|
||||
if(!forbidChiseling)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class Compatibility
|
||||
{
|
||||
|
||||
public static void init(FMLPostInitializationEvent event)
|
||||
{
|
||||
new MarbleCompatibility().postInit(event);
|
||||
@@ -31,7 +30,6 @@ public class Compatibility
|
||||
if(Loader.isModLoaded(modname) && GameRegistry.findBlock(modname, blockname) != null)
|
||||
{
|
||||
Carving.chisel.addVariation(name, GameRegistry.findBlock(modname, blockname), metadata, order);
|
||||
GameRegistry.findBlock(modname, blockname).setHarvestLevel("chisel", 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class ModItems {
|
||||
public static ItemUpgrade upgrade;
|
||||
|
||||
public static void load() {
|
||||
chisel = (ItemChisel) new ItemChisel().setTextureName("chisel:chisel").setCreativeTab(ModTabs.tabChisel);
|
||||
chisel = (ItemChisel) new ItemChisel().setCreativeTab(ModTabs.tabChisel);
|
||||
GameRegistry.registerItem(chisel, "chisel");
|
||||
|
||||
if (Configurations.featureEnabled("cloud")) {
|
||||
@@ -44,8 +44,9 @@ public class ModItems {
|
||||
GameRegistry.registerItem(upgrade, upgrade.getUnlocalizedName());
|
||||
}
|
||||
|
||||
// TODO deprecated
|
||||
if(Configurations.featureEnabled("diamondChisel")){
|
||||
diamondChisel = (ItemDiamondChisel) new ItemDiamondChisel().setTextureName(Chisel.MOD_ID + ":diamondChisel").setCreativeTab(ModTabs.tabChisel);
|
||||
diamondChisel = (ItemDiamondChisel) new ItemDiamondChisel().setTextureName(Chisel.MOD_ID + ":diamondChisel");
|
||||
GameRegistry.registerItem(diamondChisel, diamondChisel.getUnlocalizedName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,209 @@
|
||||
package com.cricketcraft.chisel.item;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.PacketHandler;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.client.GeneralChiselClient;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemChisel extends Item implements IChiselMode {
|
||||
public static Carving carving = Carving.chisel;
|
||||
|
||||
public ItemChisel() {
|
||||
super();
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName("chisel");
|
||||
}
|
||||
public static Carving carving = Carving.chisel;
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon ironIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon diamondIcon;
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
public ItemChisel() {
|
||||
super();
|
||||
setMaxStackSize(1);
|
||||
setHasSubtypes(true);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChiselMode getChiselMode(ItemStack itemStack) {
|
||||
return ChiselMode.SINGLE;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister register) {
|
||||
ironIcon = register.registerIcon(Chisel.MOD_ID + ":chisel");
|
||||
diamondIcon = register.registerIcon(Chisel.MOD_ID + ":diamondChisel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4){
|
||||
StatCollector.translateToLocal("item.chisel.desc");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(ItemStack stack, int pass) {
|
||||
return getIconFromDamage(stack.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamage(int damage) {
|
||||
return damage == 0 ? ironIcon : diamondIcon;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
||||
list.add(new ItemStack(item, 1, 0));
|
||||
list.add(new ItemStack(item, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
String name = stack.getItemDamage() == 0 ? "chisel" : "diamondChisel";
|
||||
return "item." + name;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean held) {
|
||||
list.add(StatCollector.translateToLocal(getUnlocalizedName(stack) + ".desc"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull3D() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLeftClickBlock(PlayerInteractEvent event) {
|
||||
ItemStack held = event.entityPlayer.getCurrentEquippedItem();
|
||||
int slot = event.entityPlayer.inventory.currentItem;
|
||||
// TODO config for diamond only
|
||||
if (event.action == Action.LEFT_CLICK_BLOCK && held != null && held.getItem() == this) {
|
||||
int x = event.x, y = event.y, z = event.z;
|
||||
Block block = event.world.getBlock(x, y, z);
|
||||
int metadata = event.world.getBlockMetadata(x, y, z);
|
||||
CarvingVariation[] variations = carving.getVariations(block, metadata);
|
||||
|
||||
if (variations != null) {
|
||||
ItemStack target = getTarget(held);
|
||||
|
||||
if (target != null) {
|
||||
for (CarvingVariation v : variations) {
|
||||
if (v.block == Block.getBlockFromItem(target.getItem()) && v.meta == target.getItemDamage()) {
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < variations.length; i++) {
|
||||
CarvingVariation v = variations[i];
|
||||
if (v.block == block && v.meta == metadata) {
|
||||
variations = ArrayUtils.remove(variations, i--);
|
||||
}
|
||||
}
|
||||
|
||||
int index = event.world.rand.nextInt(variations.length);
|
||||
CarvingVariation newVar = variations[index];
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, newVar);
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes that the player is holding a chisel
|
||||
*/
|
||||
private void setVariation(EntityPlayer player, World world, int x, int y, int z, CarvingVariation v) {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketPlaySound(x, y, z, v), (EntityPlayerMP) player);
|
||||
world.setBlock(x, y, z, v.block);
|
||||
world.setBlockMetadataWithNotify(x, y, z, v.meta, 3);
|
||||
player.getCurrentEquippedItem().damageItem(1, player);
|
||||
if (player.getCurrentEquippedItem().stackSize <= 0) {
|
||||
player.destroyCurrentEquippedItem();
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getTarget(ItemStack chisel) {
|
||||
return chisel.hasTagCompound() ? ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget")) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChiselMode getChiselMode(ItemStack itemStack) {
|
||||
// TODO
|
||||
return ChiselMode.SINGLE;
|
||||
}
|
||||
|
||||
public static class PacketPlaySound implements IMessage {
|
||||
|
||||
public PacketPlaySound() {
|
||||
}
|
||||
|
||||
private int x, y, z;
|
||||
private int block;
|
||||
private byte meta;
|
||||
|
||||
public PacketPlaySound(int x, int y, int z, CarvingVariation v) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.block = Block.getIdFromBlock(v.block);
|
||||
this.meta = (byte) v.meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(block);
|
||||
buf.writeByte(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
block = buf.readInt();
|
||||
meta = (byte) buf.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlaySoundHandler implements IMessageHandler<PacketPlaySound, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketPlaySound message, MessageContext ctx) {
|
||||
String sound = ItemChisel.carving.getVariationSound(Block.getBlockById(message.block), message.meta);
|
||||
GeneralChiselClient.spawnChiselEffect(message.x, message.y, message.z, sound);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,22 @@
|
||||
package com.cricketcraft.chisel.item;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
|
||||
public class ItemDiamondChisel extends Item implements IChiselMode{
|
||||
public static Carving carving = Carving.chisel;
|
||||
private static final HashSet<String> toolSet = new HashSet<String>();
|
||||
|
||||
public ItemDiamondChisel() {
|
||||
super();
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName("diamondChisel");
|
||||
toolSet.add("chisel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
if(!entityplayer.isSneaking())
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,8 +24,9 @@ public class ItemDiamondChisel extends Item implements IChiselMode{
|
||||
return ChiselMode.SINGLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4){
|
||||
StatCollector.translateToLocal("item.diamondChisel.desc");
|
||||
list.add("Deprecated. Craft to get new version.");
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public class ClientProxy extends CommonProxy
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntitySmashingRock.class, new RenderSnowball(ModItems.smashingRock));
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(ModItems.chisel, renderer);
|
||||
// TODO deprecated
|
||||
MinecraftForgeClient.registerItemRenderer(ModItems.diamondChisel, renderer);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user