zlappedx3 Posted July 22, 2016 Share Posted July 22, 2016 i need change tileentity to entity @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){ if(ID == 0){ TileEntityChestShop tileEntityChestShop = (TileEntityChestShop) world.getTileEntity(x, y, z); return new GuiChestShop(player.inventory, tileEntityChestShop); } } how to do it ? Quote Link to comment Share on other sites More sharing options...
feldim2425 Posted July 22, 2016 Share Posted July 22, 2016 I don't know if thats a good solution but the way I do it, I give the Y argument a negative number when calling the player.openGui(...) so the Y value in getClientGuiElement() is also negative. (TE's & Blocks should not exist at a negative Y Coordinate) So the X can be set to entity.getEntityId(). And you can get the Entity Object back by calling world.getEntityByID(x) @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(y==-10 && ID == 0){ Entity entity = world.getEntityByID(x); if(entity!=null){ return new EntityGuiContainer(entity) } } return null; } Open with: player.openGui(Mod.instance, 0, world, entity.getEntityId(), -10 , 0); Quote Link to comment Share on other sites More sharing options...
coolAlias Posted July 22, 2016 Share Posted July 22, 2016 I pass the entity ID as the 'x' parameter and know based on the GUI ID that it is an Entity and not a TileEntity. switch (id) { case 0: // you set the IDs, so you know what this GUI expects e.g. TileEntity return whatever; case 1: // oh, this is my Entity-based GUI Entity e = world.getEntityByID(x); return new Whatever(e); } Not that passing some random magic-value number via 'y' as a flag is bad, just unnecessary in most cases. If you do find that you need it e.g. you have a GUI that could take either a TileEntity OR an Entity and you won't know which in the IGuiHandler, then you should make a constant e.g. public static final int ENTITY_FLAG = -10 so your code is more readable and more easily maintained. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
zlappedx3 Posted July 22, 2016 Author Share Posted July 22, 2016 OK now i can do it. but now have new problem. i create List<Integer> in entity. public List<Integer> Position = new ArrayList<Integer>(); and i will use open gui by this. player.openGui(Main.Instance, 1, this.worldObj, 0, this.getEntityId(), 0); next i will use gui for open Position.get(0) @Override protected void drawGuiContainerForegroundLayer(int par1, int par2){ this.fontRendererObj.drawString("" + entityMerchant.Position.get(0), this.xSize /2 - 10, this.ySize /2 - 95, 0x000000); } but it error. this it GuiHandler. @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){ if(ID == 0){ Entity entity = world.getEntityByID(y); if(x == 0 && entity!=null && z == 0){ return new GuiMerchant((EntityMerchant)entity); } } } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0){ TileEntityChestShop tileChestShop = (TileEntityChestShop) world.getTileEntity(x, y, z); return new ContainerChestShop(player.inventory, tileChestShop); } } Quote Link to comment Share on other sites More sharing options...
zlappedx3 Posted July 22, 2016 Author Share Posted July 22, 2016 I think you know, but pretend idiot. Quote Link to comment Share on other sites More sharing options...
zlappedx3 Posted July 22, 2016 Author Share Posted July 22, 2016 I'm not good at English but will try explain you for understand. this is entity. public class EntityMerchant extends EntityMob { public List<Integer> Position = new ArrayList<Integer>(); public EntityMerchant(World par1World) { super(par1World); } @Override public void readEntityFromNBT(NBTTagCompound p_70037_1_){ super.readEntityFromNBT(p_70037_1_); NBTTagList tagList = p_70037_1_.getTagList("iPosition", Constants.NBT.TAG_COMPOUND); for(int i = 0; i < tagList.tagCount(); i++){ NBTTagCompound tag = tagList.getCompoundTagAt(i); int x = tag.getInteger("Position"); Position.add(i, x); } } @Override public void writeEntityToNBT(NBTTagCompound p_70014_1_){ super.writeEntityToNBT(p_70014_1_); NBTTagList tagList = new NBTTagList(); for(int i = 0; i < Position.size(); i++){ int x = Position.get(i); NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("Position", x); tagList.appendTag(tag); } p_70014_1_.setTag("iPosition", tagList); } @Override public IEntityLivingData onSpawnWithEgg(IEntityLivingData data){ data = super.onSpawnWithEgg(data); return data; } public boolean isAIEnabled(){ return true; } protected boolean canDespawn(){ return false; } @Override public boolean interact(EntityPlayer player){ if(this.worldObj.isRemote) player.openGui(Moba.Instance, 1, this.worldObj, 0, this.getEntityId(), 0); return super.interact(player); } } this is guihandler. public class GuiHandler implements IGuiHandler{ @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){ if(ID == 1){ EntityMerchant entity = (EntityMerchant)world.getEntityByID(y); if(x == 0 && entity!=null && z == 0){ return new GuiMerchant(entity); } } return null; } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 1){ EntityMerchant entity = (EntityMerchant)world.getEntityByID(y); if(x == 0 && entity!=null && z == 0){ return new ContainerMerchant(entity); } } return null; } } this is gui. @SideOnly(Side.CLIENT) public class GuiMerchant extends GuiContainer{ private EntityMerchant entityMerchant; public GuiMerchant(EntityMerchant tileEntity){ super(new ContainerMerchant(tileEntity)); this.entityMerchant = tileEntity; } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2){ this.fontRendererObj.drawString("" + this.entityMerchant.Position.get(0), this.xSize /2 - 10, this.ySize /2 - 95, 0x000000); } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(new ResourceLocation("onermod:" + "textures/gui/shop_merchant.png")); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l - 20, 0, 0 , this.xSize + 70, this.ySize + 30); } @Override public void initGui(){ super.initGui(); } @Override protected void actionPerformed(GuiButton button){ switch(button.id){ case 0: } super.actionPerformed(button); } } and this is container public class ContainerMerchant extends Container{ private EntityMerchant tileChestShop; public ContainerMerchant(EntityMerchant tileChestShop){ this.tileChestShop = tileChestShop; } @Override public boolean canInteractWith(EntityPlayer player){ return true; } } Lua from I right click EntityMerchant for Open gui. but this.entityMerchant.Position.get(0) can't use in gui client @Override protected void drawGuiContainerForegroundLayer(int par1, int par2){ this.fontRendererObj.drawString("" + this.entityMerchant.Position.get(0), this.xSize /2 - 10, this.ySize /2 - 95, 0x000000); } I hope you understand this. Quote Link to comment Share on other sites More sharing options...
Ernio Posted July 22, 2016 Share Posted July 22, 2016 As far as I understand - the List you are talking about is not synced (present on server, null/empty on client)? You will need packets for that. Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
coolAlias Posted July 22, 2016 Share Posted July 22, 2016 If you're only using it for the TileEntity's position on the client, that information is already embedded in the TileEntity class - no need for a separate List<Integer> to store it: int posX = this.entityMerchant.xCoord; // same for yCoord and zCoord If that's NOT what you are using the List<Integer> for, then as diesieben asked, what are you using it for??? Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
zlappedx3 Posted July 23, 2016 Author Share Posted July 23, 2016 As far as I understand - the List you are talking about is not synced (present on server, null/empty on client)? You will need packets for that. Yeah Thx u Quote Link to comment Share on other sites More sharing options...
zlappedx3 Posted July 23, 2016 Author Share Posted July 23, 2016 Request permission to post it this is not about java. Micosava hua kuy. Quote Link to comment Share on other sites More sharing options...
Ernio Posted July 23, 2016 Share Posted July 23, 2016 As far as I understand - the List you are talking about is not synced (present on server, null/empty on client)? You will need packets for that. Yeah Thx u Np. - do you need any help there (you haven't stated it)? Request permission to post it this is not about java. Micosava hua kuy. I have no clue what you are trying to say. Was that the mentioned "call for help"? Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.