Work on getting the Minium Stone and Philosopher Stone to have a working portable crafting table, add in a PlayerDestroyItem event when the Minium Stone is used up in crafting

This commit is contained in:
pahimar 2012-09-09 00:21:44 -04:00
parent 2a23c104df
commit d2b2e6e061
7 changed files with 109 additions and 5 deletions

View file

@ -1,11 +1,18 @@
package ee3.client.core.handlers;
import java.util.EnumSet;
import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.KeyBinding;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.TickType;
import ee3.client.lib.KeyBindings;
import ee3.common.EquivalentExchange3;
import ee3.common.item.ModItems;
import ee3.common.lib.GuiIds;
import ee3.common.lib.Reference;
/**
@ -34,7 +41,17 @@ public class KeyBindingHandler extends KeyBindingRegistry.KeyHandler {
if (tickEnd) {
// If we are not in a GUI of any kind, continue execution
if (FMLClientHandler.instance().getClient().currentScreen == null) {
if (kb.keyDescription == Reference.KEYBINDING_EXTRA) {
ItemStack currentItem = FMLClientHandler.instance().getClient().thePlayer.getCurrentEquippedItem();
if (currentItem != null) {
// TODO Works sorta, fix this up proper
if ((currentItem.getItem().shiftedIndex == ModItems.miniumStone.shiftedIndex) || (currentItem.getItem().shiftedIndex == ModItems.philStone.shiftedIndex)) {
EntityClientPlayerMP thePlayer = FMLClientHandler.instance().getClient().thePlayer;
thePlayer.openGui(EquivalentExchange3.instance, GuiIds.PORTABLE_CRAFTING, thePlayer.worldObj, (int)thePlayer.posX, (int)thePlayer.posY, (int)thePlayer.posZ);
}
}
}
}
}

View file

@ -0,0 +1,41 @@
package ee3.client.gui;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import ee3.common.container.ContainerPortableCrafting;
import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiContainer;
import net.minecraft.src.StatCollector;
import net.minecraft.src.World;
@SideOnly(Side.CLIENT)
public class GuiPortableCrafting extends GuiContainer {
public GuiPortableCrafting(EntityPlayer player, World world, int x, int y, int z) {
super(new ContainerPortableCrafting(player.inventory, world, x, y, z));
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer() {
this.fontRenderer.drawString(StatCollector.translateToLocal("container.crafting"), 28, 6, 4210752);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
int var4 = this.mc.renderEngine.getTexture("/gui/crafting.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(var4);
int var5 = (this.width - this.xSize) / 2;
int var6 = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
}
}

View file

@ -0,0 +1,19 @@
package ee3.common.container;
import net.minecraft.src.ContainerWorkbench;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.World;
public class ContainerPortableCrafting extends ContainerWorkbench {
public ContainerPortableCrafting(InventoryPlayer inventoryPlayer, World world, int x, int y, int z) {
super(inventoryPlayer, world, x, y, z);
}
@Override
public boolean canInteractWith(EntityPlayer var1) {
return true;
}
}

View file

@ -5,6 +5,9 @@ import net.minecraft.src.EnumRarity;
import net.minecraft.src.World;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import ee3.client.gui.GuiPortableCrafting;
import ee3.common.container.ContainerPortableCrafting;
import ee3.common.lib.GuiIds;
import ee3.common.tile.TileCalcinator;
/**
@ -39,11 +42,19 @@ public class CommonProxy implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == GuiIds.PORTABLE_CRAFTING) {
return new ContainerPortableCrafting(player.inventory, world, x, y, z);
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == GuiIds.PORTABLE_CRAFTING) {
return new GuiPortableCrafting(player, world, x, y, z);
}
return null;
}

View file

@ -3,6 +3,8 @@ package ee3.common.core.handlers;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import cpw.mods.fml.common.ICraftingHandler;
import ee3.common.item.ModItems;
import ee3.common.lib.ConfigurationSettings;
@ -26,10 +28,16 @@ public class CraftingHandler implements ICraftingHandler {
currentItemStack = craftMatrix.getStackInSlot(i);
if (currentItemStack != null) {
if (currentItemStack.itemID == ModItems.miniumStone.shiftedIndex) {
// Capture the destruction of the Minium Stone when used the final time
currentItemStack.damageItem(ConfigurationSettings.MINIUM_STONE_TRANSMUTE_COST, player);
currentItemStack.stackSize++;
// If we still have enough durability to do the transmute, do it
if ((currentItemStack.getItemDamage() + ConfigurationSettings.MINIUM_STONE_TRANSMUTE_COST) <= currentItemStack.getMaxDamage()) {
currentItemStack.damageItem(ConfigurationSettings.MINIUM_STONE_TRANSMUTE_COST, player);
currentItemStack.stackSize++;
}
// Else capture the destruction of the item, and throw the event
else {
currentItemStack.damageItem(ConfigurationSettings.MINIUM_STONE_TRANSMUTE_COST, player);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, currentItemStack));
}
} else if (currentItemStack.itemID == ModItems.philStone.shiftedIndex) {
currentItemStack.stackSize++;

View file

@ -7,6 +7,7 @@ public class PlayerDestroyItemHandler {
@ForgeSubscribe
public void onPlayerDestroyItemEvent(PlayerDestroyItemEvent event) {
// TODO Come back and actually do what I want here
System.out.println(event.original.getItemNameandInformation());
}

View file

@ -0,0 +1,7 @@
package ee3.common.lib;
public class GuiIds {
public static final int PORTABLE_CRAFTING = 1;
}