Finish updating slot logic for Tool Stations, fix dupe bugs

This commit is contained in:
mDiyo committed 2014-07-05 21:08:58 -08:00
1 parent c16c376868
commit 2629e241cd
26 files changed
+202 -154

No files matched your search

@@ -16,14 +16,6 @@ import tconstruct.client.ToolCoreRenderer;
import tconstruct.client.entity.projectile.ArrowRenderCustom;
import tconstruct.client.entity.projectile.DaggerRenderCustom;
import tconstruct.client.entity.projectile.LaunchedItemRender;
import tconstruct.client.gui.CraftingStationGui;
import tconstruct.client.gui.FrypanGui;
import tconstruct.client.gui.FurnaceGui;
import tconstruct.client.gui.PartCrafterGui;
import tconstruct.client.gui.PatternChestGui;
import tconstruct.client.gui.StencilTableGui;
import tconstruct.client.gui.ToolForgeGui;
import tconstruct.client.gui.ToolStationGui;
import tconstruct.client.pages.MaterialPage;
import tconstruct.client.pages.ModifierPage;
import tconstruct.client.pages.ToolPage;
@@ -38,6 +30,14 @@ import tconstruct.tools.entity.ArrowEntity;
import tconstruct.tools.entity.DaggerEntity;
import tconstruct.tools.entity.FancyEntityItem;
import tconstruct.tools.entity.LaunchedPotion;
import tconstruct.tools.gui.CraftingStationGui;
import tconstruct.tools.gui.FrypanGui;
import tconstruct.tools.gui.FurnaceGui;
import tconstruct.tools.gui.PartCrafterGui;
import tconstruct.tools.gui.PatternChestGui;
import tconstruct.tools.gui.StencilTableGui;
import tconstruct.tools.gui.ToolForgeGui;
import tconstruct.tools.gui.ToolStationGui;
import tconstruct.tools.logic.CraftingStationLogic;
import tconstruct.tools.logic.FrypanLogic;
import tconstruct.tools.logic.FurnaceLogic;
@@ -0,0 +1,402 @@
package tconstruct.tools.gui;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.tools.ToolCore;
import tconstruct.tools.logic.CraftingStationLogic;
public class CraftingStationGui extends GuiContainer
{
public boolean active;
public String toolName;
public GuiTextField text;
public String title, body = "";
CraftingStationLogic logic;
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z)
{
super(logic.getGuiContainer(inventory, world, x, y, z));
this.logic = logic;
// text = new GuiTextField(this.fontRendererObj, this.xSize / 2 - 5, 8,
// 30, 12);
// this.text.setText("");
title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1");
body = StatCollector.translateToLocal("gui.toolforge2");
toolName = "";
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()), 8, 6, 0x202020);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 0x202020);
if (logic.chest != null)
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.chest.get().getInventoryName()), -108, this.ySize - 160, 0x202020);
// this.fontRendererObj.drawString(toolName + "_", this.xSize / 2 - 18,
// 8, 0xffffff);
if (logic.tinkerTable)
{
if (logic.isStackInSlot(0))
drawToolStats();
else
drawToolInformation();
}
}
void drawToolStats ()
{
ItemStack stack = logic.getStackInSlot(0);
if (stack.getItem() instanceof ToolCore)
{
ToolCore tool = (ToolCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
this.drawCenteredString(fontRendererObj, "\u00A7n" + tool.getToolName(), xSize + 63, 8, 0xffffff);
drawModularToolStats(stack, tool, tags);
}
else if (stack.getItem() instanceof ArmorCore)
{
ArmorCore armor = (ArmorCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("TinkerArmor");
this.drawCenteredString(fontRendererObj, "\u00A7n" + armor.getClass().getSimpleName(), xSize + 63, 8, 0xffffff);
drawModularArmorStats(stack, armor, tags);
}
}
void drawModularArmorStats (ItemStack stack, ArmorCore tool, NBTTagCompound tags)
{
int modifiers = tags.getInteger("Modifiers");
int base = 24;
int offset = 0;
if (modifiers > 0)
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
boolean displayToolTips = true;
int tipNum = 0;
while (displayToolTips)
{
tipNum++;
String tooltip = "ModifierTip" + tipNum;
if (tags.hasKey(tooltip))
{
String tipName = tags.getString(tooltip);
fontRendererObj.drawString("- " + tipName, xSize + 8, base + (offset + tipNum) * 10, 0xffffff);
}
else
displayToolTips = false;
}
}
void drawModularToolStats (ItemStack stack, ToolCore tool, NBTTagCompound tags)
{
List categories = Arrays.asList(tool.getTraits());
final int durability = tags.getInteger("Damage");
final int maxDur = tags.getInteger("TotalDurability");
int availableDurability = maxDur - durability;
// Durability
int base = 24;
int offset = 0;
if (maxDur > 0)
{
if (maxDur >= 10000)
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation1"), xSize + 8, base + offset * 11, 0xffffff);
offset++;
fontRendererObj.drawString("- " + availableDurability + "/" + maxDur, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
else
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation2") + availableDurability + "/" + maxDur, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
}
final float stonebound = tags.getFloat("Shoddy");
// Attack
if (categories.contains("weapon"))
{
int attack = (int) (tags.getInteger("Attack"));
float stoneboundDamage = (float) Math.log(durability / 72f + 1) * -2 * stonebound;
attack += stoneboundDamage;
attack *= tool.getDamageModifier();
if (attack < 1)
attack = 1;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2f + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundDamage != 0)
{
heart = stoneboundDamage == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
String bloss = stoneboundDamage > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
this.fontRendererObj.drawString(bloss + (int) stoneboundDamage / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
offset++;
}
if (categories.contains("bow"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int drawSpeed = tags.getInteger("DrawSpeed");
float flightSpeed = tags.getFloat("FlightSpeed");
float trueDraw = drawSpeed / 20f * flightSpeed;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation6") + df.format(trueDraw) + "s", xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation7") + df.format(flightSpeed) + "x", xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
if (categories.contains("ammo"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int attack = (int) (tags.getInteger("Attack"));
float mass = tags.getFloat("Mass");
float shatter = tags.getFloat("BreakChance");
float accuracy = tags.getFloat("Accuracy");
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation10"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString("- " + attack / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
else
this.fontRendererObj.drawString("- " + attack / 2f + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
int minAttack = attack;
int maxAttack = attack * 2;
heart = StatCollector.translateToLocal("gui.partcrafter9");
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation11"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(df.format(minAttack / 2f) + "-" + df.format(maxAttack / 2f) + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation8") + df.format(mass), xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation9") + df.format(accuracy - 4) + "%", xSize + 8, base + offset * 10, 0xffffff);
offset++;
/*
* this.fontRendererObj.drawString("Chance to break: " +
* df.format(shatter)+"%", xSize + 8, base + offset * 10, 0xffffff);
* offset++;
*/
offset++;
}
// Mining
if (categories.contains("dualharvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed") / 100f;
float mineSpeed2 = tags.getInteger("MiningSpeed2") / 100f;
float stoneboundSpeed = (float) Math.log(durability / 90f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
float trueSpeed = mineSpeed + stoneboundSpeed;
float trueSpeed2 = mineSpeed + stoneboundSpeed;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation12"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
fontRendererObj.drawString("- " + df.format(trueSpeed) + ", " + df.format(trueSpeed2), xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRendererObj.drawString(bloss + df.format(stoneboundSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
offset++;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation13"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
fontRendererObj.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", " + getHarvestLevelName(tags.getInteger("HarvestLevel2")), xSize + 8, base + offset * 10,
0xffffff);
offset++;
offset++;
}
else if (categories.contains("harvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
int heads = 1;
if (tags.hasKey("MiningSpeed2"))
{
mineSpeed += tags.getInteger("MiningSpeed2");
heads++;
}
if (tags.hasKey("MiningSpeedHandle"))
{
mineSpeed += tags.getInteger("MiningSpeedHandle");
heads++;
}
if (tags.hasKey("MiningSpeedExtra"))
{
mineSpeed += tags.getInteger("MiningSpeedExtra");
heads++;
}
float trueSpeed = mineSpeed / (heads * 100f);
float stoneboundSpeed = (float) Math.log(durability / 90f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
trueSpeed += stoneboundSpeed;
if (trueSpeed < 0)
trueSpeed = 0;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation14") + df.format(trueSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRendererObj.drawString(bloss + df.format(stoneboundSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation15") + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
else if (categories.contains("utility"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
float trueSpeed = mineSpeed / (100f);
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation16") + trueSpeed, xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
int modifiers = tags.getInteger("Modifiers");
if (modifiers > 0)
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
if (tags.hasKey("Tooltip1"))
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation17"), xSize + 8, base + offset * 10, 0xffffff);
}
boolean displayToolTips = true;
int tipNum = 0;
while (displayToolTips)
{
tipNum++;
String tooltip = "ModifierTip" + tipNum;
if (tags.hasKey(tooltip))
{
String tipName = tags.getString(tooltip);
fontRendererObj.drawString("- " + tipName, xSize + 8, base + (offset + tipNum) * 10, 0xffffff);
}
else
displayToolTips = false;
}
}
protected String getHarvestLevelName (int num)
{
switch (num)
{
case 0:
return StatCollector.translateToLocal("gui.partcrafter.mining1");
case 1:
return StatCollector.translateToLocal("gui.partcrafter.mining2");
case 2:
return StatCollector.translateToLocal("gui.partcrafter.mining3");
case 3:
return StatCollector.translateToLocal("gui.partcrafter.mining4");
case 4:
return StatCollector.translateToLocal("gui.partcrafter.mining5");
case 5:
return StatCollector.translateToLocal("gui.partcrafter.mining6");
default:
return String.valueOf(num);
}
}
void drawToolInformation ()
{
this.drawCenteredString(fontRendererObj, title, xSize + 63, 8, 0xffffff);
fontRendererObj.drawSplitString(body, xSize + 8, 24, 115, 0xffffff);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
private static final ResourceLocation chest = new ResourceLocation("tinker", "textures/gui/chestside.png");
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
if (active)
{
this.drawTexturedModalRect(cornerX + 62, cornerY, 0, this.ySize, 112, 22);
}
this.mc.getTextureManager().bindTexture(icons);
// Draw the slots
if (logic.tinkerTable && !logic.isStackInSlot(5))
this.drawTexturedModalRect(cornerX + 47, cornerY + 33, 0, 233, 18, 18);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(icons);
// Draw chest side
if (logic.chest != null)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(chest);
if (logic.doubleChest == null)
this.drawTexturedModalRect(cornerX - 116, cornerY, 0, 0, 121, this.ySize);
else
this.drawTexturedModalRect(cornerX - 116, cornerY, 125, 0, 122, this.ySize + 21);
}
// Draw description
if (logic.tinkerTable)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(description);
cornerX = (this.width + this.xSize) / 2;
cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, 126, this.ySize + 30);
}
}
}
@@ -0,0 +1,48 @@
package tconstruct.tools.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.tools.logic.FrypanLogic;
public class FrypanGui extends GuiContainer
{
public FrypanLogic logic;
public FrypanGui(InventoryPlayer inventoryplayer, FrypanLogic frypan, World world, int x, int y, int z)
{
super(frypan.getGuiContainer(inventoryplayer, world, x, y, z));
logic = frypan;
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
fontRendererObj.drawString(StatCollector.translateToLocal("crafters.Frypan"), 60, 6, 0x404040);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/frypan.png");
@Override
protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
if (logic.fuel > 0)
{
int fuel = logic.gaugeFuelScaled(12);
drawTexturedModalRect(cornerX + 27, (cornerY + 40) - fuel, 176, 12 - fuel, 14, fuel + 2);
}
int fuelgague = logic.gaugeProgressScaled(24);
drawTexturedModalRect(cornerX + 140, cornerY + 8, 176, 14, fuelgague, 16);
}
}
@@ -0,0 +1,62 @@
package tconstruct.tools.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import tconstruct.tools.inventory.FurnaceContainer;
import tconstruct.tools.logic.FurnaceLogic;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class FurnaceGui extends GuiContainer
{
private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("textures/gui/container/furnace.png");
private FurnaceLogic logic;
public FurnaceGui(InventoryPlayer inventory, FurnaceLogic furnace)
{
super(new FurnaceContainer(inventory, furnace));
this.logic = furnace;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of
* the items)
*/
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
String s = this.logic.isInvNameLocalized() ? this.logic.getInvName() : I18n.format(this.logic.getInvName());
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the
* items)
*/
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;
if (this.logic.isBurning())
{
i1 = this.logic.gaugeFuelScaled(12);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
}
i1 = this.logic.gaugeProgressScaled(24);
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}
@@ -0,0 +1,57 @@
package tconstruct.tools.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import tconstruct.library.client.ToolGuiElement;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButtonTool extends GuiButton
{
/**
* True for pointing right (next page), false for pointing left (previous
* page).
*/
int textureX;
int textureY;
public String texture;
public ToolGuiElement element;
private static ResourceLocation background;// = new
// ResourceLocation("tinker",
// "textures/gui/armorextended.png");
public GuiButtonTool(int id, int posX, int posY, int texX, int texY, String domain, String tex, ToolGuiElement e)
{
super(id, posX, posY, 18, 18, "");
textureX = texX;
textureY = texY;
texture = tex;
element = e;
background = new ResourceLocation(domain, tex);
}
/**
* Draws this button to the screen.
*/
@Override
public void drawButton (Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
boolean var4 = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(background);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int var5 = this.getHoverState(this.field_146123_n);
int index = 18 * getHoverState(field_146123_n);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 144 + index * 2, 216, 18, 18);
this.drawTexturedModalRect(this.xPosition, this.yPosition, textureX * 18, textureY * 18, 18, 18);
}
}
}
@@ -0,0 +1,302 @@
package tconstruct.tools.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import tconstruct.client.gui.NewContainerGui;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.tools.ToolMaterial;
import tconstruct.smeltery.inventory.ActiveContainer;
import tconstruct.tools.inventory.PartCrafterChestContainer;
import tconstruct.tools.logic.PartBuilderLogic;
public class PartCrafterGui extends NewContainerGui
{
PartBuilderLogic logic;
String title, otherTitle = "";
boolean drawChestPart;
boolean hasTop, hasBottom;
ItemStack topMaterial, bottomMaterial;
ToolMaterial topEnum, bottomEnum;
public PartCrafterGui(InventoryPlayer inventoryplayer, PartBuilderLogic partlogic, World world, int x, int y, int z)
{
super((ActiveContainer) partlogic.getGuiContainer(inventoryplayer, world, x, y, z));
logic = partlogic;
drawChestPart = container instanceof PartCrafterChestContainer;
title = "\u00A7n" + (StatCollector.translateToLocal("gui.partcrafter1"));
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
this.fontRendererObj.drawString(StatCollector.translateToLocal("crafters.PartBuilder"), 6, 6, 4210752);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
if (drawChestPart)
this.fontRendererObj.drawString(StatCollector.translateToLocal("inventory.PatternChest"), -108, this.ySize - 148, 4210752);
drawMaterialInformation();
}
void drawDefaultInformation ()
{
title = "\u00A7n" + StatCollector.translateToLocal("gui.partcrafter2");
this.drawCenteredString(fontRendererObj, title, xSize + 63, 8, 16777215);
fontRendererObj.drawSplitString(StatCollector.translateToLocal("gui.partcrafter3"), xSize + 8, 24, 115, 16777215);
}
void drawMaterialInformation ()
{
ItemStack top = logic.getStackInSlot(2);
//ItemStack topResult = logic.getStackInSlot(4);
ItemStack bottom = logic.getStackInSlot(3);
//ItemStack bottomResult = logic.getStackInSlot(6);
if (topMaterial != top)
{
topMaterial = top;
int topID = PatternBuilder.instance.getPartID(top);
if (topID != Short.MAX_VALUE)// && topResult != null)
{
topEnum = TConstructRegistry.getMaterial(topID);
hasTop = true;
title = "\u00A7n" + topEnum.name();
}
else
hasTop = false;
}
if (bottomMaterial != bottom)
{
bottomMaterial = bottom;
int bottomID = PatternBuilder.instance.getPartID(bottom);
if (bottomID != Short.MAX_VALUE)// && bottomResult != null)
{
bottomEnum = TConstructRegistry.getMaterial(bottomID);
hasBottom = true;
otherTitle = "\u00A7n" + bottomEnum.name();
}
else
hasBottom = false;
}
int offset = 8;
if (hasTop)
{
this.drawCenteredString(fontRendererObj, title, xSize + 63, offset, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + topEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + topEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + topEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + getHarvestLevelName(topEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = topEnum.attack();
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
offset = 90;
if (hasBottom)
{
this.drawCenteredString(fontRendererObj, otherTitle, xSize + 63, offset, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + bottomEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + bottomEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + bottomEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + getHarvestLevelName(bottomEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = bottomEnum.attack();
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
if (!hasTop && !hasBottom)
drawDefaultInformation();
}
public static String getHarvestLevelName (int num)
{
switch (num)
{
case 0:
return (StatCollector.translateToLocal("gui.partcrafter.mining1"));
case 1:
return (StatCollector.translateToLocal("gui.partcrafter.mining2"));
case 2:
return (StatCollector.translateToLocal("gui.partcrafter.mining3"));
case 3:
return (StatCollector.translateToLocal("gui.partcrafter.mining4"));
case 4:
return (StatCollector.translateToLocal("gui.partcrafter.mining5"));
case 5:
return (StatCollector.translateToLocal("gui.partcrafter.mining6"));
default:
return String.valueOf(num);
}
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/toolparts.png");
private static final ResourceLocation minichest = new ResourceLocation("tinker", "textures/gui/patternchestmini.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
// Draw Slots
this.drawTexturedModalRect(cornerX + 39, cornerY + 26, 0, 166, 98, 36);
if (!logic.isStackInSlot(0))
{
this.drawTexturedModalRect(cornerX + 39, cornerY + 26, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(2))
{
this.drawTexturedModalRect(cornerX + 57, cornerY + 26, 176, 18, 18, 18);
}
if (!logic.isStackInSlot(1))
{
this.drawTexturedModalRect(cornerX + 39, cornerY + 44, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(3))
{
this.drawTexturedModalRect(cornerX + 57, cornerY + 44, 176, 36, 18, 18);
}
// Draw chest
if (drawChestPart)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(minichest);
this.drawTexturedModalRect(cornerX - 116, cornerY + 11, 0, 0, this.xSize, this.ySize);
}
// Draw description
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(description);
cornerX = (this.width + this.xSize) / 2;
cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 126, 0, 126, this.ySize);
}
@Override
protected void mouseClicked (int mouseX, int mouseY, int clickNum)
{
boolean flag = clickNum == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
long l = Minecraft.getSystemTime();
this.field_94074_J = this.field_94072_H == slot && l - this.field_94070_G < 250L && this.field_94073_I == clickNum;
this.field_94068_E = false;
int offsetLeft = drawChestPart ? 108 : 0;
if (clickNum == 0 || clickNum == 1 || flag)
{
int i1 = this.guiLeft;
int j1 = this.guiTop;
boolean flag1 = mouseX < i1 - offsetLeft || mouseY < j1 || mouseX >= i1 + this.xSize || mouseY >= j1 + this.ySize;
int k1 = -1;
if (slot != null)
{
k1 = slot.slotNumber;
}
if (flag1)
{
k1 = -999;
}
if (this.mc.gameSettings.touchscreen && flag1 && this.mc.thePlayer.inventory.getItemStack() == null)
{
this.mc.displayGuiScreen((GuiScreen) null);
return;
}
if (k1 != -1)
{
if (this.mc.gameSettings.touchscreen)
{
if (slot != null && slot.getHasStack())
{
this.clickedSlot = slot;
this.draggedStack = null;
this.isRightMouseClick = clickNum == 1;
}
else
{
this.clickedSlot = null;
}
}
else if (!this.field_94076_q)
{
if (this.mc.thePlayer.inventory.getItemStack() == null)
{
if (clickNum == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
{
this.handleMouseClick(slot, k1, clickNum, 3);
}
else
{
boolean flag2 = k1 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
byte b0 = 0;
if (flag2)
{
this.field_94075_K = slot != null && slot.getHasStack() ? slot.getStack() : null;
b0 = 1;
}
else if (k1 == -999)
{
b0 = 4;
}
this.handleMouseClick(slot, k1, clickNum, b0);
}
this.field_94068_E = true;
}
else
{
this.field_94076_q = true;
this.field_94067_D = clickNum;
this.field_94077_p.clear();
if (clickNum == 0)
{
this.field_94071_C = 0;
}
else if (clickNum == 1)
{
this.field_94071_C = 1;
}
}
}
}
}
this.field_94072_H = slot;
this.field_94070_G = l;
this.field_94073_I = clickNum;
}
}
@@ -0,0 +1,43 @@
package tconstruct.tools.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.tools.logic.PatternChestLogic;
public class PatternChestGui extends GuiContainer
{
public PatternChestLogic logic;
public PatternChestGui(InventoryPlayer inventoryplayer, PatternChestLogic holder, World world, int x, int y, int z)
{
super(holder.getGuiContainer(inventoryplayer, world, x, y, z));
logic = holder;
xSize = 194;
ySize = 168;
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
fontRendererObj.drawString(StatCollector.translateToLocal("inventory.PatternChest"), 60, 6, 0x404040);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 17, (ySize - 96) + 2, 0x404040);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/patternchest.png");
@Override
protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
}
}
@@ -0,0 +1,127 @@
package tconstruct.tools.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.TConstruct;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.inventory.PatternShaperContainer;
import tconstruct.tools.logic.StencilTableLogic;
import tconstruct.util.network.packet.PacketStencilTable;
public class StencilTableGui extends GuiContainer
{
StencilTableLogic logic;
int patternIndex;
public StencilTableGui(InventoryPlayer inventoryplayer, StencilTableLogic shaper, World world, int x, int y, int z)
{
super(new PatternShaperContainer(inventoryplayer, shaper));
logic = shaper;
patternIndex = 0;
}
@Override
public void onGuiClosed ()
{
super.onGuiClosed();
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
fontRendererObj.drawString(StatCollector.translateToLocal("crafters.PatternShaper"), 50, 6, 0x404040);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/patternshaper.png");
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
if (!logic.isStackInSlot(0))
{
this.drawTexturedModalRect(cornerX + 47, cornerY + 34, 176, 0, 18, 18);
}
}
@Override
public void initGui ()
{
super.initGui();
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.buttonList.clear();
/*ToolGuiElement repair = TConstruct.toolButtons.get(0);
GuiButtonTool repairButton = new GuiButtonTool(0, cornerX - 110, cornerY, repair.buttonIconX, repair.buttonIconY, repair.texture); // Repair
repairButton.enabled = false;
this.buttonList.add(repairButton);*/
this.buttonList.add(new GuiButton(0, cornerX - 120, cornerY, 120, 20, (StatCollector.translateToLocal("gui.stenciltable1"))));
this.buttonList.add(new GuiButton(1, cornerX - 120, cornerY + 20, 120, 20, (StatCollector.translateToLocal("gui.stenciltable2"))));
//for (int iter = 0; iter < TConstructContent.patternOutputs.length; iter++)
//{
/*ToolGuiElement element = TConstruct.toolButtons.get(iter);
GuiButtonTool button = new GuiButtonTool(iter, cornerX - 110 + 22 * (iter % 5), cornerY + 22 * (iter / 5), element.buttonIconX, element.buttonIconY, element.texture); // Repair
this.buttonList.add(button);*/
//}
}
@Override
protected void actionPerformed (GuiButton button)
{
ItemStack pattern = logic.getStackInSlot(0);
if (pattern != null && pattern.getItem() == TinkerTools.blankPattern)
{
int meta = pattern.getItemDamage();
if (meta == 0)
{
if (button.id == 0)
{
patternIndex++;
if (patternIndex == 21)
patternIndex++;
if (patternIndex >= TinkerTools.patternOutputs.length - 1)
patternIndex = 0;
}
else if (button.id == 1)
{
patternIndex--;
if (patternIndex < 0)
patternIndex = TinkerTools.patternOutputs.length - 2;
if (patternIndex == 21)
patternIndex--;
}
ItemStack stack = new ItemStack(TinkerTools.woodPattern, 1, patternIndex + 1);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
/*else if (meta == 1 || meta == 2)
{
ItemStack stack = new ItemStack(TContent.metalPattern, 1, 0);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}*/
}
}
void updateServer (ItemStack stack)
{
TConstruct.packetPipeline.sendToServer(new PacketStencilTable(logic.xCoord, logic.yCoord, logic.zCoord, stack));
}
}
@@ -0,0 +1,119 @@
package tconstruct.tools.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
import tconstruct.tools.logic.ToolForgeLogic;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ToolForgeGui extends ToolStationGui
{
int selectedButton;
public ToolForgeGui(InventoryPlayer inventoryplayer, ToolForgeLogic stationlogic, World world, int x, int y, int z)
{
super(inventoryplayer, stationlogic, world, x, y, z);
}
@Override
public void initGui ()
{
super.initGui();
this.buttonList.clear();
ToolGuiElement repair = TConstructClientRegistry.toolButtons.get(0);
GuiButtonTool repairButton = new GuiButtonTool(0, this.guiLeft, this.guiTop, repair.buttonIconX, repair.buttonIconY, repair.domain, repair.texture, repair); // Repair
repairButton.enabled = false;
this.buttonList.add(repairButton);
int offset = TConstructClientRegistry.tierTwoButtons.size();
for (int iter = 0; iter < TConstructClientRegistry.tierTwoButtons.size(); iter++)
{
ToolGuiElement element = TConstructClientRegistry.tierTwoButtons.get(iter);
GuiButtonTool button = new GuiButtonTool(iter + 1, this.guiLeft + 22 * ((iter + 1) % 5), this.guiTop + 22 * ((iter + 1) / 5), element.buttonIconX, element.buttonIconY, repair.domain,
element.texture, element);
this.buttonList.add(button);
}
for (int iter = 1; iter < TConstructClientRegistry.toolButtons.size(); iter++)
{
ToolGuiElement element = TConstructClientRegistry.toolButtons.get(iter);
GuiButtonTool button = new GuiButtonTool(iter + offset, this.guiLeft + 22 * ((iter + offset) % 5), this.guiTop + 22 * ((iter + offset) / 5), element.buttonIconX, element.buttonIconY,
repair.domain, element.texture, element);
this.buttonList.add(button);
}
}
@Override
protected void actionPerformed (GuiButton button)
{
GuiButtonTool b = (GuiButtonTool) button;
((GuiButton) this.buttonList.get(selectedButton)).enabled = true;
selectedButton = button.id;
button.enabled = false;
setSlotType(b.element.slotType);
iconX = b.element.iconsX;
iconY = b.element.iconsY;
title = "\u00A7n" + b.element.title;
body = b.element.body;
}
@Override
void resetGui ()
{
this.text.setText("");
selectedButton = 0;
setSlotType(0);
iconX = new int[] { 0, 1, 2, 13 };
iconY = new int[] { 13, 13, 13, 13 };
title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1");
body = StatCollector.translateToLocal("gui.toolforge2");
}
@Override
void setSlotType (int type)
{
switch (type)
{
case 0:
slotX = new int[] { 56, 38, 38, 14 }; // Repair
slotY = new int[] { 37, 28, 46, 37 };
break;
case 1:
slotX = new int[] { 56, 56, 56, 14 }; // Three parts
slotY = new int[] { 19, 55, 37, 37 };
break;
case 2:
slotX = new int[] { 56, 56, 14, 14 }; // Two parts
slotY = new int[] { 28, 46, 28, 46 };
break;
case 3:
slotX = new int[] { 38, 47, 56, 14 }; // Double head
slotY = new int[] { 28, 46, 28, 37 };
break;
case 4:
slotX = new int[] { 47, 38, 56, 47 }; // Four parts
slotY = new int[] { 19, 37, 37, 55 };
break;
case 5:
slotX = new int[] { 38, 47, 56, 47 }; // Four parts, double head
slotY = new int[] { 19, 55, 19, 37 };
break;
case 6:
slotX = new int[] { 38, 38, 20, 56 }; // Double head
slotY = new int[] { 28, 46, 28, 28 };
break;
case 7:
slotX = new int[] { 56, 56, 56, 14 }; // Three parts reverse
slotY = new int[] { 19, 37, 55, 37 };
break;
}
toolSlots.resetSlots(slotX, slotY);
}
}
@@ -0,0 +1,516 @@
package tconstruct.tools.gui;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import tconstruct.TConstruct;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
import tconstruct.library.tools.ToolCore;
import tconstruct.smeltery.inventory.ActiveContainer;
import tconstruct.tools.inventory.ToolStationContainer;
import tconstruct.tools.logic.ToolStationLogic;
import tconstruct.util.network.packet.PacketToolStation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ToolStationGui extends GuiContainer
{
public ToolStationLogic logic;
public ToolStationContainer toolSlots;
public GuiTextField text;
public String toolName;
public int guiType;
public int[] slotX, slotY, iconX, iconY;
public boolean active;
public String title, body = "";
public ToolStationGui(InventoryPlayer inventoryplayer, ToolStationLogic stationlogic, World world, int x, int y, int z)
{
super((ActiveContainer) stationlogic.getGuiContainer(inventoryplayer, world, x, y, z));
this.logic = stationlogic;
toolSlots = (ToolStationContainer) inventorySlots;
text = new GuiTextField(this.fontRendererObj, 83, 8, 30, 12);
this.text.setMaxStringLength(40);
this.text.setEnableBackgroundDrawing(false);
this.text.setVisible(true);
this.text.setCanLoseFocus(false);
this.text.setFocused(true);
this.text.setTextColor(0xffffff);
toolName = "";
resetGui();
Keyboard.enableRepeatEvents(true);
}
@Override
protected void mouseClicked (int mouseX, int mouseY, int mouseButton)
{
super.mouseClicked(mouseX, mouseY, mouseButton);
if (mouseButton == 0)
{
int gLeft = this.guiLeft + 68 + 110;
int gTop = this.guiTop + 6;
int gwidth = 102;
int gheight = 12;
active = mouseX > gLeft && mouseX < gLeft + gwidth && mouseY > gTop && mouseY < gTop + gheight;
}
}
void resetGui ()
{
this.text.setText("");
guiType = 0;
setSlotType(0);
iconX = new int[] { 0, 1, 2 };
iconY = new int[] { 13, 13, 13 };
title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1");
body = StatCollector.translateToLocal("gui.toolforge2");
}
@Override
public void initGui ()
{
super.initGui();
this.guiLeft -= 110;
this.xSize += 110;
this.buttonList.clear();
ToolGuiElement repair = TConstructClientRegistry.toolButtons.get(0);
GuiButtonTool repairButton = new GuiButtonTool(0, this.guiLeft, this.guiTop, repair.buttonIconX, repair.buttonIconY, repair.domain, repair.texture, repair); // Repair
repairButton.enabled = false;
this.buttonList.add(repairButton);
for (int iter = 1; iter < TConstructClientRegistry.toolButtons.size(); iter++)
{
ToolGuiElement element = TConstructClientRegistry.toolButtons.get(iter);
GuiButtonTool button = new GuiButtonTool(iter, this.guiLeft + 22 * (iter % 5), this.guiTop + 22 * (iter / 5), element.buttonIconX, element.buttonIconY, repair.domain, element.texture,
element);
this.buttonList.add(button);
}
}
@Override
protected void actionPerformed (GuiButton button)
{
((GuiButton) this.buttonList.get(guiType)).enabled = true;
guiType = button.id;
button.enabled = false;
ToolGuiElement element = TConstructClientRegistry.toolButtons.get(guiType);
setSlotType(element.slotType);
iconX = element.iconsX;
iconY = element.iconsY;
title = "\u00A7n" + element.title;
body = element.body;
}
void setSlotType (int type)
{
switch (type)
{
case 0:
slotX = new int[] { 56, 38, 38 }; // Repair
slotY = new int[] { 37, 28, 46 };
break;
case 1:
slotX = new int[] { 56, 56, 56 }; // Three parts
slotY = new int[] { 19, 55, 37 };
break;
case 2:
slotX = new int[] { 56, 56, 14 }; // Two parts
slotY = new int[] { 28, 46, 37 };
break;
case 3:
slotX = new int[] { 38, 47, 56 }; // Double head
slotY = new int[] { 28, 46, 28 };
break;
case 7:
slotX = new int[] { 56, 56, 56 }; // Three parts reverse
slotY = new int[] { 19, 37, 55 };
break;
}
toolSlots.resetSlots(slotX, slotY);
}
@Override
public void updateScreen ()
{
super.updateScreen();
this.text.updateCursorCounter();
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of
* the items)
*/
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.getInvName()), 116, 8, 0x000000);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 118, this.ySize - 96 + 2, 0x000000);
this.fontRendererObj.drawString(toolName + "_", 180, 8, 0xffffff);
if (logic.isStackInSlot(0))
drawToolStats();
else
drawToolInformation();
}
void drawToolStats ()
{
ItemStack stack = logic.getStackInSlot(0);
if (stack.getItem() instanceof ToolCore)
{
ToolCore tool = (ToolCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
this.drawCenteredString(fontRendererObj, "\u00A7n" + tool.getToolName(), 349, 8, 0xffffff);
drawModularToolStats(stack, tool, tags);
}
}
void drawModularToolStats (ItemStack stack, ToolCore tool, NBTTagCompound tags)
{
List categories = Arrays.asList(tool.getTraits());
final int durability = tags.getInteger("Damage");
final int maxDur = tags.getInteger("TotalDurability");
int availableDurability = maxDur - durability;
// Durability
int base = 24;
int offset = 0;
if (maxDur > 0)
{
if (maxDur >= 10000)
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation1"), 294, base + offset * 11, 0xffffff);
offset++;
fontRendererObj.drawString("- " + availableDurability + "/" + maxDur, 294, base + offset * 10, 0xffffff);
offset++;
}
else
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation2") + availableDurability + "/" + maxDur, 294, base + offset * 10, 0xffffff);
offset++;
}
}
final float stonebound = tags.getFloat("Shoddy");
// Attack
if (categories.contains("weapon"))
{
int attack = (int) (tags.getInteger("Attack")) + 1;
float stoneboundDamage = (float) Math.log(durability / 72f + 1) * -2 * stonebound;
attack += stoneboundDamage;
attack *= tool.getDamageModifier();
if (attack < 1)
attack = 1;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart, 294, base + offset * 10, 0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2f + heart, 294, base + offset * 10, 0xffffff);
offset++;
if (stoneboundDamage != 0)
{
heart = stoneboundDamage == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
String bloss = stoneboundDamage > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
this.fontRendererObj.drawString(bloss + (int) stoneboundDamage / 2 + heart, 294, base + offset * 10, 0xffffff);
offset++;
}
offset++;
}
if (categories.contains("bow"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int drawSpeed = tags.getInteger("DrawSpeed");
float flightSpeed = tags.getFloat("FlightSpeed");
float trueDraw = drawSpeed / 20f * flightSpeed;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation6") + df.format(trueDraw) + "s", 294, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation7") + df.format(flightSpeed) + "x", 294, base + offset * 10, 0xffffff);
offset++;
offset++;
}
if (categories.contains("ammo"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int attack = (int) (tags.getInteger("Attack"));
float mass = tags.getFloat("Mass");
float shatter = tags.getFloat("BreakChance");
float accuracy = tags.getFloat("Accuracy");
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation10"), 294, base + offset * 10, 0xffffff);
offset++;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString("- " + attack / 2 + heart, 294, base + offset * 10, 0xffffff);
else
this.fontRendererObj.drawString("- " + attack / 2f + heart, 294, base + offset * 10, 0xffffff);
offset++;
int minAttack = attack;
int maxAttack = attack * 2;
heart = StatCollector.translateToLocal("gui.partcrafter9");
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation11"), 294, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(df.format(minAttack / 2f) + "-" + df.format(maxAttack / 2f) + heart, 294, base + offset * 10, 0xffffff);
offset++;
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation8") + df.format(mass), 294, base + offset * 10, 0xffffff);
offset++;
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation9") + df.format(accuracy - 4) + "%", 294, base + offset * 10, 0xffffff);
offset++;
/*
* this.fontRendererObj.drawString("Chance to break: " +
* df.format(shatter)+"%", xSize + 8, base + offset * 10, 0xffffff);
* offset++;
*/
offset++;
}
// Mining
if (categories.contains("dualharvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed") / 100f;
float mineSpeed2 = tags.getInteger("MiningSpeed2") / 100f;
float stoneboundSpeed = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
float trueSpeed = mineSpeed + stoneboundSpeed;
float trueSpeed2 = mineSpeed + stoneboundSpeed;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation12"), 294, base + offset * 10, 0xffffff);
offset++;
fontRendererObj.drawString("- " + df.format(trueSpeed) + ", " + df.format(trueSpeed2), 294, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRendererObj.drawString(bloss + df.format(stoneboundSpeed), 294, base + offset * 10, 0xffffff);
offset++;
}
offset++;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation13"), 294, base + offset * 10, 0xffffff);
offset++;
fontRendererObj.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", " + getHarvestLevelName(tags.getInteger("HarvestLevel2")), 294, base + offset * 10, 0xffffff);
offset++;
offset++;
}
else if (categories.contains("harvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
int heads = 1;
if (tags.hasKey("MiningSpeed2"))
{
mineSpeed += tags.getInteger("MiningSpeed2");
heads++;
}
if (tags.hasKey("MiningSpeedHandle"))
{
mineSpeed += tags.getInteger("MiningSpeedHandle");
heads++;
}
if (tags.hasKey("MiningSpeedExtra"))
{
mineSpeed += tags.getInteger("MiningSpeedExtra");
heads++;
}
float trueSpeed = mineSpeed / (heads * 100f);
float stoneboundSpeed = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
trueSpeed += stoneboundSpeed;
if (trueSpeed < 0)
trueSpeed = 0;
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation14") + df.format(trueSpeed), 294, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRendererObj.drawString(bloss + df.format(stoneboundSpeed), 294, base + offset * 10, 0xffffff);
offset++;
}
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation15") + getHarvestLevelName(tags.getInteger("HarvestLevel")), 294, base + offset * 10, 0xffffff);
offset++;
offset++;
}
else if (categories.contains("utility"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
float trueSpeed = mineSpeed / (100f);
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation16") + trueSpeed, 294, base + offset * 10, 0xffffff);
offset++;
offset++;
}
int modifiers = tags.getInteger("Modifiers");
if (modifiers > 0)
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), 294, base + offset * 10, 0xffffff);
offset++;
}
if (tags.hasKey("Tooltip1"))
{
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation17"), 294, base + offset * 10, 0xffffff);
}
boolean displayToolTips = true;
int tipNum = 0;
while (displayToolTips)
{
tipNum++;
String tooltip = "ModifierTip" + tipNum;
if (tags.hasKey(tooltip))
{
String tipName = tags.getString(tooltip);
fontRendererObj.drawString("- " + tipName, 294, base + (offset + tipNum) * 10, 0xffffff);
}
else
displayToolTips = false;
}
}
void drawToolInformation ()
{
this.drawCenteredString(fontRendererObj, title, 349, 8, 0xffffff);
fontRendererObj.drawSplitString(body, 294, 24, 115, 0xffffff);
}
protected String getHarvestLevelName (int num)
{
switch (num)
{
case 0:
return StatCollector.translateToLocal("gui.partcrafter.mining1");
case 1:
return StatCollector.translateToLocal("gui.partcrafter.mining2");
case 2:
return StatCollector.translateToLocal("gui.partcrafter.mining3");
case 3:
return StatCollector.translateToLocal("gui.partcrafter.mining4"); // Mithril
case 4:
return StatCollector.translateToLocal("gui.partcrafter.mining5");
case 5:
return StatCollector.translateToLocal("gui.partcrafter.mining6");
default:
return String.valueOf(num);
}
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/toolstation.png");
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
/**
* Draw the background layer for the GuiContainer (everything behind the
* items)
*/
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
final int cornerX = this.guiLeft + 110;
this.drawTexturedModalRect(cornerX, this.guiTop, 0, 0, 176, this.ySize);
if (active)
{
this.drawTexturedModalRect(cornerX + 62, this.guiTop, 0, this.ySize, 112, 22);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(icons);
// Draw the slots
for (int i = 0; i < slotX.length; i++)
{
this.drawTexturedModalRect(cornerX + slotX[i] - 4, this.guiTop + slotY[i] - 4, 140, 212, 28, 28);
if (!logic.isStackInSlot(i + 1))
{
this.drawTexturedModalRect(cornerX + slotX[i], this.guiTop + slotY[i], 18 * iconX[i], 18 * iconY[i], 18, 18);
}
}
// Draw description
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(description);
this.drawTexturedModalRect(cornerX + 176, this.guiTop, 0, 0, 126, this.ySize + 30);
}
@Override
protected void keyTyped (char par1, int keyCode)
{
if (keyCode == 1 || (!active && keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()))
{
logic.setToolname("");
updateServer("");
Keyboard.enableRepeatEvents(false);
this.mc.thePlayer.closeScreen();
}
else if (active)
{
text.textboxKeyTyped(par1, keyCode);
toolName = text.getText().trim();
logic.setToolname(toolName);
updateServer(toolName);
}
}
void updateServer (String name)
{
/*
* ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
* DataOutputStream outputStream = new DataOutputStream(bos); try {
* outputStream.writeByte(1);
* outputStream.writeInt(logic.getWorld().provider.dimensionId);
* outputStream.writeInt(logic.xCoord);
* outputStream.writeInt(logic.yCoord);
* outputStream.writeInt(logic.zCoord); outputStream.writeUTF(name); }
* catch (Exception ex) { ex.printStackTrace(); }
*
* Packet250CustomPayload packet = new Packet250CustomPayload();
* packet.channel = "TConstruct"; packet.data = bos.toByteArray();
* packet.length = bos.size();
*
* PacketDispatcher.sendPacketToServer(packet);
*/
TConstruct.packetPipeline.sendToServer(new PacketToolStation(logic.xCoord, logic.yCoord, logic.zCoord, name));
}
/*
* protected void mouseClicked(int par1, int par2, int par3) {
* super.mouseClicked(par1, par2, par3); text.mouseClicked(par1, par2,
* par3); }
*/
}
@@ -1,14 +1,14 @@
package tconstruct.tools.inventory;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.TConstruct;
import tconstruct.library.event.ToolCraftedEvent;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.ToolCore;
public class SlotTool extends Slot
@@ -24,57 +24,53 @@ public class SlotTool extends Slot
}
/**
* Check if the stack is a valid item for this slot. Always true beside for
* the armor slots.
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid (ItemStack stack)
{
return false;
// return stack.getItem() instanceof ToolCore;
//return stack.getItem() instanceof ToolCore;
}
@Override
public void onPickupFromSlot (EntityPlayer par1EntityPlayer, ItemStack stack)
{
this.onCrafting(stack);
// stack.setUnlocalizedName("\u00A7f" + toolName);
//stack.setUnlocalizedName("\u00A7f" + toolName);
super.onPickupFromSlot(par1EntityPlayer, stack);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes,
* not ore and wood. Typically increases an internal count then calls
* onCrafting(item).
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
@Override
protected void onCrafting (ItemStack stack, int par2)
{
// this.field_75228_b += par2;
//this.field_75228_b += par2;
this.onCrafting(stack);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes,
* not ore and wood.
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
@Override
protected void onCrafting (ItemStack stack)
{
NBTTagCompound tags = stack.getTagCompound();
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
if (stack.getItem() instanceof IModifyable)
{
tags.getCompoundTag("InfiTool").setBoolean("Built", true);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName());
Boolean full = (inventory.getStackInSlot(2) != null || inventory.getStackInSlot(3) != null);
for (int i = 2; i <= 3; i++)
inventory.decrStackSize(i, 1);
int amount = inventory.getStackInSlot(1).getItem() instanceof ToolCore ? stack.stackSize : 1;
ItemStack compare = inventory.getStackInSlot(1);
int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1;
inventory.decrStackSize(1, amount);
if (!player.worldObj.isRemote && full)
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "tinker:little_saw", 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F);
// player.worldObj.playAuxSFX(1021, (int)player.posX,
// (int)player.posY, (int)player.posZ, 0);
MinecraftForge.EVENT_BUS.post(new ToolCraftedEvent(this.inventory, player, stack));
}
else //Simply naming items
{
int amount = inventory.getStackInSlot(1).stackSize;
inventory.decrStackSize(1, amount);
}
}
}
}
@@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.library.event.ToolCraftedEvent;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.modifier.IModifyable;
public class SlotToolForge extends SlotTool
{
@@ -20,21 +20,25 @@ public class SlotToolForge extends SlotTool
super(entityplayer, builder, par3, par4, par5);
}
@Override
protected void onCrafting (ItemStack stack)
{
NBTTagCompound tags = stack.getTagCompound();
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
if (stack.getItem() instanceof IModifyable)
{
tags.getCompoundTag("InfiTool").setBoolean("Built", true);
Boolean full = (inventory.getStackInSlot(2) != null || inventory.getStackInSlot(3) != null);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName());
Boolean full = (inventory.getStackInSlot(2) != null || inventory.getStackInSlot(3) != null || inventory.getStackInSlot(4) != null);
for (int i = 2; i <= 4; i++)
inventory.decrStackSize(i, 1);
int amount = inventory.getStackInSlot(1).getItem() instanceof ToolCore ? stack.stackSize : 1;
ItemStack compare = inventory.getStackInSlot(1);
int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1;
inventory.decrStackSize(1, amount);
if (!player.worldObj.isRemote && full)
player.worldObj.playAuxSFX(1021, (int) player.posX, (int) player.posY, (int) player.posZ, 0);
MinecraftForge.EVENT_BUS.post(new ToolCraftedEvent(this.inventory, player, stack));
}
else //Simply naming items
{
int amount = inventory.getStackInSlot(1).stackSize;
inventory.decrStackSize(1, amount);
}
}
}
}
@@ -6,7 +6,9 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.library.event.ToolCraftedEvent;
import tconstruct.library.modifier.IModifyable;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.logic.ToolForgeLogic;
import tconstruct.tools.logic.ToolStationLogic;
@@ -78,16 +80,24 @@ public class ToolForgeContainer extends ToolStationContainer
@Override
protected void craftTool (ItemStack stack)
{
NBTTagCompound tags = stack.getTagCompound();
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
if (stack.getItem() instanceof IModifyable)
{
tags.getCompoundTag("InfiTool").setBoolean("Built", true);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName());
Boolean full = (logic.getStackInSlot(2) != null || logic.getStackInSlot(3) != null || logic.getStackInSlot(4) != null);
for (int i = 2; i <= 4; i++)
logic.decrStackSize(i, 1);
int amount = logic.getStackInSlot(1).getItem() instanceof ToolCore ? stack.stackSize : 1;
ItemStack compare = logic.getStackInSlot(1);
int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1;
logic.decrStackSize(1, amount);
EntityPlayer player = invPlayer.player;
if (!player.worldObj.isRemote && full)
player.worldObj.playAuxSFX(1021, (int) player.posX, (int) player.posY, (int) player.posZ, 0);
MinecraftForge.EVENT_BUS.post(new ToolCraftedEvent(this.logic, player, stack));
}
else //Simply naming items
{
int amount = logic.getStackInSlot(1).stackSize;
logic.decrStackSize(1, amount);
if (!logic.getWorldObj().isRemote)
logic.getWorldObj().playAuxSFX(1021, (int) logic.xCoord, (int) logic.yCoord, (int) logic.zCoord, 0);
}
}
@@ -8,7 +8,9 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.library.event.ToolCraftedEvent;
import tconstruct.library.modifier.IModifyable;
import tconstruct.smeltery.inventory.ActiveContainer;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.logic.ToolStationLogic;
@@ -135,16 +137,25 @@ public class ToolStationContainer extends ActiveContainer
protected void craftTool (ItemStack stack)
{
NBTTagCompound tags = stack.getTagCompound();
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
if (stack.getItem() instanceof IModifyable)
{
tags.getCompoundTag("InfiTool").setBoolean("Built", true);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName());
Boolean full = (logic.getStackInSlot(2) != null || logic.getStackInSlot(3) != null);
for (int i = 2; i <= 3; i++)
logic.decrStackSize(i, 1);
int amount = logic.getStackInSlot(1).getItem() instanceof ToolCore ? stack.stackSize : 1;
ItemStack compare = logic.getStackInSlot(1);
int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1;
logic.decrStackSize(1, amount);
EntityPlayer player = invPlayer.player;
if (!player.worldObj.isRemote && full)
player.worldObj.playSoundEffect(logic.xCoord, logic.yCoord, logic.zCoord, "tinker:little_saw", 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F);
MinecraftForge.EVENT_BUS.post(new ToolCraftedEvent(this.logic, player, stack));
}
else
//Simply naming items
{
int amount = logic.getStackInSlot(1).stackSize;
logic.decrStackSize(1, amount);
logic.getWorldObj().playSoundEffect(logic.xCoord, logic.yCoord, logic.zCoord, "tinker:little_saw", 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F);
}
}
@@ -161,28 +172,6 @@ public class ToolStationContainer extends ActiveContainer
Slot otherInventorySlot;
ItemStack copyStack = null;
/*
* if (stack.isStackable()) { while (stack.stackSize > 0 &&
* (!playerInventory && slotIndex < slotsTotal || playerInventory &&
* slotIndex >= slotsStart)) { otherInventorySlot =
* (Slot)this.inventorySlots.get(slotIndex); copyStack =
* otherInventorySlot.getStack();
*
* if (copyStack != null && copyStack.itemID == stack.itemID &&
* (!stack.getHasSubtypes() || stack.getItemDamage() ==
* copyStack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack,
* copyStack)) { int totalSize = copyStack.stackSize + stack.stackSize;
*
* if (totalSize <= stack.getMaxStackSize()) { stack.stackSize = 0;
* copyStack.stackSize = totalSize; otherInventorySlot.onSlotChanged();
* failedToMerge = true; } else if (copyStack.stackSize <
* stack.getMaxStackSize()) { stack.stackSize -= stack.getMaxStackSize()
* - copyStack.stackSize; copyStack.stackSize = stack.getMaxStackSize();
* otherInventorySlot.onSlotChanged(); failedToMerge = true; } }
*
* if (playerInventory) { --slotIndex; } else { ++slotIndex; } } }
*/
if (stack.stackSize > 0)
{
if (playerInventory)
@@ -220,14 +209,6 @@ public class ToolStationContainer extends ActiveContainer
}
}
/*
* boolean emptySlots = ( ((Slot) inventorySlots.get(2)).getStack() ==
* null && ((Slot) inventorySlots.get(3)).getStack() == null );
* TConstruct.logger.info("Empty slots"); if (!failedToMerge &&
* emptySlots) player.worldObj.playAuxSFX(1021, (int)player.posX,
* (int)player.posY, (int)player.posZ, 0);
*/
return failedToMerge;
}
}
@@ -7,7 +7,9 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import tconstruct.library.crafting.ModifyBuilder;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.tools.inventory.ToolStationContainer;
/* Simple class for storing items in the block
@@ -69,18 +71,63 @@ public class ToolStationLogic extends InventoryLogic implements ISidedInventory
public void buildTool (String name)
{
toolName = name;
ItemStack tool = ToolBuilder.instance.buildTool(inventory[1], inventory[2], inventory[3], name);
if (inventory[0] == null)
inventory[0] = tool;
else
ItemStack output = null;
if (inventory[1] != null)
{
NBTTagCompound tags = inventory[0].getTagCompound();
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
if (inventory[1].getItem() instanceof IModifyable) //Modify item
{
inventory[0] = tool;
if (inventory[2] == null && inventory[3] == null)
output = inventory[1].copy();
else
{
output = ModifyBuilder.instance.modifyItem(inventory[1], new ItemStack[] { inventory[2], inventory[3] });
}
}
else
//Build new item
{
toolName = name;
ItemStack tool = ToolBuilder.instance.buildTool(inventory[1], inventory[2], inventory[3], name);
if (inventory[0] == null)
output = tool;
else if (tool != null)
{
NBTTagCompound tags = tool.getTagCompound();
if (!tags.getCompoundTag(((IModifyable) tool.getItem()).getBaseTagName()).hasKey("Built"))
{
output = tool;
}
}
}
if (!name.equals("")) //Name item
{
ItemStack temp = inventory[1].copy();
if (output != null)
temp = output;
if (temp != null)
{
NBTTagCompound tags = temp.getTagCompound();
if (tags == null)
{
tags = new NBTTagCompound();
temp.setTagCompound(tags);
}
if (!(tags.hasKey("display")))
{
NBTTagCompound display = new NBTTagCompound();
String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name;
display.setString("Name", dName);
tags.setTag("display", display);
temp.setRepairCost(2);
output = temp;
}
}
}
}
inventory[0] = output;
}
public void setToolname (String name)