Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

kris91268

Members
  • Posts

    57
  • Joined

  • Last visited

Everything posted by kris91268

  1. Hello reader, I am trying to have a block with a TileEntitySpecialRenderer and a block model have animated textures. The workaround so far that I have is to change the texture every 5 times the method is called in the TileEntitySpecialRenderer implemented class, but this causes some strange behaviours. If I look at the blocks on a more acute angle, the textures seem to speed up really fast compared to when the player stares at it directly. It also does not stop when the game is paused. Because of this, I am wandering if there is another way to have block animations with blocks that have models than what I have already got. If there is no other way, does anyone know any OpenGL code to make the block render more correctly (uniform speed no matter what angle)? An example of my workaround is below: TileEntityLightBridgeSectionRenderer.java The reference to LightTextures.bridgeTextures is simply an array of ResourceLocations for the texture for every frame. Any help is much appreciated
  2. The suggested changes still do not work in the link you provided me, but thank you.
  3. Hello, I have a gravity lift block, which repels you upwards from a certain set height, however I am having problems with that height not saving. When the GUI is closed, it calls a method directly in the tile entity class to set the height for which the gravity lift would propel you upwards. It does work, but does not save. I know you must use packets for this, but I have not been able to find a tutorial that teaches what I need - all of the packet tutorials are not for 1.7.2. I have posted a topic on the Forge Forums a while back about the same issue, but that was for MC 1.6, so it is outdated. Any help with ways of solving this would be much appreciated! Plus any links to tutorials that have exactly what I need. Code: TileEntityGravityLift.java GuiGravityLift.java
  4. Thank you, that helped lots. It now works fine without that error.
  5. From what I have seen, it appears to compile automatically. My compiled files are in the bin folder where my ForgeGradle workspace is set up. Is this way not the correct way to do this?
  6. I am having the following problem with my mod. When I launch it, I get the following error: java.lang.NoSuchFieldError: iron at at kris91268.lbd.Blocks.BlockLightBridgeSource.<init>(BlockLightBridgeSource.java:37) ...rest ommited... This only appears to happen when launching my mod with the normal Minecraft launcher; it does not happen in my mod development environment (ForgeGradle) Snippet of BlockLightBridgeSource.java where the error comes from: public BlockLightBridgeSource() { super(Material.iron); // this is where the error originates. setHardness(1.5F); setResistance(6.0F); setStepSound(Block.soundTypeMetal); setBlockName("lightBridgeSource"); setBlockTextureName("lbd:lightBridgeSource"); setCreativeTab(CreativeTabs.tabRedstone); } Any help is much appreciated! -kris91268
  7. WorldSavedData does not have anything that I need, I had a look. Plus it is an abstract class, so I cannot declare a new object from it. And when you say "Don't reinvent the wheel", what exactly do you mean? I know what you physically mean by it, but how am I 'starting from scratch'?
  8. I've used both Scotty's, and GotoLink's suggestions with how I should do this. I've added an if else statement that sets the value to a string depending on what type of world it is in, here it is below if (!world.isRemote) { worldname = world.getWorldInfo().getWorldName(); } else { worldname = ModLoader.getMinecraftServerInstance().getFolderName(); } I know ModLoader is not ideal, but is the best option avaliable. It works fine clientside, but in a server, it crashes with a FileNotFound exception because it reads from the default saves folder in the .minecraft directory, but that is not where the server holds it's world files. Is there any way for getting the name of the directory for the worlds that the server uses?
  9. That gets the name of the dimension, I do not need that, I need the name of the world that you set when you name your world on creation so I can save a file for each individual world in the saves folder.
  10. Then how does Minecraft know which world you are in, so it can save the contents of the world to the disc under the saves folder? Because I need to save an additional file in there, but I do not know how to detect the name of the world that the player sets on creation.
  11. Yes it does, but it sometimes says that the world is name MpServer or something like that, when I am playing singleplayer. So then my program breaks. How would I stop this MpServer coming before it returns the proper world name?
  12. Hello, I am writing a new save system for my mod and I am just trying to find out how do you get the name of the world that the current player is logged into? By name, I mean the name that you set when you create a new world or rename one. Also, is the variable of the name of the world accessible through the EntityPlayer, or the World classes, or if there is another one (Please specify if you do) Thank you in advance for all of those who can help me
  13. Yeah I know, which explains the crash server side, but it does not launch the player clientside too, it launches every other entity but the player clientside.
  14. OK, I have been doing some testing with other entities, and they seem to launch fine, even with different height settings set on the grav lift, its like it seems to work for everything, but the player. Why is this? (I have removed the code about the par5Entity instanceof EntityPlayer, e.t.c and just placed the methods to propel entites in the air).
  15. The gui class contains a method to set if you want your gui to pause the game or not, the method looks like this public boolean doesGuiPauseGame() { return true; } Just copy and paste that method into your gui file and change the value from true to false, and you should be all good.
  16. You are assigning new values to xSize and ySize, remove these new assignments and keep everything else. The reason is because you are assigning a new value to xSize and ySize, which GuiContainer uses these values to find the size of the inventory window in pixels. I recommend removing these assignments, then tell me how it went. Change this public GuiTub(InventoryPlayer invPlayer, CherTub tub) { super(new ContainerTub(invPlayer, tub)); xSize = 176; ySize = 149; } to this public GuiTub(InventoryPlayer invPlayer, CherTub tub) { super(new ContainerTub(invPlayer, tub)); } and remove the new assignments Also where you say, Minecraft.getMinecraft().func_110434_K().func_110577_a( new ResourceLocation("row:textures/gui/gui_tub.png")); you don't need to create another instance, GuiContainer already has an instance of Minecraft, it looks like this this.mc.func_110434_K().func_110577_a(yourtexturefile) But you don't need to do the above if you don't want to, it will just decrease the amount of objects (and code that you have to write) and be much easier, totally up to you to change the above code. If the above methods do not work, I recommend you still remove the new assignments of xSize and ySize, and use the furnace gui texture as your template, just paste over it and remove the furnace bar icons, keep all of the empty space. This worked for me with my gui. Hope I have been of help to you
  17. I think that it has something to do with your for loop, that could be making the wrong numbers that represent the metadata that you require. Try removing it and declearing each recipe individually (I know, it's a pain to do), that is what i have in a previous mod that I made, and that worked.
  18. Forge has a coremods folder in the .minecraft directory. I'm pretty sure your mod should go in there. In your main post, you stated that you placed the mod in the mods folder.
  19. I have been doing some work and following the Packet handling tutorial again, and I have successfully sended a packet to the tile entity, and it writes to it's nbt. That is all solved. However, when I collide with the block, it doesn't get the set height for the specific tile entity. How would I retrieve this for use in the block class. Here is the changed files GuiGravityLift.java package kris91268.lbd; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import kris91268.lbd.Blocks.BlockGravityLift; import kris91268.lbd.Packet.PacketBlockChange; import kris91268.lbd.Tileentity.TileEntityGravityLift; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; /** * * @author Arbiter * */ public class GuiGravityLift extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation("lbd:textures/gui/gravlift.png"); private GuiButton dnButton; private GuiButton decByPointZeroOne; private GuiButton decByPointOne; private GuiButton incByPointOne; private GuiButton incByOnePointZero; private GuiTextField number; public static String gravLiftHeight; private TileEntityGravityLift tileEntity; public EntityPlayer player; public GuiGravityLift(InventoryPlayer par1, TileEntityGravityLift par2, EntityPlayer player) { super(new ContainerGravityLift(par1, par2)); tileEntity = par2; this.player = player; } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { fontRenderer.drawString("Gravity Lift", 8, 6, 4210752); fontRenderer.drawString("Inventory", 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { this.mc.func_110434_K().func_110577_a(texture); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); this.number.drawTextBox(); } @Override public void initGui() { super.initGui(); Keyboard.enableRepeatEvents(true); this.buttonList.add(this.dnButton = new GuiButton(0, this.width / 2 - 25, this.height / 4 + 35, 50, 20, "Done")); this.buttonList.add(this.decByPointZeroOne = new GuiButton(1, this.width / 2 - 75, this.height / 4 + 0, 40, 20, "-0.1")); this.buttonList.add(this.decByPointOne = new GuiButton(2, this.width / 2 - 75, this.height / 4 + 25, 40, 20, "-1.0")); this.buttonList.add(this.incByPointOne = new GuiButton(3, this.width / 2 + 25, this.height / 4 + 0, 40, 20, "+0.1")); this.buttonList.add(this.incByOnePointZero = new GuiButton(4, this.width / 2 + 25, this.height / 4 + 25, 40, 20, "+1.0")); this.number = new GuiTextField(this.fontRenderer, this.width / 2 - 20, this.height / 4 + 1, 40, 20); this.number.setVisible(true); this.number.setCanLoseFocus(false); this.number.setFocused(true); this.number.setText(tileEntity.height.toString()); gravLiftHeight = tileEntity.height.toString(); } public void onGuiClosed() { Keyboard.enableRepeatEvents(false); Double theNumber = Double.parseDouble(gravLiftHeight); } public boolean isAboveZero(String par1Str) { Double theDouble = Double.parseDouble(par1Str); return theDouble >= 0.00 ? true : false; } public boolean isBelowFive(String par1Str) { Double theDouble = Double.parseDouble(par1Str); return theDouble <= 5.00 ? true : false; } public void updateScreen() { this.number.updateCursorCounter(); } /** public void mouseClicked(int par1, int par2, int par3) { super.mouseClicked(par1, par2, par3); this.number.mouseClicked(par1, par2, par3); } public void keyTyped(char par1, int par2) { this.number.textboxKeyTyped(par1, par2); ((GuiButton)this.buttonList.get(0)).enabled = this.number.getText().trim().length() > 0; if (par2 == 28 || par2 == 156) { this.actionPerformed((GuiButton)this.buttonList.get(0)); } }**/ @Override protected void actionPerformed(GuiButton guiButton) { int x = tileEntity.xCoord; int y = tileEntity.yCoord; int z = tileEntity.zCoord; switch (guiButton.id) { case 0: this.mc.displayGuiScreen((GuiScreen)null); break; case 1: Double heightInDoubles = Double.parseDouble(gravLiftHeight); if (heightInDoubles != 0.0) { heightInDoubles -= 0.1; } gravLiftHeight = heightInDoubles.toString(); number.setText(gravLiftHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(heightInDoubles, tileEntity, x, y, z).makePacket()); break; case 2: Double heightInDoubles1 = Double.parseDouble(gravLiftHeight); if (heightInDoubles1 < 1.0) { heightInDoubles1 = 0.0; } else { heightInDoubles1 -= 1.0; } gravLiftHeight = heightInDoubles1.toString(); number.setText(gravLiftHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(heightInDoubles1, tileEntity, x, y, z).makePacket()); break; case 3: Double theHeight = Double.parseDouble(gravLiftHeight); if (theHeight != 5.0) { theHeight += 0.1; } gravLiftHeight = theHeight.toString(); number.setText(gravLiftHeight); tileEntity.bindHeightToTileEntity(theHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(theHeight, tileEntity, x, y, z).makePacket()); break; case 4: Double theNumber = Double.parseDouble(gravLiftHeight); if (theNumber > 4.0) { theNumber = 5.0; } else { theNumber += 1.0; } gravLiftHeight = theNumber.toString(); number.setText(gravLiftHeight); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(; DataOutputStream dataStream = new DataOutputStream(outputStream); try { dataStream.writeDouble(theNumber); dataStream.writeInt(tileEntity.xCoord); dataStream.writeInt(tileEntity.yCoord); dataStream.writeInt(tileEntity.zCoord); } catch (Exception e) { e.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "lbd"; packet.data = outputStream.toByteArray(); packet.length = outputStream.size(); Side side = FMLCommonHandler.instance().getEffectiveSide(); if (side == Side.SERVER) { EntityPlayerMP playerMP = (EntityPlayerMP)player; } else if (side == Side.CLIENT) { EntityClientPlayerMP clientPlayer = (EntityClientPlayerMP)player; clientPlayer.sendQueue.addToSendQueue(packet); } default: break; } } } GuiGravityLiftHandler.java package kris91268.lbd; import kris91268.lbd.Tileentity.TileEntityGravityLift; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; /** * * @author Arbiter * */ public class GuiGravLiftHandler implements IGuiHandler { @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntityGravityLift tileEntity = (TileEntityGravityLift)world.getBlockTileEntity(x, y, z); return new ContainerGravityLift(player.inventory, tileEntity); } @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); return tileEntity instanceof TileEntityGravityLift ? new GuiGravityLift(player.inventory, (TileEntityGravityLift)tileEntity, player) : null; } } TileEntityGravityLift.java package kris91268.lbd.Tileentity; import java.awt.List; import kris91268.lbd.Blocks.BlockGravityLift; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; /** * * @author Arbiter * */ public class TileEntityGravityLift extends TileEntity implements IInventory { private String aString; public Double height = new Double(0.0D); public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); height = par1NBTTagCompound.getDouble("height"); System.out.println(height); } public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); par1NBTTagCompound.setDouble("height", height); System.out.println(height); } public boolean isUsableByPlayer(EntityPlayer par1EntityPlayer) { return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } public void something(String par1Str) { this.aString = par1Str; } @Override public String getInvName() { return "Gravity Lift"; } public void bindHeightToTileEntity(double theHeight) { this.height = theHeight; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } public double getHeightLevel() { return height; } public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 3, nbt); } @Override public int getSizeInventory() { return 0; } @Override public ItemStack getStackInSlot(int i) { return null; } @Override public ItemStack decrStackSize(int i, int j) { return null; } @Override public ItemStack getStackInSlotOnClosing(int i) { return null; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { } @Override public boolean isInvNameLocalized() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { return true; } @Override public void openChest() { } @Override public void closeChest() { } @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { return false; } } BlockGravityLift.jaca package kris91268.lbd.Blocks; import java.util.Random; import kris91268.lbd.GuiGravityLift; import kris91268.lbd.ModLBD; import kris91268.lbd.Tileentity.TileEntityGravityLift; import cpw.mods.fml.common.registry.BlockProxy; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; /** * * @author Arbiter * */ public class BlockGravityLift extends BlockContainer implements BlockProxy { public Class theTileEntityClass; public BlockGravityLift(int par1, Class<? extends TileEntity> entityClass) { super(par1, Material.iron); theTileEntityClass = entityClass; setHardness(1.5F); setResistance(1.0F); setStepSound(Block.soundMetalFootstep); setUnlocalizedName("lbd:gravityLift"); func_111022_d("lbd:gravityLift"); setCreativeTab(CreativeTabs.tabRedstone); setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3F, 1.0F); } public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) { par5Entity.fallDistance = 0.0F; TileEntityGravityLift tileEntity = (TileEntityGravityLift)par1World.getBlockTileEntity(par2, par3, par4); double height = tileEntity.getHeightLevel(); if (height <= 0.0D) { return; } if (par1World.isRemote) { if (par5Entity instanceof EntityPlayer) { par5Entity.setVelocity(0.0D, height / 2, 0.0D); par5Entity.moveEntity(0.0D, height, 0.0D); } } else { if (par5Entity instanceof EntityPlayerMP) { par5Entity.addVelocity(0.0D, height / 2, 0.0D); par5Entity.moveEntity(0.0D, height, 0.0D); } } } @Override public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); par1World.setBlockTileEntity(par2, par3, par4, new TileEntityGravityLift()); } public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer player, int metadata, float par7, float par8, float par9) { if (!par1World.isRemote) { TileEntityGravityLift tileEntity = (TileEntityGravityLift)par1World.getBlockTileEntity(par2, par3, par4); if (tileEntity != null) { player.openGui(ModLBD.instance, 0, par1World, par2, par3, par4); } } return true; } public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { double d0 = (double)((float)par2 + 0.5F); double d1 = (double)((float)par3 + 0.3F); double d2 = (double)((float)par4 + 0.5F); par1World.spawnParticle("portal", d0, d1, d2, 0.0D, 0.0D, 0.0D); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public int getRenderType() { return -1; } @Override public boolean hasTileEntity(int par1) { return true; } public TileEntity createNewTileEntity(World par1World) { try { return new TileEntityGravityLift(); } catch (Exception e) { System.out.println("Error creating a new tile entity"); return null; } } } PacketHandler.java package kris91268.lbd.Packet; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.util.logging.Logger; import kris91268.lbd.Packet.PacketBase.ProtocolException; import kris91268.lbd.Tileentity.TileEntityGravityLift; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; import cpw.mods.fml.relauncher.Side; /** * * @author Arbiter * */ public class PacketHandler implements IPacketHandler { @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { if (packet.channel.equals("lbd")) { handleHeight(packet, player); } } private void handleHeight(Packet250CustomPayload packet, Player player) { DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data)); double height; int x; int y; int z; try { height = inputStream.readDouble(); x = inputStream.readInt(); y = inputStream.readInt(); z = inputStream.readInt(); } catch (IOException e) { e.printStackTrace(); return; } EntityPlayer entityPlayer = (EntityPlayer)player; TileEntityGravityLift tileEntity = (TileEntityGravityLift)entityPlayer.worldObj.getBlockTileEntity(x, y, z); tileEntity.bindHeightToTileEntity(height); } }
  20. So how do you guys suggest how I send the packet, all of the packet stuff is done, just need somewhere to send it.
  21. In that case, what do you think I should do? How do you propose I implement the packet sending code. Here is the files that I have changed GuiGravityLift.java package kris91268.lbd; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.network.PacketDispatcher; import kris91268.lbd.Blocks.BlockGravityLift; import kris91268.lbd.Packet.PacketBlockChange; import kris91268.lbd.Tileentity.TileEntityGravityLift; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; /** * * @author Arbiter * */ public class GuiGravityLift extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation("lbd:textures/gui/gravlift.png"); private GuiButton dnButton; private GuiButton decByPointZeroOne; private GuiButton decByPointOne; private GuiButton incByPointOne; private GuiButton incByOnePointZero; private GuiTextField number; public static String gravLiftHeight; private TileEntityGravityLift tileEntity; public GuiGravityLift(InventoryPlayer par1, TileEntityGravityLift par2) { super(new ContainerGravityLift(par1, par2)); tileEntity = par2; } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { fontRenderer.drawString("Gravity Lift", 8, 6, 4210752); fontRenderer.drawString("Inventory", 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { this.mc.func_110434_K().func_110577_a(texture); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); this.number.drawTextBox(); } @Override public void initGui() { super.initGui(); Keyboard.enableRepeatEvents(true); this.buttonList.add(this.dnButton = new GuiButton(0, this.width / 2 - 25, this.height / 4 + 35, 50, 20, "Done")); this.buttonList.add(this.decByPointZeroOne = new GuiButton(1, this.width / 2 - 75, this.height / 4 + 0, 40, 20, "-0.1")); this.buttonList.add(this.decByPointOne = new GuiButton(2, this.width / 2 - 75, this.height / 4 + 25, 40, 20, "-1.0")); this.buttonList.add(this.incByPointOne = new GuiButton(3, this.width / 2 + 25, this.height / 4 + 0, 40, 20, "+0.1")); this.buttonList.add(this.incByOnePointZero = new GuiButton(4, this.width / 2 + 25, this.height / 4 + 25, 40, 20, "+1.0")); this.number = new GuiTextField(this.fontRenderer, this.width / 2 - 20, this.height / 4 + 1, 40, 20); this.number.setVisible(true); this.number.setCanLoseFocus(false); this.number.setFocused(true); if (tileEntity.height == null) { tileEntity.height = 0.0D; this.number.setText(tileEntity.height.toString()); gravLiftHeight = tileEntity.height.toString(); } else { this.number.setText(tileEntity.height.toString()); gravLiftHeight = tileEntity.height.toString(); } } public void onGuiClosed() { Keyboard.enableRepeatEvents(false); Double theNumber = Double.parseDouble(gravLiftHeight); tileEntity.bindHeightToTileEntity(theNumber); String s = "gravlift"; ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(out); try { dataOut.writeDouble(theNumber); this.mc.getNetHandler().addToSendQueue(new Packet250CustomPayload(s, out.toByteArray())); this.tileEntity.getDescriptionPacket(); this.tileEntity.bindHeightToTileEntity(theNumber); } catch (Exception e) { e.printStackTrace(); } } public boolean isAboveZero(String par1Str) { Double theDouble = Double.parseDouble(par1Str); return theDouble >= 0.00 ? true : false; } public boolean isBelowFive(String par1Str) { Double theDouble = Double.parseDouble(par1Str); return theDouble <= 5.00 ? true : false; } public void updateScreen() { this.number.updateCursorCounter(); } /** public void mouseClicked(int par1, int par2, int par3) { super.mouseClicked(par1, par2, par3); this.number.mouseClicked(par1, par2, par3); } public void keyTyped(char par1, int par2) { this.number.textboxKeyTyped(par1, par2); ((GuiButton)this.buttonList.get(0)).enabled = this.number.getText().trim().length() > 0; if (par2 == 28 || par2 == 156) { this.actionPerformed((GuiButton)this.buttonList.get(0)); } }**/ @Override protected void actionPerformed(GuiButton guiButton) { int x = tileEntity.xCoord; int y = tileEntity.yCoord; int z = tileEntity.zCoord; switch (guiButton.id) { case 0: this.mc.displayGuiScreen((GuiScreen)null); break; case 1: Double heightInDoubles = Double.parseDouble(gravLiftHeight); if (heightInDoubles != 0.0) { heightInDoubles -= 0.1; } gravLiftHeight = heightInDoubles.toString(); number.setText(gravLiftHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(heightInDoubles, tileEntity, x, y, z).makePacket()); break; case 2: Double heightInDoubles1 = Double.parseDouble(gravLiftHeight); if (heightInDoubles1 < 1.0) { heightInDoubles1 = 0.0; } else { heightInDoubles1 -= 1.0; } gravLiftHeight = heightInDoubles1.toString(); number.setText(gravLiftHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(heightInDoubles1, tileEntity, x, y, z).makePacket()); break; case 3: Double theHeight = Double.parseDouble(gravLiftHeight); if (theHeight != 5.0) { theHeight += 0.1; } gravLiftHeight = theHeight.toString(); number.setText(gravLiftHeight); tileEntity.bindHeightToTileEntity(theHeight); PacketDispatcher.sendPacketToServer(new PacketBlockChange(theHeight, tileEntity, x, y, z).makePacket()); break; case 4: Double theNumber = Double.parseDouble(gravLiftHeight); if (theNumber > 4.0) { theNumber = 5.0; } else { theNumber += 1.0; } gravLiftHeight = theNumber.toString(); number.setText(gravLiftHeight); String s = "gravlift"; ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(out); try { dataOut.writeDouble(theNumber); this.mc.getNetHandler().addToSendQueue(new Packet250CustomPayload(s, out.toByteArray())); tileEntity.getDescriptionPacket(); this.tileEntity.bindHeightToTileEntity(theNumber); } catch (Exception e) { e.printStackTrace(); } default: break; } } } TileEntityGravityLift.java package kris91268.lbd.Tileentity; import java.awt.List; import kris91268.lbd.Blocks.BlockGravityLift; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; /** * * @author Arbiter * */ public class TileEntityGravityLift extends TileEntity implements IInventory { private String aString; public Double height; public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); height = par1NBTTagCompound.getDouble("height"); System.out.println(height); } public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); par1NBTTagCompound.setDouble("height", height); System.out.println(height); } public boolean isUsableByPlayer(EntityPlayer par1EntityPlayer) { return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } public void something(String par1Str) { this.aString = par1Str; } @Override public String getInvName() { return "Gravity Lift"; } public void bindHeightToTileEntity(double theHeight) { this.height = theHeight; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } public double getHeightLevel() { return this.height; } public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 3, nbt); } @Override public int getSizeInventory() { return 0; } @Override public ItemStack getStackInSlot(int i) { return null; } @Override public ItemStack decrStackSize(int i, int j) { return null; } @Override public ItemStack getStackInSlotOnClosing(int i) { return null; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { } @Override public boolean isInvNameLocalized() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { return true; } @Override public void openChest() { } @Override public void closeChest() { } @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { return false; } }
  22. Actually, I found that it is much easier just to use a packet already used in Minecraft, in this case, I use the Packet132TileEntityData packet since that is all I need, and I found it actually saves data. Thanks for the help everyone has given me.
  23. You would need the block class to extend off BlockContainer, and have a tile entity class linked to that block. Follow the Container part of the Containers and GUI's tutorial to see how to make a container for a block, and how to make the resulting gui. I would recommend looking at the Tile Entities tutorials so you understand Tile Entities fully.
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.