Chisel item refactor.

Add chisel slot to autochisel. 
Refactor slot tooltip and valid items.
This commit is contained in:
tterrag1098 committed 2015-01-09 01:50:32 -05:00
1 parent 9202778b4d
commit 71e839831f
21 files changed
+288 -318

No files matched your search

@@ -1,5 +1,6 @@
package com.cricketcraft.chisel;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.block.BlockCarvable;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityPresent;
@@ -17,9 +18,11 @@ import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerChisel;
import com.cricketcraft.chisel.inventory.ContainerPresent;
import com.cricketcraft.chisel.inventory.InventoryChiselSelection;
import com.cricketcraft.chisel.item.chisel.ChiselController;
import com.cricketcraft.chisel.proxy.CommonProxy;
import com.cricketcraft.chisel.utils.General;
import com.cricketcraft.chisel.world.GeneratorChisel;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
@@ -136,6 +139,7 @@ public class Chisel {
ChiselTabs.preInit();
Features.preInit();
PacketHandler.init();
ChiselController.INSTANCE.preInit();
proxy.preInit();
}
@@ -1,6 +1,6 @@
package com.cricketcraft.chisel;
import com.cricketcraft.chisel.item.ItemChisel;
import com.cricketcraft.chisel.item.chisel.ChiselController;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
@@ -10,6 +10,6 @@ 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);
INSTANCE.registerMessage(ChiselController.PlaySoundHandler.class, ChiselController.PacketPlaySound.class, 0, Side.CLIENT);
}
}
@@ -14,6 +14,7 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.init.ChiselItems;
@@ -28,18 +29,19 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
public String getUnlocalizedName() {
return ChiselItems.upgrade.getUnlocalizedName() + "_" + this.name().toLowerCase();
}
public String getLocalizedName() {
return StatCollector.translateToLocal(getUnlocalizedName() + ".name");
}
}
private final int BASE = 0, TARGET = 1, OUTPUT = 2, MIN_UPGRADE = 3;
public static final int BASE = 0, TARGET = 1, OUTPUT = 2, CHISEL = 3, MIN_UPGRADE = 4;
private static EntityItem ghostItem;
boolean equal = false;
private ItemStack[] inventory = new ItemStack[6];
private ItemStack[] inventory = new ItemStack[7];
private String name = "autoChisel";
public float xRot, yRot, zRot; // used for floating target client only
@Override
@@ -92,7 +94,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
ItemStack base = inventory[BASE], target = inventory[TARGET], output = inventory[OUTPUT];
if (!worldObj.isRemote && worldObj.getWorldTime() % checkPeriod == 0) {
if (!worldObj.isRemote && worldObj.getWorldTime() % checkPeriod == 0 && hasChisel()) {
if (base != null && target != null) {
if (canBeMadeFrom(base, target)) {
// the max possible for this craft
@@ -130,6 +132,9 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
if (base.stackSize <= 0) {
inventory[BASE] = null; // clear out 0 size itemstacks
}
((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], inventory[TARGET]);
// we changed something, so we need to tell the chunk to save
markDirty();
}
@@ -163,6 +168,10 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
return false;
}
private boolean hasChisel() {
return inventory[CHISEL] != null && inventory[CHISEL].getItem() == ChiselItems.chisel && inventory[CHISEL].stackSize >= 1;
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
@@ -241,7 +250,21 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
return true;
if (itemStack == null) {
return false;
}
switch(slot) {
case BASE:
case TARGET:
return !Carving.chisel.getItems(itemStack).isEmpty();
case OUTPUT:
return false;
case CHISEL:
return itemStack.getItem() instanceof IChiselItem;
default:
return itemStack.getItem() == ChiselItems.upgrade && Upgrade.values()[slot - MIN_UPGRADE].ordinal() == itemStack.getItemDamage();
}
}
@Override
@@ -308,4 +331,19 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
}
return false;
}
public String getSlotTooltipUnloc(int slotNumber) {
String base = "autochisel.slot.%s.tooltip";
String name = null;
if (slotNumber < MIN_UPGRADE) {
if (slotNumber == TARGET) {
name = "target";
} else if (slotNumber == CHISEL) {
name = "chisel";
}
return name == null ? null : String.format(base, name);
} else {
return Upgrade.values()[slotNumber - MIN_UPGRADE].getUnlocalizedName() + ".name";
}
}
}
@@ -13,15 +13,19 @@ import org.lwjgl.opengl.GL11;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel.SlotUpgrade;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel.SlotAutoChisel;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
public class GuiAutoChisel extends GuiContainer {
private static final ResourceLocation gui = new ResourceLocation("chisel:textures/autochisel-gui.png");
private TileEntityAutoChisel autochisel;
public GuiAutoChisel(InventoryPlayer inventoryPlayer, TileEntityAutoChisel tileEntityAutoChisel) {
super(new ContainerAutoChisel(inventoryPlayer, tileEntityAutoChisel));
autochisel = tileEntityAutoChisel;
}
@SuppressWarnings("unchecked")
@@ -34,16 +38,17 @@ public class GuiAutoChisel extends GuiContainer {
for (Slot slot : (List<Slot>) inventorySlots.inventorySlots) {
if (mouseInside(slot, mouseX - x, mouseY - y)) {
if (slot instanceof SlotUpgrade) {
this.func_146283_a(Lists.newArrayList(((SlotUpgrade) slot).upgradeType.getLocalizedName()), mouseX - x, mouseY - y);
} else if (slot.slotNumber == 1) {
this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal("autochisel.slot.target.tooltip")), mouseX - x, mouseY - y);
if (slot instanceof SlotAutoChisel) {
String tt = autochisel.getSlotTooltipUnloc(slot.slotNumber);
if (!Strings.isNullOrEmpty(tt)) {
this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal(tt)), mouseX - x, mouseY - y);
}
}
}
}
RenderHelper.enableGUIStandardItemLighting();
}
private boolean mouseInside(Slot slot, int x, int y) {
return x >= slot.xDisplayPosition && x <= slot.xDisplayPosition + 16 && y >= slot.yDisplayPosition && y <= slot.yDisplayPosition + 16;
}
@@ -116,29 +116,19 @@ public class RenderAutoChisel extends TileEntitySpecialRenderer implements ISimp
private static EntityItem ghostItem;
private final RenderItem renderTargetAndChisel, renderBase;
private final RenderItem renderItem;
public RenderAutoChisel() {
Chisel.renderAutoChiselId = RenderingRegistry.getNextAvailableRenderId();
renderTargetAndChisel = new RenderItem() {
renderItem = new RenderItem() {
@Override
public boolean shouldBob() {
return false;
}
};
renderTargetAndChisel.setRenderManager(RenderManager.instance);
renderBase = new RenderItem() {
@Override
public boolean shouldBob() {
return true;
}
};
renderBase.setRenderManager(RenderManager.instance);
renderItem.setRenderManager(RenderManager.instance);
}
private static final Random rand = new Random();
@@ -148,7 +138,7 @@ public class RenderAutoChisel extends TileEntitySpecialRenderer implements ISimp
// Render Blocks
TileEntityAutoChisel autoChisel = (TileEntityAutoChisel) tile;
EntityItem item = autoChisel.getItemForRendering(1);
EntityItem item = autoChisel.getItemForRendering(TileEntityAutoChisel.TARGET);
rand.setSeed(tile.xCoord + tile.yCoord + tile.zCoord);
rand.nextBoolean();
@@ -170,17 +160,26 @@ public class RenderAutoChisel extends TileEntitySpecialRenderer implements ISimp
GL11.glRotatef(autoChisel.zRot, 0, 0, 1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_CONSTANT_ALPHA);
renderTargetAndChisel.doRender(item, 0, 0, 0, 0, 0);
renderItem.doRender(item, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
GL11.glPopAttrib();
}
EntityItem item2 = autoChisel.getItemForRendering(0);
if (item2 != null) {
item = autoChisel.getItemForRendering(TileEntityAutoChisel.BASE);
if (item != null) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.4, y + 0.83, z + 0.5);
renderBase.doRender(item2, 0, 0, 0, 0, 0);
GL11.glTranslated(x + 0.35, y + 0.934, z + 0.5);
renderItem.doRender(item, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
}
item = autoChisel.getItemForRendering(TileEntityAutoChisel.CHISEL);
if (item != null) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.7, y + 1, z + 0.5);
GL11.glTranslated(-0.12, 0, 0);
GL11.glScalef(0.9f, 0.9f, 0.9f);
renderItem.doRender(item, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
}
}
@@ -13,48 +13,69 @@ public class Configurations {
public static Configuration config;
public static boolean configExists;
public static boolean oldPillars;
public static boolean disableCTM;
public static boolean blockDescriptions;
public static double concreteVelocity;
public static boolean ghostCloud;
public static boolean chiselStoneToCobbleBricks;
public static int factoryBlockAmount;
public static boolean allowMossy;
public static boolean chiselRecipe;
public static boolean autoChisel;
public static boolean fancy;
public static boolean enableFMP;
public static boolean chiselStoneToCobbleBricks;
public static int factoryBlockAmount;
public static int particlesTickrate;
public static int marbleAmount;
public static int limestoneAmount;
public static int graniteAmount;
public static int dioriteAmount;
public static int andesiteAmount;
public static double concreteVelocity;
public static int particlesTickrate;
public static boolean oldPillars;
public static boolean disableCTM;
public static boolean fancy;
public static boolean blockDescriptions;
public static boolean allowChiselDamage;
public static int ironChiselMaxDamage;
public static int diamondChiselMaxDamage;
public static boolean refreshConfig() {
concreteVelocity = config.get("general", "concreteVelocity", 0.45,
String category;
/* general */
category = "general";
concreteVelocity = config.get(category, "concreteVelocity", 0.45,
"Traversing concrete roads, players will acceleration to this velocity. For reference, normal running speed is about 0.28. Set to 0 to disable acceleration.").getDouble(0.45);
particlesTickrate = config.get("client", "particleTickrate", 1, "Particle tick rate. Greater value = less particles.").getInt(1);
oldPillars = config.get("client", "pillarOldGraphics", false, "Use old pillar textures").getBoolean(false);
disableCTM = !config.get("client", "connectedTextures", true, "Enable connected textures").getBoolean(true);
fancy = config.get("client", "fancyLeaves", true, "Enable fancy textures").getBoolean(true);
blockDescriptions = config.get("client", "tooltipsUseBlockDescriptions", true, "Make variations of blocks have the same name, and use the description in tooltip to distinguish them.")
ghostCloud = config.get(category, "doesCloudRenderLikeGhost", true).getBoolean(true);
factoryBlockAmount = config.get(category, "amountYouGetFromFactoryBlockCrafting", 32).getInt(32);
allowMossy = config.get(category, "allowCobbleToMossyInChisel", true).getBoolean(true);
chiselRecipe = config.get(category, "chiselAlternateRecipe", false, "Use alternative crafting recipe for the chisel").getBoolean(false);
enableFMP = config.get(category, "enableFMP", true, "Do you want to enable FMP").getBoolean(true);
chiselStoneToCobbleBricks = config.get(category, "chiselStoneToCobbleBricks", true, "Chisel stone to cobblestone and bricks by left clicking.").getBoolean(false);
/* worldgen */
category = "worldgen";
marbleAmount = config.get(category, "marbleAmount", 7, "Amount of marble to generate in the world; use 0 for none").getInt(7);
limestoneAmount = config.get(category, "limestoneAmount", 8, "Amount of limestone to generate in the world; use 0 for none").getInt(8);
graniteAmount = config.get(category, "graniteAmount", 8, "Amount of granite to generate in the world; use 0 for none.").getInt(8);
dioriteAmount = config.get(category, "dioriteAmount", 8, "Amount of diorite to generate in the world; use 0 for none.").getInt(8);
andesiteAmount = config.get(category, "andesiteAmount", 8, "Amount of andesite to generate in the world; use 0 for none.").getInt(8);
/* client */
category = "client";
particlesTickrate = config.get(category, "particleTickrate", 1, "Particle tick rate. Greater value = less particles.").getInt(1);
oldPillars = config.get(category, "pillarOldGraphics", false, "Use old pillar textures").getBoolean(false);
disableCTM = !config.get(category, "connectedTextures", true, "Enable connected textures").getBoolean(true);
fancy = config.get(category, "fancyLeaves", true, "Enable fancy textures").getBoolean(true);
blockDescriptions = config.get(category, "tooltipsUseBlockDescriptions", true, "Make variations of blocks have the same name, and use the description in tooltip to distinguish them.")
.getBoolean(true);
ghostCloud = config.get("general", "doesCloudRenderLikeGhost", true).getBoolean(true);
factoryBlockAmount = config.get("general", "amountYouGetFromFactoryBlockCrafting", 32).getInt(32);
allowMossy = config.get("general", "allowCobbleToMossyInChisel", true).getBoolean(true);
marbleAmount = config.get("worldgen", "marbleAmount", 7, "Amount of marble to generate in the world; use 0 for none").getInt(7);
limestoneAmount = config.get("worldgen", "limestoneAmount", 8, "Amount of limestone to generate in the world; use 0 for none").getInt(8);
graniteAmount = config.get("worldgen", "graniteAmount", 8, "Amount of granite to generate in the world; use 0 for none.").getInt(8);
dioriteAmount = config.get("worldgen", "dioriteAmount", 8, "Amount of diorite to generate in the world; use 0 for none.").getInt(8);
andesiteAmount = config.get("worldgen", "andesiteAmount", 8, "Amount of andesite to generate in the world; use 0 for none.").getInt(8);
chiselRecipe = config.get("general", "chiselAlternateRecipe", false, "Use alternative crafting recipe for the chisel").getBoolean(false);
autoChisel = config.get("general", "autoChisel", true, "Should people be allowed to use the auto chisel").getBoolean(true);
enableFMP = config.get("general", "enableFMP", true, "Do you want to enable FMP").getBoolean(true);
chiselStoneToCobbleBricks = config.get("general", "chiselStoneToCobbleBricks", true, "Chisel stone to cobblestone and bricks by left clicking.").getBoolean(false);
/* chisel */
category = "chisel";
allowChiselDamage = config.get(category, "allowChiselDamage", true, "Should the chisel be damageable and take damage when it chisels something.").getBoolean();
ironChiselMaxDamage = config.get(category, "ironChiselMaxDamage", 500, "The max damage of the standard iron chisel. Default: 500.").getInt();
diamondChiselMaxDamage = config.get(category, "diamondChiselMaxDamage", 5000, "The max damage of the diamond chisel. Default: 5000").getInt();
if (config.hasChanged()) {
config.save();
@@ -65,21 +86,23 @@ public class Configurations {
public static boolean featureEnabled(Features feature) {
return config.get("features", featureName(feature), true).getBoolean(true) && refreshConfig();
}
// this makes the old camelCase names from the new CONSTANT_CASE names
private static String featureName (Features feature) {
private static String featureName(Features feature) {
String[] words = feature.name().toLowerCase(Locale.ENGLISH).split("_");
if (words.length == 1) {
return words[0];
}
String ret = words[0];
for (int i = 1; i < words.length; i++) {
ret += StringUtils.capitalize(words[i]);
}
return ret;
}
@Deprecated
public static boolean featureEnabled(String feature) {return false;}
public static boolean featureEnabled(String feature) {
return false;
}
}
@@ -2,10 +2,10 @@ package com.cricketcraft.chisel.init;
import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.item.ItemBallOMoss;
import com.cricketcraft.chisel.item.ItemChisel;
import com.cricketcraft.chisel.item.ItemCloudInABottle;
import com.cricketcraft.chisel.item.ItemSmashingRock;
import com.cricketcraft.chisel.item.ItemUpgrade;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
@@ -13,6 +13,7 @@ import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
public final class ChiselItems {
public static final ItemChisel chisel = null;
public static final ItemChisel diamondChisel = null;
public static final ItemCloudInABottle cloudinabottle = null;
public static final ItemBallOMoss ballomoss = null;
public static final ItemSmashingRock smashingrock = null;
@@ -59,11 +59,12 @@ import com.cricketcraft.chisel.entity.EntityCloudInABottle;
import com.cricketcraft.chisel.entity.EntitySmashingRock;
import com.cricketcraft.chisel.item.ItemBallOMoss;
import com.cricketcraft.chisel.item.ItemCarvable;
import com.cricketcraft.chisel.item.ItemChisel;
import com.cricketcraft.chisel.item.ItemCloudInABottle;
import com.cricketcraft.chisel.item.ItemMarbleSlab;
import com.cricketcraft.chisel.item.ItemSmashingRock;
import com.cricketcraft.chisel.item.ItemUpgrade;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
import com.cricketcraft.chisel.item.chisel.ItemChisel.ChiselType;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.EntityRegistry;
@@ -314,8 +315,10 @@ public enum Features {
@Override
void addItems() {
ItemChisel chisel = (ItemChisel) new ItemChisel().setCreativeTab(ChiselTabs.tabChisel);
ItemChisel chisel = (ItemChisel) new ItemChisel(ChiselType.IRON).setCreativeTab(ChiselTabs.tabChisel);
ItemChisel diamondChisel = (ItemChisel) new ItemChisel(ChiselType.DIAMOND).setCreativeTab(ChiselTabs.tabChisel);
GameRegistry.registerItem(chisel, "chisel");
GameRegistry.registerItem(diamondChisel, "diamondChisel");
}
@Override
@@ -7,23 +7,18 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel.Upgrade;
import com.cricketcraft.chisel.init.ChiselItems;
public class ContainerAutoChisel extends Container {
public static class SlotUpgrade extends Slot {
public static class SlotAutoChisel extends Slot {
public Upgrade upgradeType;
public SlotUpgrade(TileEntityAutoChisel inv, int id, int x, int y, Upgrade upgrade) {
public SlotAutoChisel(TileEntityAutoChisel inv, int id, int x, int y) {
super(inv, id, x, y);
this.upgradeType = upgrade;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() == ChiselItems.upgrade && stack.getItemDamage() == upgradeType.ordinal();
return inventory.isItemValidForSlot(slotNumber, stack);
}
}
@@ -35,12 +30,13 @@ public class ContainerAutoChisel extends Container {
ContainerAutoChisel.player = player.player;
autoChisel = tileEntityAutoChisel;
addSlotToContainer(new Slot(tileEntityAutoChisel, 0, 53, 15));
addSlotToContainer(new Slot(tileEntityAutoChisel, 1, 78, 51));
addSlotToContainer(new Slot(tileEntityAutoChisel, 2, 103, 15));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 3, 151, 11, Upgrade.SPEED));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 4, 151, 31, Upgrade.AUTOMATION));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 5, 151, 51, Upgrade.STACK));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 0, 53, 15));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 1, 78, 51));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 2, 103, 15));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 3, 8, 62));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 4, 151, 11));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 5, 151, 31));
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 6, 151, 51));
bindPlayerInventory(player);
}
@@ -73,22 +69,13 @@ public class ContainerAutoChisel extends Container {
itemStack = itemStack1.copy();
// if we are in the auto chisel
if (slotNumber <= 5) {
if (slotNumber <= 6) {
if (!this.mergeItemStack(itemStack1, 33, 42, false)) {
return null;
}
} else {
// if this is an upgrade, check the upgrade slots
if (itemStack1.getItem() == ChiselItems.upgrade) {
if (!this.mergeItemStack(itemStack1, 3, 6, false)) {
return null;
}
} else {
// otherwise just put it in one of the 3 other slots
if (!this.mergeItemStack(itemStack1, 0, 3, false)) {
return null;
}
}
// otherwise just put it in one of the machine slots
} else if (!this.mergeItemStack(itemStack1, 0, 7, false)) {
return null;
}
if (itemStack1.stackSize == 0) {
@@ -9,7 +9,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.item.ItemChisel;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
import com.cricketcraft.chisel.utils.General;
public class ContainerChisel extends Container {
@@ -8,7 +8,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.item.ItemChisel;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
public class InventoryChiselSelection implements IInventory {
@@ -5,7 +5,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.utils.General;
import com.cricketcraft.chisel.api.IChiselItem;
public class SlotChiselSelection extends Slot {
@@ -54,9 +54,8 @@ public class SlotChiselSelection extends Slot {
}
selInventory.updateItems();
String sound = container.carving.getVariationSound(itemstack.getItem(), itemstack.getItemDamage());
player.worldObj.playSoundAtEntity(player, sound, 0.3f + 0.7f * General.rand.nextFloat(), 0.6f + 0.4f * General.rand.nextFloat());
((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj, player.inventory, player.inventory.currentItem, container.chisel, crafted);
/*
* ItemStack stack=player.inventory.getItemStack();
@@ -1,209 +0,0 @@
package com.cricketcraft.chisel.item;
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;
@SideOnly(Side.CLIENT)
private IIcon ironIcon;
@SideOnly(Side.CLIENT)
private IIcon diamondIcon;
public ItemChisel() {
super();
setMaxStackSize(1);
setHasSubtypes(true);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister register) {
ironIcon = register.registerIcon(Chisel.MOD_ID + ":chisel");
diamondIcon = register.registerIcon(Chisel.MOD_ID + ":diamondChisel");
}
@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 = 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;
}
}
}
@@ -0,0 +1,97 @@
package com.cricketcraft.chisel.item.chisel;
import java.util.List;
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;
import com.cricketcraft.chisel.Chisel;
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.utils.GeneralClient;
public class ItemChisel extends Item implements IChiselItem {
public enum ChiselType {
IRON(Configurations.ironChiselMaxDamage), DIAMOND(Configurations.diamondChiselMaxDamage);
final int maxDamage;
ChiselType(int maxDamage) {
this.maxDamage = maxDamage;
}
}
public static Carving carving = Carving.chisel;
private ChiselType type;
public ItemChisel(ChiselType type) {
super();
this.type = type;
setMaxStackSize(1);
setHasSubtypes(true);
setTextureName(Chisel.MOD_ID + ":chisel_" + type.name().toLowerCase());
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public int getMaxDamage(ItemStack stack) {
if (Configurations.allowChiselDamage) {
return type.maxDamage;
}
return 0;
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return "item." + Chisel.MOD_ID + ".chisel_" + type.name().toLowerCase();
}
@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 ChiselMode getChiselMode(ItemStack itemStack) {
return ChiselMode.SINGLE;
}
@Override
public void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target) {
if (Configurations.allowChiselDamage) {
chisel.setItemDamage(chisel.getItemDamage() + 1);
}
if (world.isRemote) {
String sound = carving.getVariationSound(target.getItem(), target.getItemDamage());
EntityPlayer player = Chisel.proxy.getClientPlayer();
GeneralClient.playChiselSound(world, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), sound);
} else {
if (chisel.getItemDamage() >= chisel.getMaxDamage()) {
inv.decrStackSize(slot, 1);
}
}
}
@Override
public ItemStack getTarget(ItemStack chisel) {
return chisel.hasTagCompound() ? ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget")) : null;
}
}
@@ -1,7 +1,10 @@
package com.cricketcraft.chisel.proxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import com.cricketcraft.chisel.Chisel;
@@ -58,7 +61,7 @@ public class ClientProxy extends CommonProxy {
RenderingRegistry.registerBlockHandler(rac);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ChiselBlocks.autoChisel), rac);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAutoChisel.class, rac);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPresent.class, new RenderPresent());
for (int x = 0; x < 16; x++) {
@@ -71,4 +74,14 @@ public class ClientProxy extends CommonProxy {
MinecraftForgeClient.registerItemRenderer(ChiselItems.chisel, renderer);
}
@Override
public EntityPlayer getClientPlayer() {
return Minecraft.getMinecraft().thePlayer;
}
@Override
public World getClientWorld() {
return Minecraft.getMinecraft().theWorld;
}
}
@@ -1,5 +1,8 @@
package com.cricketcraft.chisel.proxy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityPresent;
@@ -17,4 +20,12 @@ public class CommonProxy {
public void init() {
}
public EntityPlayer getClientPlayer() {
return null;
}
public World getClientWorld() {
return null;
}
}
@@ -89,6 +89,6 @@ public class General {
Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
return par1World.rayTraceBlocks(var13, var23, par3);
}
public static final String[] sGNames = new String[] { "White", "Orange", "Magenta", "Light Blue", "Yellow", "Lime", "Pink", "Gray", "Light Gray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black" };
}
@@ -1,8 +1,10 @@
# Key localizations
# Item localizations
item.chisel.name=Chisel
item.chisel.chisel_iron.name=Chisel
item.chisel.desc=Right-Click to open GUI
item.chisel.chisel_diamond.name=Diamond Chisel
item.chisel.chisel_diamond.desc=Left click and it changes blocks!
item.ballMoss.name=Ball O' Moss
item.ballMoss.desc=Right-Click to throw. This will turn Cobblestone to Moss Stone on impact.
item.cloudBottle.name=Cloud In A Bottle
@@ -37,12 +39,9 @@ tile.granite.name=Granite
tile.granite.0.desc=Generates in your world
tile.granite.1.desc=Polished Granite
#Diamond Chisel
item.diamondChisel.name=Diamond Chisel
item.diamondChisel.desc=Left click and it changes blocks!
#Auto Chisel
tile.autoChisel.name=Auto Chisel
autochisel.slot.chisel.tooltip=Chisel Slot
autochisel.slot.target.tooltip=Target Slot
#Leaves
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B