mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-21 12:42:57 +00:00
Made battlesigns have editable text
This commit is contained in:
1 parent
fc0d73dbf6
commit
3d028e7123
20 files changed
+545
-205
No files matched your search
@@ -239,6 +239,7 @@ public class ToolProxyClient extends ToolProxyCommon
|
||||
TProxyCommon.registerClientGuiHandler(toolForgeID, this);
|
||||
TProxyCommon.registerClientGuiHandler(furnaceID, this);
|
||||
TProxyCommon.registerClientGuiHandler(craftingStationID, this);
|
||||
TProxyCommon.registerClientGuiHandler(battlesignTextID, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,6 +253,8 @@ public class ToolProxyClient extends ToolProxyCommon
|
||||
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);
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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 class BattlesignBlock extends EquipBlock
|
||||
{
|
||||
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 class BattlesignBlock extends EquipBlock
|
||||
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 class BattlesignBlock extends EquipBlock
|
||||
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 class BattlesignBlock extends EquipBlock
|
||||
return new BattlesignLogic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package tconstruct.tools.logic;
|
||||
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 @@ import net.minecraft.world.World;
|
||||
|
||||
public class BattlesignLogic extends EquipLogic
|
||||
{
|
||||
protected String[] text;
|
||||
|
||||
public BattlesignLogic()
|
||||
{
|
||||
@@ -23,15 +26,34 @@ public class BattlesignLogic extends EquipLogic
|
||||
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 class BattlesignLogic extends EquipLogic
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,15 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
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 class BattlesignTesr extends TileEntitySpecialRenderer
|
||||
{
|
||||
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 @@ public class BattlesignTesr extends TileEntitySpecialRenderer
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user