diff --git a/resources/assets/tinker/textures/gui/battlesignText.png b/resources/assets/tinker/textures/gui/battlesignText.png new file mode 100644 index 00000000000..d53e259c3bf Binary files /dev/null and b/resources/assets/tinker/textures/gui/battlesignText.png differ diff --git a/src/main/java/tconstruct/client/pages/ModifierPage.java b/src/main/java/tconstruct/client/pages/ModifierPage.java index 15c803d1a14..a94504860c6 100644 --- a/src/main/java/tconstruct/client/pages/ModifierPage.java +++ b/src/main/java/tconstruct/client/pages/ModifierPage.java @@ -1,5 +1,6 @@ package tconstruct.client.pages; +import java.util.*; import mantle.client.pages.BookPage; import mantle.lib.client.MantleClientRegistry; import net.minecraft.client.renderer.RenderHelper; @@ -8,9 +9,6 @@ import org.lwjgl.opengl.*; import org.w3c.dom.*; -import java.util.LinkedList; -import java.util.List; - public class ModifierPage extends BookPage { String type; @@ -29,19 +27,21 @@ public void readPageFromXML (Element element) type = nodes.item(0).getTextContent(); nodes = element.getElementsByTagName("recipe"); - if (nodes != null) { + if (nodes != null) + { String recipe = nodes.item(0).getTextContent(); icons = MantleClientRegistry.getRecipeIcons(recipe); - if(type.equals("travelmulti")) + if (type.equals("travelmulti")) { List stacks = new LinkedList(); List tools = new LinkedList(); String[] suffixes = new String[] { "goggles", "vest", "wings", "boots", "glove", "belt" }; - for(String suffix : suffixes) + for (String suffix : suffixes) { ItemStack[] icons2 = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent() + suffix); - if(icons2 != null) { + if (icons2 != null) + { stacks.add(icons2); tools.add(suffix); } @@ -49,7 +49,8 @@ public void readPageFromXML (Element element) iconsMulti = new ItemStack[stacks.size()][]; toolMulti = new ItemStack[stacks.size()]; - for(int i = 0; i < stacks.size(); i++) { + for (int i = 0; i < stacks.size(); i++) + { iconsMulti[i] = stacks.get(i); toolMulti[i] = MantleClientRegistry.getManualIcon("travel" + tools.get(i)); } @@ -66,9 +67,9 @@ public void readPageFromXML (Element element) public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) { String tStation = new String("Tool Station"); - if(icons.length > 4) + if (icons.length > 4) tStation = "Tinker Table"; - if(icons.length > 3) + if (icons.length > 3) tStation = "Tool Forge"; if (isTranslatable) tStation = StatCollector.translateToLocal(tStation); @@ -80,34 +81,35 @@ public void renderContentLayer (int localWidth, int localHeight, boolean isTrans ItemStack toolstack = MantleClientRegistry.getManualIcon("ironpick"); if (type.equals("weapon")) toolstack = MantleClientRegistry.getManualIcon("ironlongsword"); - if(type.equals("travelgoggles")) + if (type.equals("travelgoggles")) toolstack = MantleClientRegistry.getManualIcon("travelgoggles"); - if(type.equals("travelvest")) + if (type.equals("travelvest")) toolstack = MantleClientRegistry.getManualIcon("travelvest"); - if(type.equals("travelwings")) + if (type.equals("travelwings")) toolstack = MantleClientRegistry.getManualIcon("travelwings"); - if(type.equals("travelboots")) + if (type.equals("travelboots")) toolstack = MantleClientRegistry.getManualIcon("travelboots"); - if(type.equals("travelbelt")) + if (type.equals("travelbelt")) toolstack = MantleClientRegistry.getManualIcon("travelbelt"); - if(type.equals("travelglove")) + if (type.equals("travelglove")) toolstack = MantleClientRegistry.getManualIcon("travelglove"); - if(type.equals("travelmulti")) + if (type.equals("travelmulti")) toolstack = toolMulti[counter]; // update displayed item - if(iconsMulti != null && iconsMulti.length > 0 && type.equals("travelmulti") && System.currentTimeMillis() - lastUpdate > 1000) + if (iconsMulti != null && iconsMulti.length > 0 && type.equals("travelmulti") && System.currentTimeMillis() - lastUpdate > 1000) { lastUpdate = System.currentTimeMillis(); counter++; - if(counter >= iconsMulti.length) + if (counter >= iconsMulti.length) counter = 0; icons = iconsMulti[counter]; toolstack = toolMulti[counter]; } manual.renderitem.zLevel = 100; - if(icons.length < 4) { + if (icons.length < 4) + { manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, toolstack, (localWidth + 54) / 2, (localHeight + 54) / 2); manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 130) / 2, (localHeight + 54) / 2); manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[1], (localWidth + 18) / 2, (localHeight + 36) / 2); @@ -121,7 +123,7 @@ public void renderContentLayer (int localWidth, int localHeight, boolean isTrans manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[1], (localWidth - 2) / 2, (localHeight + 36) / 2); manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[2], (localWidth - 2) / 2, (localHeight + 74) / 2); manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[3], (localWidth + 36) / 2, (localHeight + 36) / 2); - if(icons[4] != null) + if (icons[4] != null) manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[4], (localWidth + 36) / 2, (localHeight + 74) / 2); } manual.renderitem.zLevel = 0; @@ -137,7 +139,7 @@ public void renderContentLayer (int localWidth, int localHeight, boolean isTrans public void renderBackgroundLayer (int localWidth, int localHeight) { manual.getMC().getTextureManager().bindTexture(background); - if(icons.length > 3) + if (icons.length > 3) manual.drawTexturedModalRect(localWidth - 7, localHeight + 32, 0, 80, 182, 78); else manual.drawTexturedModalRect(localWidth + 12, localHeight + 32, 0, 0, 154, 78); diff --git a/src/main/java/tconstruct/items/tools/BattleSign.java b/src/main/java/tconstruct/items/tools/BattleSign.java index c99b1252d23..dcf3ca335ca 100644 --- a/src/main/java/tconstruct/items/tools/BattleSign.java +++ b/src/main/java/tconstruct/items/tools/BattleSign.java @@ -1,11 +1,13 @@ package tconstruct.items.tools; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.*; import net.minecraft.world.World; +import tconstruct.TConstruct; import tconstruct.library.tools.Weapon; -import tconstruct.tools.TinkerTools; +import tconstruct.tools.*; import tconstruct.tools.logic.EquipLogic; public class BattleSign extends Weapon @@ -16,50 +18,12 @@ public BattleSign() this.setUnlocalizedName("InfiTool.Battlesign"); } - /* - * public ItemStack onItemRightClick(ItemStack stack, World world, - * EntityPlayer player) { if (!player.isSneaking()) - * player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); return - * stack; } - */ - @Override public String getToolName () { return "Battlesign"; } - /* - * public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, - * World par3World, int par4, int par5, int par6, int par7, float par8, - * float par9, float par10) { if (par7 == 0 || !player.isSneaking()) { - * return false; } else if (!par3World.getBlockMaterial(par4, par5, - * par6).isSolid()) { return false; } else { if (par7 == 1) { ++par5; } - * - * if (par7 == 2) { --par6; } - * - * if (par7 == 3) { ++par6; } - * - * if (par7 == 4) { --par4; } - * - * if (par7 == 5) { ++par4; } - * - * if (!player.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)) { - * return false; } else if (!Block.signPost.canPlaceBlockAt(par3World, par4, - * par5, par6)) { return false; } else { if (par7 == 1) { int var11 = - * MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 16.0F / - * 360.0F) + 0.5D) & 15; par3World.setBlock(par4, par5, par6, - * Block.signPost.blockID, var11); } else { par3World.setBlock(par4, par5, - * par6, Block.signWall.blockID, par7); } - * - * //--par1ItemStack.stackSize; TileEntitySign var12 = - * (TileEntitySign)par3World.getBlockTileEntity(par4, par5, par6); - * - * if (var12 != null) { player.displayGUIEditSign(var12); } - * - * return true; } } } - */ - @Override public Item getHeadItem () { @@ -176,6 +140,11 @@ else if (!TinkerTools.battlesignBlock.canPlaceBlockAt(world, x, y, z)) logic.setEquipmentItem(stack); --stack.stackSize; + if (FMLCommonHandler.instance().getSide() == Side.CLIENT) + { + player.openGui(TConstruct.instance, ToolProxyClient.battlesignTextID, world, x, y, z); + } + return true; } } diff --git a/src/main/java/tconstruct/smeltery/SmelteryProxyClient.java b/src/main/java/tconstruct/smeltery/SmelteryProxyClient.java index ccd730d783f..7d2e32066aa 100644 --- a/src/main/java/tconstruct/smeltery/SmelteryProxyClient.java +++ b/src/main/java/tconstruct/smeltery/SmelteryProxyClient.java @@ -43,7 +43,8 @@ void registerRenderer () RenderingRegistry.registerBlockHandler(new RenderBlockFluid()); RenderingRegistry.registerBlockHandler(new BlockRenderCastingChannel()); - if (!PHConstruct.newSmeltery) { + if (!PHConstruct.newSmeltery) + { RenderingRegistry.registerBlockHandler(new SmelteryRender()); } diff --git a/src/main/java/tconstruct/smeltery/TinkerSmeltery.java b/src/main/java/tconstruct/smeltery/TinkerSmeltery.java index 09fcaa98cc2..2b2602b4aa3 100644 --- a/src/main/java/tconstruct/smeltery/TinkerSmeltery.java +++ b/src/main/java/tconstruct/smeltery/TinkerSmeltery.java @@ -1077,7 +1077,8 @@ protected static void addRecipesForSmeltery () Smeltery.addSmelteryFuel(pyrotheum, 1500, 9); // BLOOD FOR THE BLOOD GOD - if(TinkerWorld.meatBlock != null) { + if (TinkerWorld.meatBlock != null) + { Smeltery.addMelting(new ItemStack(Items.rotten_flesh), TinkerWorld.meatBlock, 0, 200, new FluidStack(bloodFluid, 5)); Smeltery.addMelting(new ItemStack(TinkerWorld.strangeFood, 1, 1), TinkerWorld.meatBlock, 0, 80, new FluidStack(bloodFluid, 160)); } diff --git a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java index b87cc7da22e..4dd14235443 100644 --- a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java +++ b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java @@ -34,7 +34,7 @@ public SmelteryGui(InventoryPlayer inventoryplayer, SmelteryLogic smeltery, Worl xSize = 248; smeltery.updateFuelDisplay(); - columns = ((SmelteryContainer)this.container).columns; + columns = ((SmelteryContainer) this.container).columns; } @Override @@ -55,7 +55,7 @@ public void drawScreen (int mouseX, int mouseY, float par3) protected void updateScrollbar (int mouseX, int mouseY, float par3) { - if (logic.getBlockCapacity() > columns*maxRows) + if (logic.getBlockCapacity() > columns * maxRows) { boolean mouseDown = Mouse.isButtonDown(0); int lefto = this.guiLeft; @@ -109,13 +109,12 @@ protected void drawGuiContainerForegroundLayer (int mouseX, int mouseY) fontRendererObj.drawString(StatCollector.translateToLocal("crafters.Smeltery"), 86, 5, 0x404040); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 90, (ySize - 96) + 2, 0x404040); - int cornerX = (width - xSize) / 2 + 36; int cornerY = (height - ySize) / 2; int[] fluidHeights = calcLiquidHeights(); int base = 0; - for(int i = 0; i < fluidHeights.length; i++) + for (int i = 0; i < fluidHeights.length; i++) { int leftX = cornerX + 54; int topY = (cornerY + 68) - fluidHeights[i] - base; @@ -169,29 +168,32 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) } } - if(logic.getCapacity() > 0) { + if (logic.getCapacity() > 0) + { // Liquids - molten metal int base = 0; int[] fluidHeights = calcLiquidHeights(); // render the fluids int basePos = 54; - for (int i = 0; i < logic.moltenMetal.size(); i++) { + for (int i = 0; i < logic.moltenMetal.size(); i++) + { FluidStack liquid = logic.moltenMetal.get(i); IIcon icon = liquid.getFluid().getStillIcon(); - if(icon == null) + if (icon == null) continue; int height = fluidHeights[i]; int h = height; - while(h > 0) { + while (h > 0) + { int v = Math.min(16, h); // we render in 16x16 squares so the texture doesn't get distorted drawLiquidRect(cornerX + basePos + 00, (cornerY + 68) - h - base, icon, 16, v); drawLiquidRect(cornerX + basePos + 16, (cornerY + 68) - h - base, icon, 16, v); drawLiquidRect(cornerX + basePos + 32, (cornerY + 68) - h - base, icon, 16, v); - drawLiquidRect(cornerX + basePos + 48, (cornerY + 68) - h - base, icon, 4, v); + drawLiquidRect(cornerX + basePos + 48, (cornerY + 68) - h - base, icon, 4, v); h -= 16; } base += height; @@ -206,29 +208,29 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) // Side inventory int xleft = 46; - xleft += 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns - int h = logic.getBlockCapacity()/columns; - if(logic.getBlockCapacity()%columns != 0) + xleft += 22 * (columns - 3); // we have to shift the whole thing to the left if we have more than 3 columns + int h = logic.getBlockCapacity() / columns; + if (logic.getBlockCapacity() % columns != 0) h++; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(backgroundSide); if (logic.getBlockCapacity() > 0) { - if(h >= 8) + if (h >= 8) { // standard 3 slots drawTexturedModalRect(cornerX - xleft, cornerY, 0, 0, 72, ySize - 8); // additional slots - for(int i = 0; i < columns-3; i++) - drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY, 50, 0, 22, ySize - 8); + for (int i = 0; i < columns - 3; i++) + drawTexturedModalRect(cornerX - xleft + 72 + i * 22, cornerY, 50, 0, 22, ySize - 8); // right end drawTexturedModalRect(cornerX - 46 + 72, cornerY, 72, 0, 25, ySize - 8); int sx = cornerX + 32; int sy = (int) (cornerY + 8 + 127 * currentScroll); // highlighted scroll bar - if(isScrolling || ( mouseX >= sx && mouseX <= sx + 12 && mouseY >= sy && mouseY <= sy + 15)) + if (isScrolling || (mouseX >= sx && mouseX <= sx + 12 && mouseY >= sy && mouseY <= sy + 15)) drawTexturedModalRect(sx, sy, 122, 0, 12, 15); // scroll bar else @@ -236,22 +238,20 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) } else { - int yd = 43 + 18*(h-3); + int yd = 43 + 18 * (h - 3); // slots // standard 3 slots drawTexturedModalRect(cornerX - xleft, cornerY, 0, 0, 72, yd); // additional slots - for(int i = 0; i < columns-3; i++) - drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY, 50, 0, 22, yd); + for (int i = 0; i < columns - 3; i++) + drawTexturedModalRect(cornerX - xleft + 72 + i * 22, cornerY, 50, 0, 22, yd); // right end drawTexturedModalRect(cornerX - 46 + 72, cornerY, 72, 0, 25, yd); - - // bottom end drawTexturedModalRect(cornerX - xleft, cornerY + yd, 0, 133, 72, 25); - for(int i = 0; i < columns-3; i++) - drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY + yd, 50, 133, 22, 25); + for (int i = 0; i < columns - 3; i++) + drawTexturedModalRect(cornerX - xleft + 72 + i * 22, cornerY + yd, 50, 133, 22, 25); drawTexturedModalRect(cornerX - 46 + 72, cornerY + yd, 72, 133, 25, 25); // grayed out scroll bar @@ -262,10 +262,10 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) xleft -= 8; // Temperature int slotSize = logic.getBlockCapacity(); - if (slotSize > columns*maxRows) - slotSize = columns*maxRows; + if (slotSize > columns * maxRows) + slotSize = columns * maxRows; int iter; - for (iter = 0; iter < slotSize && iter + slotPos*columns < logic.getBlockCapacity(); iter++) + for (iter = 0; iter < slotSize && iter + slotPos * columns < logic.getBlockCapacity(); iter++) { int slotTemp = logic.getTempForSlot(iter + slotPos * columns) - 20; int maxTemp = logic.getMeltingPointForSlot(iter + slotPos * columns) - 20; @@ -280,32 +280,36 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) int maxSlots = Math.min(maxRows, h) * columns; for (; iter < maxSlots; iter++) { - drawTexturedModalRect(cornerX - xleft + (iter % columns * 22)-1, cornerY + 8 + (iter / columns * 18)-1, 98, 47, 22, 18); + drawTexturedModalRect(cornerX - xleft + (iter % columns * 22) - 1, cornerY + 8 + (iter / columns * 18) - 1, 98, 47, 22, 18); } } - protected int[] calcLiquidHeights() + protected int[] calcLiquidHeights () { int fluidHeights[] = new int[logic.moltenMetal.size()]; int cap = logic.getCapacity(); if (logic.getTotalLiquid() > cap) cap = logic.getTotalLiquid(); - for (int i = 0; i < logic.moltenMetal.size(); i++) { + for (int i = 0; i < logic.moltenMetal.size(); i++) + { FluidStack liquid = logic.moltenMetal.get(i); float h = (float) liquid.amount / (float) cap; - fluidHeights[i] = Math.max(3, (int) Math.ceil(h*52f)); + fluidHeights[i] = Math.max(3, (int) Math.ceil(h * 52f)); } // check if we have enough height to render everything int sum = 0; - do { + do + { sum = 0; int biggest = -1; int m = 0; - for (int i = 0; i < fluidHeights.length; i++) { + for (int i = 0; i < fluidHeights.length; i++) + { sum += fluidHeights[i]; - if (logic.moltenMetal.get(i).amount > biggest) { + if (logic.moltenMetal.get(i).amount > biggest) + { biggest = logic.moltenMetal.get(i).amount; m = i; } diff --git a/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java b/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java index abab9cf06a8..2851e058d13 100644 --- a/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java +++ b/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java @@ -30,13 +30,13 @@ public SmelteryContainer(InventoryPlayer inventoryplayer, SmelteryLogic smeltery int y = 0; int xleft = 2; - xleft -= 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns + xleft -= 22 * (columns - 3); // we have to shift the whole thing to the left if we have more than 3 columns - for(int i = 0; i < totalSlots; i++) + for (int i = 0; i < totalSlots; i++) { - int x = i%columns; + int x = i % columns; this.addDualSlotToContainer(new ActiveSlot(smeltery, x + y * columns, xleft + x * 22, 8 + y * 18, y < 8)); - if(x == columns-1) + if (x == columns - 1) y++; } @@ -65,7 +65,7 @@ public int updateRows (int invRow) for (int iter = 0; iter < activeInventorySlots.size(); iter++) { ActiveSlot slot = (ActiveSlot) activeInventorySlots.get(iter); - if (slot.activeSlotNumber >= basePos && slot.activeSlotNumber < basePos + columns*SmelteryGui.maxRows) + if (slot.activeSlotNumber >= basePos && slot.activeSlotNumber < basePos + columns * SmelteryGui.maxRows) { slot.setActive(true); } @@ -74,7 +74,7 @@ public int updateRows (int invRow) slot.setActive(false); } int xleft = 2; - xleft -= 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns + xleft -= 22 * (columns - 3); // we have to shift the whole thing to the left if we have more than 3 columns int xPos = (iter - basePos) % columns; int yPos = (iter - basePos) / columns; @@ -88,9 +88,9 @@ public int updateRows (int invRow) public int scrollTo (float scrollPos) { - int slots = SmelteryGui.maxRows*columns; + int slots = SmelteryGui.maxRows * columns; float total = (logic.getSizeInventory() - slots) / columns; - if((logic.getSizeInventory() - slots)%columns != 0) + if ((logic.getSizeInventory() - slots) % columns != 0) total++; int rowPos = Math.round(total * scrollPos); return updateRows(rowPos); diff --git a/src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.java b/src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.java index 1f54a5bbc22..eb71661a2d7 100644 --- a/src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.java @@ -4,8 +4,7 @@ import net.minecraftforge.fluids.FluidStack; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.CastingRecipe; -import tconstruct.library.event.SmelteryCastEvent; -import tconstruct.library.event.SmelteryCastedEvent; +import tconstruct.library.event.*; public class CastingBasinLogic extends CastingBlockLogic { @@ -15,12 +14,14 @@ public CastingBasinLogic() } @Override - public SmelteryCastEvent getCastingEvent(CastingRecipe recipe, FluidStack metal) { + public SmelteryCastEvent getCastingEvent (CastingRecipe recipe, FluidStack metal) + { return new SmelteryCastEvent.CastingBasin(recipe, metal); } @Override - public SmelteryCastedEvent getCastedEvent(CastingRecipe recipe, ItemStack result) { + public SmelteryCastedEvent getCastedEvent (CastingRecipe recipe, ItemStack result) + { return new SmelteryCastedEvent.CastingBasin(recipe, result); } } diff --git a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java index a22b605ba3d..813f715cde9 100644 --- a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java @@ -3,25 +3,22 @@ import cpw.mods.fml.common.eventhandler.Event; import mantle.blocks.abstracts.InventoryLogic; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ISidedInventory; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; +import net.minecraft.network.*; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; import tconstruct.TConstruct; -import tconstruct.library.crafting.CastingRecipe; -import tconstruct.library.crafting.LiquidCasting; -import tconstruct.library.event.SmelteryCastEvent; -import tconstruct.library.event.SmelteryCastedEvent; +import tconstruct.library.crafting.*; +import tconstruct.library.event.*; import tconstruct.library.util.IPattern; -public abstract class CastingBlockLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory { +public abstract class CastingBlockLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory +{ public FluidStack liquid; protected int castingDelay = 0; protected int renderOffset = 0; @@ -31,7 +28,8 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid protected int tick; protected final LiquidCasting liquidCasting; - public CastingBlockLogic(LiquidCasting casting) { + public CastingBlockLogic(LiquidCasting casting) + { // input slot and output slot, 1 item in it max super(2, 1); this.liquidCasting = casting; @@ -81,12 +79,14 @@ public int updateCapacity (int capacity) /* FluidHandler stuff. Mostly delegated to Tank stuff */ @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + public int fill (ForgeDirection from, FluidStack resource, boolean doFill) + { return fill(resource, doFill); } @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain) + { // only same liquid if (liquid.getFluid() != resource.getFluid()) return null; @@ -95,34 +95,40 @@ public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrai } @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain) + { return drain(maxDrain, doDrain); } @Override - public boolean canFill(ForgeDirection from, Fluid fluid) { + public boolean canFill (ForgeDirection from, Fluid fluid) + { return fill(from, new FluidStack(fluid, 1), false) > 0; } @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) { + public boolean canDrain (ForgeDirection from, Fluid fluid) + { FluidStack drained = drain(from, new FluidStack(fluid, 1), false); return drained != null && drained.amount > 0; } /* Tank stuff */ @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) { + public FluidTankInfo[] getTankInfo (ForgeDirection from) + { return new FluidTankInfo[] { getInfo() }; } @Override - public FluidStack getFluid() { + public FluidStack getFluid () + { return liquid == null ? null : liquid.copy(); } @Override - public int getFluidAmount() { + public int getFluidAmount () + { return liquid != null ? liquid.amount : 0; } @@ -132,22 +138,25 @@ public int getLiquidAmount () } @Override - public int getCapacity() { + public int getCapacity () + { return this.capacity; } @Override - public FluidTankInfo getInfo() { + public FluidTankInfo getInfo () + { return new FluidTankInfo(this); } /** * Create and return the casting event here. It'll be fired automatically. */ - public abstract SmelteryCastEvent getCastingEvent(CastingRecipe recipe, FluidStack metal); + public abstract SmelteryCastEvent getCastingEvent (CastingRecipe recipe, FluidStack metal); @Override - public int fill(FluidStack resource, boolean doFill) { + public int fill (FluidStack resource, boolean doFill) + { if (resource == null) return 0; @@ -227,7 +236,8 @@ else if (resource.isFluidEqual(this.liquid)) } @Override - public FluidStack drain(int maxDrain, boolean doDrain) { + public FluidStack drain (int maxDrain, boolean doDrain) + { if (liquid == null || liquid.fluidID <= 0 || castingDelay > 0) return null; if (liquid.amount <= 0) @@ -272,7 +282,8 @@ public int[] getAccessibleSlotsFromSide (int side) } @Override - public boolean canInsertItem (int slot, ItemStack itemstack, int side) { + public boolean canInsertItem (int slot, ItemStack itemstack, int side) + { // can't insert if there's liquid in it if (liquid != null) return false; @@ -282,44 +293,52 @@ public boolean canInsertItem (int slot, ItemStack itemstack, int side) { } @Override - public boolean canExtractItem (int slot, ItemStack itemstack, int side) { + public boolean canExtractItem (int slot, ItemStack itemstack, int side) + { // only output slot return slot == 1; } /* We don't have a gui or anything */ @Override - public Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z) { + public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) + { return null; } @Override - protected String getDefaultName() { + protected String getDefaultName () + { return null; } @Override - public String getInventoryName() { + public String getInventoryName () + { return null; } @Override - public String getInvName() { + public String getInvName () + { return null; } @Override - public boolean hasCustomInventoryName() { + public boolean hasCustomInventoryName () + { return false; } @Override - public void openInventory() { + public void openInventory () + { } @Override - public void closeInventory() { + public void closeInventory () + { } @@ -359,7 +378,7 @@ public void updateEntity () /** * Create and return the casting event here. It'll be fired automatically. */ - public abstract SmelteryCastedEvent getCastedEvent(CastingRecipe recipe, ItemStack result); + public abstract SmelteryCastedEvent getCastedEvent (CastingRecipe recipe, ItemStack result); public void castLiquid () { @@ -385,7 +404,6 @@ public void castLiquid () } } - @Override public void readFromNBT (NBTTagCompound tags) { diff --git a/src/main/java/tconstruct/smeltery/logic/CastingTableLogic.java b/src/main/java/tconstruct/smeltery/logic/CastingTableLogic.java index e2100667bf9..58452b358dd 100644 --- a/src/main/java/tconstruct/smeltery/logic/CastingTableLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/CastingTableLogic.java @@ -4,8 +4,7 @@ import net.minecraftforge.fluids.FluidStack; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.CastingRecipe; -import tconstruct.library.event.SmelteryCastEvent; -import tconstruct.library.event.SmelteryCastedEvent; +import tconstruct.library.event.*; public class CastingTableLogic extends CastingBlockLogic { @@ -15,12 +14,14 @@ public CastingTableLogic() } @Override - public SmelteryCastEvent getCastingEvent(CastingRecipe recipe, FluidStack metal) { + public SmelteryCastEvent getCastingEvent (CastingRecipe recipe, FluidStack metal) + { return new SmelteryCastEvent.CastingTable(recipe, metal); } @Override - public SmelteryCastedEvent getCastedEvent(CastingRecipe recipe, ItemStack result) { + public SmelteryCastedEvent getCastedEvent (CastingRecipe recipe, ItemStack result) + { return new SmelteryCastedEvent.CastingTable(recipe, result); } } \ No newline at end of file diff --git a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java index 89295f5365b..18d3d5a9f26 100644 --- a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java @@ -73,19 +73,19 @@ public SmelteryLogic() meltingTemps = new int[0]; } - public int getBlocksPerLayer() + public int getBlocksPerLayer () { int xd = maxPos.x - minPos.x + 1; int zd = maxPos.z - minPos.z + 1; return xd * zd; } - public int getCapacityPerLayer() + public int getCapacityPerLayer () { - return getBlocksPerLayer()*MB_PER_BLOCK_CAPACITY; + return getBlocksPerLayer() * MB_PER_BLOCK_CAPACITY; } - public int getBlockCapacity() + public int getBlockCapacity () { return maxBlockCapacity; } @@ -324,7 +324,7 @@ void detectEntities () if (minPos == null || maxPos == null) return; - AxisAlignedBB box = AxisAlignedBB.getBoundingBox(minPos.x, minPos.y, minPos.z, maxPos.x+1, minPos.y + layers, maxPos.z+1); + AxisAlignedBB box = AxisAlignedBB.getBoundingBox(minPos.x, minPos.y, minPos.z, maxPos.x + 1, minPos.y + layers, maxPos.z + 1); List list = worldObj.getEntitiesWithinAABB(Entity.class, box); for (Object o : list) @@ -737,18 +737,18 @@ public void checkValidPlacement () { switch (getRenderDirection()) { - case 2: // +z - alignInitialPlacement(xCoord, yCoord, zCoord + 1); - break; - case 3: // -z - alignInitialPlacement(xCoord, yCoord, zCoord - 1); - break; - case 4: // +x - alignInitialPlacement(xCoord + 1, yCoord, zCoord); - break; - case 5: // -x - alignInitialPlacement(xCoord - 1, yCoord, zCoord); - break; + case 2: // +z + alignInitialPlacement(xCoord, yCoord, zCoord + 1); + break; + case 3: // -z + alignInitialPlacement(xCoord, yCoord, zCoord - 1); + break; + case 4: // +x + alignInitialPlacement(xCoord + 1, yCoord, zCoord); + break; + case 5: // -x + alignInitialPlacement(xCoord - 1, yCoord, zCoord); + break; } } @@ -760,15 +760,15 @@ public void alignInitialPlacement (int x, int y, int z) // adjust the x-position of the block until the difference between the outer walls is at most 1 // basically this means we center the block inside the smeltery on the x axis. int xd1 = 1, xd2 = 1; // x-difference - for(int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed + for (int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed { - if(worldObj.getBlock(x - xd1, y, z) == null || worldObj.isAirBlock(x - xd1,y,z)) + if (worldObj.getBlock(x - xd1, y, z) == null || worldObj.isAirBlock(x - xd1, y, z)) xd1++; - else if(worldObj.getBlock(x + xd2, y, z) == null || worldObj.isAirBlock(x + xd2,y,z)) + else if (worldObj.getBlock(x + xd2, y, z) == null || worldObj.isAirBlock(x + xd2, y, z)) xd2++; // if one side hit a wall and the other didn't we might have to center our x-position again - if(xd1-xd2 > 1) + if (xd1 - xd2 > 1) { // move x and offsets to the -x xd1--; @@ -776,7 +776,7 @@ else if(worldObj.getBlock(x + xd2, y, z) == null || worldObj.isAirBlock(x + xd2, xd2++; } // or the right - if(xd2-xd1 > 1) + if (xd2 - xd1 > 1) { xd2--; x++; @@ -785,15 +785,15 @@ else if(worldObj.getBlock(x + xd2, y, z) == null || worldObj.isAirBlock(x + xd2, } // same for z-axis int zd1 = 1, zd2 = 1; - for(int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed + for (int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed { - if(worldObj.getBlock(x, y, z - zd1) == null || worldObj.isAirBlock(x, y, z - zd1)) + if (worldObj.getBlock(x, y, z - zd1) == null || worldObj.isAirBlock(x, y, z - zd1)) zd1++; - else if(worldObj.getBlock(x, y, z + zd2) == null || worldObj.isAirBlock(x, y, z + zd2)) + else if (worldObj.getBlock(x, y, z + zd2) == null || worldObj.isAirBlock(x, y, z + zd2)) zd2++; // if one side hit a wall and the other didn't we might have to center our x-position again - if(zd1-zd2 > 1) + if (zd1 - zd2 > 1) { // move x and offsets to the -x zd1--; @@ -801,7 +801,7 @@ else if(worldObj.getBlock(x, y, z + zd2) == null || worldObj.isAirBlock(x, y, z zd2++; } // or the right - if(zd2-zd1 > 1) + if (zd2 - zd1 > 1) { zd2--; z++; @@ -810,7 +810,7 @@ else if(worldObj.getBlock(x, y, z + zd2) == null || worldObj.isAirBlock(x, y, z } // do the check - int[] sides = new int[] {xd1, xd2, zd1, zd2}; + int[] sides = new int[] { xd1, xd2, zd1, zd2 }; checkValidStructure(x, y, z, sides); } @@ -878,7 +878,7 @@ public void checkValidStructure (int x, int y, int z, int[] sides) } } - public boolean checkBricksOnLevel(int x, int y, int z, int[] sides) + public boolean checkBricksOnLevel (int x, int y, int z, int[] sides) { int numBricks = 0; Block block; @@ -911,16 +911,16 @@ public boolean checkBricksOnLevel(int x, int y, int z, int[] sides) numBricks += checkBricks(xMax, y, zPos); } - int neededBricks = (xMax-xMin)*2 + (zMax-zMin)*2 - 4; // -4 because corners are not needed + int neededBricks = (xMax - xMin) * 2 + (zMax - zMin) * 2 - 4; // -4 because corners are not needed return numBricks == neededBricks; } - public boolean checkSameLevel(int x, int y, int z, int[] sides) + public boolean checkSameLevel (int x, int y, int z, int[] sides) { lavaTanks.clear(); - boolean check = checkBricksOnLevel(x,y,z,sides); + boolean check = checkBricksOnLevel(x, y, z, sides); if (check && lavaTanks.size() > 0) return true; @@ -930,9 +930,9 @@ public boolean checkSameLevel(int x, int y, int z, int[] sides) public int recurseStructureUp (int x, int y, int z, int[] sides, int count) { - boolean check = checkBricksOnLevel(x,y,z,sides); + boolean check = checkBricksOnLevel(x, y, z, sides); - if(!check) + if (!check) return count; count++; @@ -941,11 +941,12 @@ public int recurseStructureUp (int x, int y, int z, int[] sides, int count) public int recurseStructureDown (int x, int y, int z, int[] sides, int count) { - boolean check = checkBricksOnLevel(x,y,z,sides); + boolean check = checkBricksOnLevel(x, y, z, sides); - if(!check) { + if (!check) + { // regular check failed, maybe it's the bottom? - Block block = worldObj.getBlock(x,y,z); + Block block = worldObj.getBlock(x, y, z); if (block != null && !worldObj.isAirBlock(x, y, z)) if (validBlockID(block)) return validateBottom(x, y, z, sides, count); @@ -975,13 +976,13 @@ public int validateBottom (int x, int y, int z, int[] sides, int count) } } - int neededBricks = (xMax+1-xMin) * (zMax+1-zMin); // +1 because we want inclusive the upper border + int neededBricks = (xMax + 1 - xMin) * (zMax + 1 - zMin); // +1 because we want inclusive the upper border if (bottomBricks == neededBricks) { tempValidStructure = true; - minPos = new CoordTuple(xMin, y+1, zMin); - maxPos = new CoordTuple(xMax, y+1, zMax); + minPos = new CoordTuple(xMin, y + 1, zMin); + maxPos = new CoordTuple(xMax, y + 1, zMax); } return count; } @@ -1034,8 +1035,6 @@ boolean validTankID (Block blockID) return blockID == TinkerSmeltery.lavaTank || blockID == TinkerSmeltery.lavaTankNether; } - - @Override public int getCapacity () { diff --git a/src/main/java/tconstruct/smeltery/model/SmelteryRender.java b/src/main/java/tconstruct/smeltery/model/SmelteryRender.java index c4b23c20753..35f229cd46a 100644 --- a/src/main/java/tconstruct/smeltery/model/SmelteryRender.java +++ b/src/main/java/tconstruct/smeltery/model/SmelteryRender.java @@ -71,7 +71,7 @@ public boolean renderSmeltery (IBlockAccess world, int x, int y, int z, Block bl int countSize = liquidSize > room ? room : liquidSize; liquidSize -= countSize; - float height = countSize > cap ? 1.0F : (float)countSize / (float)cap; + float height = countSize > cap ? 1.0F : (float) countSize / (float) cap; float renderBase = base; float renderHeight = height + base; base += height; @@ -79,8 +79,8 @@ public boolean renderSmeltery (IBlockAccess world, int x, int y, int z, Block bl renderer.setRenderBounds(0, renderBase, 0, 1, renderHeight, 1); Fluid fluid = liquid.getFluid(); - for(int xi = from.x; xi <= to.x; xi++) - for(int zi = from.z; zi <= to.z; zi++) + for (int xi = from.x; xi <= to.x; xi++) + for (int zi = from.z; zi <= to.z; zi++) { float minX = xi == from.x ? -0.001F : 0F; float minZ = zi == from.z ? -0.001F : 0F; @@ -109,8 +109,8 @@ void renderLayer (SmelteryLogic logic, int start, CoordTuple from, CoordTuple to { renderer.setRenderBounds(-0.001F, -0.001F, -0.001F, 1.001F, 1.001F, 1.001F); int i = start; - for(int x = from.x; x <= to.x; x++) - for(int z = from.z; z <= to.z; z++) + for (int x = from.x; x <= to.x; x++) + for (int z = from.z; z <= to.z; z++) { ItemStack input = logic.getStackInSlot(i); if (input != null && logic.getTempForSlot(i) > 20) diff --git a/src/main/java/tconstruct/tools/ToolProxyClient.java b/src/main/java/tconstruct/tools/ToolProxyClient.java index 7b70fb8fed2..6c098100818 100644 --- a/src/main/java/tconstruct/tools/ToolProxyClient.java +++ b/src/main/java/tconstruct/tools/ToolProxyClient.java @@ -239,6 +239,7 @@ protected void registerGuiHandler () TProxyCommon.registerClientGuiHandler(toolForgeID, this); TProxyCommon.registerClientGuiHandler(furnaceID, this); TProxyCommon.registerClientGuiHandler(craftingStationID, this); + TProxyCommon.registerClientGuiHandler(battlesignTextID, this); } @Override @@ -252,6 +253,8 @@ public Object getClientGuiElement (int ID, EntityPlayer player, World world, int return new PatternChestGui(player.inventory, (PatternChestLogic) world.getTileEntity(x, y, z), world, x, y, z); if (ID == ToolProxyCommon.frypanGuiID) return new FrypanGui(player.inventory, (FrypanLogic) world.getTileEntity(x, y, z), world, x, y, z); + if (ID == ToolProxyCommon.battlesignTextID) + return new BattlesignGui((BattlesignLogic) world.getTileEntity(x, y, z)); if (ID == ToolProxyCommon.stencilTableID) return new StencilTableGui(player.inventory, (StencilTableLogic) world.getTileEntity(x, y, z), world, x, y, z); diff --git a/src/main/java/tconstruct/tools/ToolProxyCommon.java b/src/main/java/tconstruct/tools/ToolProxyCommon.java index 5d0913814d9..76fad92ef21 100644 --- a/src/main/java/tconstruct/tools/ToolProxyCommon.java +++ b/src/main/java/tconstruct/tools/ToolProxyCommon.java @@ -17,6 +17,7 @@ public class ToolProxyCommon implements IGuiHandler public static final int toolForgeID = 5; public static final int furnaceID = 8; public static final int craftingStationID = 11; + public static final int battlesignTextID = 12; public ToolProxyCommon() { diff --git a/src/main/java/tconstruct/tools/blocks/BattlesignBlock.java b/src/main/java/tconstruct/tools/blocks/BattlesignBlock.java index b13bdfda42d..f14514552f6 100644 --- a/src/main/java/tconstruct/tools/blocks/BattlesignBlock.java +++ b/src/main/java/tconstruct/tools/blocks/BattlesignBlock.java @@ -1,8 +1,10 @@ package tconstruct.tools.blocks; +import cpw.mods.fml.relauncher.*; import java.util.List; import net.minecraft.block.material.Material; import net.minecraft.entity.*; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.*; @@ -17,7 +19,7 @@ public BattlesignBlock(Material material) { super(material); - this.setBlockBounds(0.45F, 0F, 0.45F, 0.55F, 1F, 0.55F); + this.setBlockBounds(0.45F, 0F, 0.45F, 0.55F, 1.125F, 0.55F); } @Override @@ -26,6 +28,13 @@ public int getRenderType () return BattlesignRender.battlesignModelID; } + @SideOnly(Side.CLIENT) + @Override + public boolean shouldSideBeRendered (IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_) + { + return p_149646_5_ == 0 && this.minY > 0.0D ? true : (p_149646_5_ == 1 && this.maxY < 1.0D ? true : (p_149646_5_ == 2 && this.minZ > 0.0D ? true : (p_149646_5_ == 3 && this.maxZ < 1.0D ? true : (p_149646_5_ == 4 && this.minX > 0.0D ? true : (p_149646_5_ == 5 && this.maxX < 1.0D ? true : !(p_149646_1_.getBlock(p_149646_2_, p_149646_3_, p_149646_4_).isOpaqueCube() && p_149646_1_.getBlock(p_149646_2_, p_149646_3_ + 1, p_149646_4_).isOpaqueCube())))))); + } + @Override public TileEntity createNewTileEntity (World world, int metadata) { @@ -84,7 +93,7 @@ public void addCollisionBoxesToList (World world, int x, int y, int z, AxisAlign setBlockBoundsBasedOnState(world, x, y, z); super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity); - setBlockBounds(0.45F, 0F, 0.45F, 0.55F, 1F, 0.55F); + setBlockBounds(0.45F, 0F, 0.45F, 0.55F, 1.125F, 0.55F); super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity); this.setBlockBoundsForItemRender(); @@ -96,4 +105,10 @@ public TileEntity createTileEntity (World world, int metadata) return new BattlesignLogic(); } + @Override + public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer) + { + return null; + } + } diff --git a/src/main/java/tconstruct/tools/gui/BattlesignGui.java b/src/main/java/tconstruct/tools/gui/BattlesignGui.java new file mode 100644 index 00000000000..38d06585699 --- /dev/null +++ b/src/main/java/tconstruct/tools/gui/BattlesignGui.java @@ -0,0 +1,178 @@ +package tconstruct.tools.gui; + +import net.minecraft.client.gui.*; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.*; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import tconstruct.TConstruct; +import tconstruct.library.TConstructRegistry; +import tconstruct.tools.logic.BattlesignLogic; +import tconstruct.util.network.SignDataPacket; + +public class BattlesignGui extends GuiScreen +{ + private BattlesignLogic battlesign; + + private float bgColR = 1F; + private float bgColG = 1F; + private float bgColB = 1F; + private static ResourceLocation background = new ResourceLocation("tinker:textures/gui/battlesignText.png"); + private String[] text = { "", "", "", "", "" }; + int currentLine = 0; + + public BattlesignGui(BattlesignLogic logic) + { + this.battlesign = logic; + + ItemStack stack = logic.getEquipmentItem(); + if (stack != null) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag("InfiTool"); + + if (tag != null) + { + int head = tag.getInteger("Head"); + + int bgCol = TConstructRegistry.getMaterial(head).primaryColor(); + + bgColR = (float) (bgCol >> 16 & 255) / 255.0F; + bgColG = (float) (bgCol >> 8 & 255) / 255.0F; + bgColB = (float) (bgCol & 255) / 255.0F; + } + } + } + + @Override + public void initGui () + { + buttonList.clear(); + + super.initGui(); + + Keyboard.enableRepeatEvents(true); + + int k = (this.width - 100) / 2; + int l = (this.height - 110) / 2; + + buttonList.add(new GuiButton(0, k, l + 100, 100, 20, "Done")); + } + + @Override + public void drawScreen (int mouseX, int mouseY, float something) + { + Tessellator t = Tessellator.instance; + + GL11.glColor4f(bgColR, bgColG, bgColB, 1F); + this.mc.getTextureManager().bindTexture(background); + int k = (this.width - 100) / 2; + int l = (this.height - 103) / 2; + + this.drawTexturedModalRect(k, l, 0, 0, 100, 103); + + super.drawScreen(mouseX, mouseY, something); + + GL11.glPushMatrix(); + + float lum = calcLuminance(bgColR, bgColG, bgColB); + for (int i = 0; i < text.length; i++) + { + fontRendererObj.drawString((lum >= 35F ? EnumChatFormatting.BLACK : lum >= 31F ? EnumChatFormatting.GRAY : EnumChatFormatting.WHITE) + (i == currentLine ? "> " : "") + text[i] + (i == currentLine ? " \u00A7r" + (lum >= 35F ? EnumChatFormatting.BLACK : lum >= 31F ? EnumChatFormatting.GRAY : EnumChatFormatting.WHITE) + "<" : ""), k - fontRendererObj.getStringWidth((i == currentLine ? "> " : "") + text[i] + (i == currentLine ? " <" : "")) / 2 + 51, l + 4 + 10 * i, 0); + } + + GL11.glPopMatrix(); + } + + @Override + protected void keyTyped (char c, int i) + { + super.keyTyped(c, i); + + if (fontRendererObj.getStringWidth(text[currentLine]) < 90 && ChatAllowedCharacters.isAllowedCharacter(c)) + { + if (Keyboard.isKeyDown(56) && c == 'f' && (text[currentLine].length() == 0 || text[currentLine].charAt(text[currentLine].length() - 1) != '\u00A7')) + { + text[currentLine] += "\u00A7"; + } + else + { + text[currentLine] += c; + } + } + else + { + switch (i) + { + case 14: + if (text[currentLine].length() > 0) + { + text[currentLine] = text[currentLine].substring(0, text[currentLine].length() - 1); + } + + break; + case 28: + moveLine(1); + break; + case 200: + moveLine(-1); + break; + case 208: + moveLine(1); + break; + } + } + } + + private void moveLine (int i) + { + if (i < 0) + { + if (currentLine <= 0) + { + currentLine = text.length - 1; + } + else + { + currentLine--; + } + } + else + { + if (currentLine >= text.length - 1) + { + currentLine = 0; + } + else + { + currentLine++; + } + } + } + + @Override + public void onGuiClosed () + { + super.onGuiClosed(); + + Keyboard.enableRepeatEvents(false); + + TConstruct.packetPipeline.sendToServer(new SignDataPacket(battlesign.getWorldObj().provider.dimensionId, battlesign.xCoord, battlesign.yCoord, battlesign.zCoord, text)); + } + + private float calcLuminance (float r, float g, float b) + { + return (r * 255 * 0.299f + g * 255 * 0.587f + b * 255 * 0.114f) / 3; + } + + @Override + protected void actionPerformed (GuiButton button) + { + if (button.id == 0) + { + this.mc.displayGuiScreen((GuiScreen) null); + this.mc.setIngameFocus(); + } + } +} diff --git a/src/main/java/tconstruct/tools/logic/BattlesignLogic.java b/src/main/java/tconstruct/tools/logic/BattlesignLogic.java index 2cdd4c93610..41fea5da39c 100644 --- a/src/main/java/tconstruct/tools/logic/BattlesignLogic.java +++ b/src/main/java/tconstruct/tools/logic/BattlesignLogic.java @@ -3,6 +3,8 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.world.World; /* Slots @@ -11,6 +13,7 @@ public class BattlesignLogic extends EquipLogic { + protected String[] text; public BattlesignLogic() { @@ -23,15 +26,34 @@ public String getDefaultName () return "decoration.battlesign"; } + @Override /* NBT */ public void readFromNBT (NBTTagCompound tags) { super.readFromNBT(tags); + + text = new String[tags.getInteger("lineCount")]; + for (int i = 0; i < text.length; i++) + { + text[i] = tags.getString("line" + i); + } } + @Override public void writeToNBT (NBTTagCompound tags) { super.writeToNBT(tags); + + if (text == null) + { + text = new String[0]; + } + + tags.setInteger("lineCount", text.length); + for (int i = 0; i < text.length; i++) + { + tags.setString("line" + i, text[i]); + } } @Override @@ -55,4 +77,30 @@ public void openInventory () public void closeInventory () { } + + public void setText (String[] text) + { + this.text = text; + } + + public String[] getText () + { + return text; + } + + @Override + public S35PacketUpdateTileEntity getDescriptionPacket () + { + NBTTagCompound compound = new NBTTagCompound(); + this.writeToNBT(compound); + + S35PacketUpdateTileEntity packet = new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound); + return packet; + } + + @Override + public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity pkt) + { + this.readFromNBT(pkt.func_148857_g()); + } } \ No newline at end of file diff --git a/src/main/java/tconstruct/tools/model/BattlesignTesr.java b/src/main/java/tconstruct/tools/model/BattlesignTesr.java index 4dc062b5dea..2bca9ddf4b4 100644 --- a/src/main/java/tconstruct/tools/model/BattlesignTesr.java +++ b/src/main/java/tconstruct/tools/model/BattlesignTesr.java @@ -6,14 +6,15 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; +import tconstruct.tools.logic.BattlesignLogic; public class BattlesignTesr extends TileEntitySpecialRenderer { - @Override - public void renderTileEntityAt (TileEntity te, double x, double y, double z, float something) + public void renderTileEntityAt (BattlesignLogic te, double x, double y, double z, float something) { GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_LIGHTING); float f = 0.016666668F * 0.6666667F; @@ -27,27 +28,31 @@ public void renderTileEntityAt (TileEntity te, double x, double y, double z, flo { case 0: GL11.glRotatef(-90F, 0F, 1F, 0F); - GL11.glTranslatef(5F, -97F, -37F); + GL11.glTranslatef(5F, -96F, -37F); break; case 1: GL11.glRotatef(90F, 0F, 1F, 0F); - GL11.glTranslatef(-85F, -97F, 53F); + GL11.glTranslatef(-85F, -96F, 53F); break; case 2: - GL11.glTranslatef(5F, -97F, 53F); + GL11.glTranslatef(5F, -96F, 53F); break; case 3: GL11.glRotatef(180F, 0F, 1F, 0F); - GL11.glTranslatef(-85F, -97F, -37F); + GL11.glTranslatef(-85F, -96F, -37F); break; } - String strings[] = { "Chicken nuggets", "Curly fries", "fuj1n", "mDiyo", "Frosty_Chicken" }; - float lum = calcLuminance(te.getWorldObj().getBlock(te.xCoord, te.yCoord, te.zCoord).colorMultiplier(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord)); + String strings[] = te.getText(); - for (int i = 0; i < strings.length; i++) + if (strings != null && strings.length > 0) { - fr.drawString((lum >= 35F ? "" : lum >= 31F ? EnumChatFormatting.DARK_GRAY : EnumChatFormatting.WHITE) + strings[i], -fr.getStringWidth(strings[i]) / 2 + 40, 10 * i, 0); + float lum = calcLuminance(te.getWorldObj().getBlock(te.xCoord, te.yCoord, te.zCoord).colorMultiplier(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord)); + + for (int i = 0; i < strings.length; i++) + { + fr.drawString((lum >= 35F ? EnumChatFormatting.BLACK : lum >= 31F ? EnumChatFormatting.GRAY : EnumChatFormatting.WHITE) + strings[i], -fr.getStringWidth(strings[i]) / 2 + 40, 10 * i, 0); + } } GL11.glPopMatrix(); @@ -61,4 +66,10 @@ private float calcLuminance (int rgb) return (r * 0.299f + g * 0.587f + b * 0.114f) / 3; } + + @Override + public void renderTileEntityAt (TileEntity te, double x, double y, double z, float something) + { + this.renderTileEntityAt((BattlesignLogic) te, x, y, z, something); + } } diff --git a/src/main/java/tconstruct/util/network/PacketPipeline.java b/src/main/java/tconstruct/util/network/PacketPipeline.java index f41d97dad92..36805af3d97 100644 --- a/src/main/java/tconstruct/util/network/PacketPipeline.java +++ b/src/main/java/tconstruct/util/network/PacketPipeline.java @@ -128,6 +128,7 @@ public void registerPackets () registerPacket(PatternTablePacket.class); registerPacket(ToolStationPacket.class); registerPacket(PacketUpdateTE.class); + registerPacket(SignDataPacket.class); } // Method to call from FMLPostInitializationEvent diff --git a/src/main/java/tconstruct/util/network/SignDataPacket.java b/src/main/java/tconstruct/util/network/SignDataPacket.java new file mode 100644 index 00000000000..bd608f01607 --- /dev/null +++ b/src/main/java/tconstruct/util/network/SignDataPacket.java @@ -0,0 +1,87 @@ +package tconstruct.util.network; + +import cpw.mods.fml.common.network.ByteBufUtils; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import mantle.common.network.AbstractPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import tconstruct.TConstruct; +import tconstruct.tools.logic.BattlesignLogic; + +public class SignDataPacket extends AbstractPacket +{ + private int dimension, x, y, z, length; + private String[] text; + + public SignDataPacket() + { + } + + public SignDataPacket(int dimension, int x, int y, int z, String[] text) + { + this.text = text; + this.dimension = dimension; + this.x = x; + this.y = y; + this.z = z; + this.length = text.length; + } + + @Override + public void encodeInto (ChannelHandlerContext ctx, ByteBuf buffer) + { + buffer.writeInt(dimension); + buffer.writeInt(x); + buffer.writeInt(y); + buffer.writeInt(z); + buffer.writeInt(length); + for (int i = 0; i < length; i++) + { + ByteBufUtils.writeUTF8String(buffer, text[i]); + } + } + + @Override + public void decodeInto (ChannelHandlerContext ctx, ByteBuf buffer) + { + dimension = buffer.readInt(); + x = buffer.readInt(); + y = buffer.readInt(); + z = buffer.readInt(); + length = buffer.readInt(); + text = new String[length]; + for (int i = 0; i < length; i++) + { + text[i] = ByteBufUtils.readUTF8String(buffer); + } + } + + @Override + public void handleClientSide (EntityPlayer player) + { + TileEntity te = player.worldObj.getTileEntity(x, y, z); + + if (te != null && te instanceof BattlesignLogic) + { + BattlesignLogic logic = (BattlesignLogic) te; + + logic.setText(text); + } + } + + @Override + public void handleServerSide (EntityPlayer player) + { + TileEntity te = player.worldObj.getTileEntity(x, y, z); + + if (te != null && te instanceof BattlesignLogic) + { + BattlesignLogic logic = (BattlesignLogic) te; + + logic.setText(text); + } + + TConstruct.packetPipeline.sendToDimension(new SignDataPacket(dimension, x, y, z, text), dimension); + } +}