Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tile Entity
- -----------------------------------------------------------------------------------------------------
- package net.minecraft.src;
- import net.minecraft.block.Block;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.INetworkManager;
- import net.minecraft.network.packet.Packet;
- import net.minecraft.network.packet.Packet132TileEntityData;
- import net.minecraft.tileentity.TileEntity;
- public class GenuineTileEntityTrophySilver extends TileEntity {
- public String type;
- public float size;
- public GenuineTileEntityTrophySilver() {
- this.type = "Chicken";
- this.size = 0.5F;
- }
- @Override
- public void readFromNBT(NBTTagCompound nbttagcompound) {
- super.readFromNBT(nbttagcompound);
- this.type = nbttagcompound.getString("type");
- this.size = nbttagcompound.getFloat("size");
- System.out.println("Load Type: " + type);
- }
- @Override
- public void writeToNBT(NBTTagCompound nbttagcompound) {
- super.writeToNBT(nbttagcompound);
- nbttagcompound.setString("type", this.type);
- nbttagcompound.setFloat("size", this.size);
- System.out.println("Saved Type: " + type);
- }
- @Override
- public Packet getDescriptionPacket() {
- NBTTagCompound nbt = new NBTTagCompound();
- nbt.setString("type", type);
- nbt.setFloat("size", size);
- return new Packet132TileEntityData(xCoord, yCoord, zCoord, 0, nbt);
- }
- @Override
- public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) {
- this.type = pkt.customParam1.getString("type");
- this.size = pkt.customParam1.getFloat("size");
- super.onDataPacket(net, pkt);
- }
- }
- GUI - Relevant parts being on GUI close.
- -----------------------------------------------------------------------------------------------------
- package net.minecraft.src;
- import java.lang.reflect.Field;
- import java.lang.reflect.Modifier;
- import java.util.Iterator;
- import java.util.Map;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.GuiScreen;
- import net.minecraft.client.multiplayer.NetClientHandler;
- import net.minecraft.entity.EntityList;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.packet.Packet130UpdateSign;
- import net.minecraft.world.World;
- public class GenuineGuiTrophySilver extends GuiScreen {
- private static boolean init;
- private static void generateEntityList() {
- Field field = EntityList.class.getDeclaredFields()[1];
- field.setAccessible(true);
- Map map = null;
- try {
- map = (Map) field.get(null);
- }
- catch (Exception exception) {
- exception.printStackTrace();
- }
- if (map != null) {
- Iterator iterator = map.keySet().iterator();
- while (iterator.hasNext()) {
- Class class1 = (Class) iterator.next();
- try {
- if (EntityLiving.class.isAssignableFrom(class1) && class1.getConstructor(new Class[] { World.class }) != null && !Modifier.isAbstract(class1.getModifiers())) {
- String s = (String) map.get(class1);
- if (!mod_GenuineTrophy.trophyListContains(s))
- mod_GenuineTrophy.registerTrophy(s);
- }
- }
- catch (SecurityException securityexception) {}
- catch (NoSuchMethodException nosuchmethodexception) {}
- }
- }
- GenuineGuiTrophySilver.init = true;
- }
- private GenuineTileEntityTrophySilver trophy;
- private EntityPlayer player;
- private int pageMax;
- private int pageCurrent;
- public GenuineGuiTrophySilver(GenuineTileEntityTrophySilver tileEntitySilver, EntityPlayer entityPlayer) {
- this.trophy = tileEntitySilver;
- this.player = entityPlayer;
- this.pageMax = 1;
- this.pageCurrent = 1;
- }
- @Override
- public void onGuiClosed() {
- NetClientHandler var1 = this.mc.getSendQueue();
- if (var1 != null)
- var1.addToSendQueue(this.trophy.getDescriptionPacket());
- super.onGuiClosed();
- }
- @Override
- protected void actionPerformed(GuiButton guibutton) {
- boolean flag = guibutton.enabled;
- if (this.trophy == null || !flag)
- return;
- if (guibutton.id == 0 || guibutton.id == 1) {
- if (guibutton.id == 0)
- this.pageCurrent--;
- if (guibutton.id == 1)
- this.pageCurrent++;
- for (int k = 0; k < this.controlList.size() - 2; k++)
- ((GuiButton) this.controlList.get(k + 2)).drawButton = false;
- for (int k = 32 * (this.pageCurrent - 1); k < 32 * this.pageCurrent; k++)
- if (k < this.controlList.size() - 2)
- ((GuiButton) this.controlList.get(k + 2)).drawButton = true;
- } else {
- this.trophy.type = guibutton.displayString.equalsIgnoreCase("Human") ? "Monster" : guibutton.displayString;
- this.trophy.size = 0.5F;
- this.mc.displayGuiScreen(null);
- this.mc.setIngameFocus();
- ModLoader.openGUI(this.player, new GenuineGuiTrophySilverOptions(this.trophy));
- }
- }
- @Override
- public void drawScreen(int i, int j, float f) {
- this.drawDefaultBackground();
- this.drawCenteredString(this.fontRenderer, "Select which mob to display.", this.width / 2, this.height / 8 - 20, 0xffffff);
- this.drawCenteredString(this.fontRenderer, "Page: " + this.pageCurrent + "/" + this.pageMax, this.width / 2, this.height / 8 + 185, 0xffffff);
- super.drawScreen(i, j, f);
- }
- @Override
- public void initGui() {
- if (!GenuineGuiTrophySilver.init)
- GenuineGuiTrophySilver.generateEntityList();
- this.controlList.add(new GuiButton(0, this.width / 2 - 120, this.height / 8 + 180, 75, 20, "Prev"));
- this.controlList.add(new GuiButton(1, this.width / 2 + 50, this.height / 8 + 180, 75, 20, "Next"));
- int npcInt = 0;
- for (int k = 0; k < mod_GenuineTrophy.getTrophyListSize() - npcInt; k++) {
- String s = mod_GenuineTrophy.getTrophy(k);
- GuiButton temp = new GuiButton(k + 2, this.width / 2 - 178 + k % 4 * 90, this.height / 8 + 22 * ((k >> 2) % 8), 88, 20, s);
- if (k > 31)
- temp.drawButton = false;
- this.controlList.add(temp);
- }
- this.pageMax = (int) Math.floor((this.controlList.size() - 3) / 32F) + 1;
- if (this.pageMax == 1)
- ((GuiButton) this.controlList.get(0)).enabled = ((GuiButton) this.controlList.get(1)).enabled = false;
- }
- @Override
- public void updateScreen() {
- if (this.pageCurrent <= 1)
- ((GuiButton) this.controlList.get(0)).enabled = false;
- else
- ((GuiButton) this.controlList.get(0)).enabled = true;
- if (this.pageCurrent >= this.pageMax)
- ((GuiButton) this.controlList.get(1)).enabled = false;
- else
- ((GuiButton) this.controlList.get(1)).enabled = true;
- super.updateScreen();
- }
- }
Advertisement