Posted June 14, 201411 yr Hello, I m doing my first mod and i wanna to make a block which use water. In gui i want see how many water are in this block. So, this is my tile entity of my block public class StrikingMachineTileEntity extends TileEntity implements ISidedInventory, IFluidHandler { public class Tank extends GenericFluidTank{ public Tank(int capacity) { super(capacity); } @Override public boolean canAccept(FluidStack fluid){ switch(fluid.fluidID) { case 1: return true; default: return false; } } } public Tank tank; ... @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { return tank.fill(resource, doFill); } @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tank.drain(resource, doDrain); } @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { return tank.drain(maxDrain, doDrain); } @Override public boolean canFill(ForgeDirection from, Fluid fluid) { return true; } @Override public boolean canDrain(ForgeDirection from, Fluid fluid) { return true; } @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { return new FluidTankInfo[]{tank.getInfo()}; } public int getFluidAmount(){ return tank.getFluidAmount(); } public FluidStack getFluid() { return tank.getFluid(); } public int getCapacity(){ return tank.getCapacity(); } } Now this is my class for my tnak public class GenericFluidTank implements IFluidTank{ private FluidStack fluid; private boolean changeType; private int capacity; public GenericFluidTank(FluidStack type, int capacity) { if(type == null) { fluid = new FluidStack(0, 0); this.changeType = true; } else fluid = FluidUtils.copy(type, 0); this.capacity = capacity; } public GenericFluidTank(int capacity){ this(null, capacity); } @Override public int getCapacity(){ return capacity; } @Override public FluidStack getFluid() { return fluid.copy(); } @Override public FluidTankInfo getInfo() { return new FluidTankInfo(this); } @Override public int fill(FluidStack resource, boolean doFill) { if(resource == null || resource.fluidID < 0){ return 0; } if(!canAccept(resource)){ return 0; } Console.println("Fluid amout before : " +this.getFluidAmount()); int tofill = Math.min(getCapacity()-this.fluid.amount, resource.amount); if(doFill && tofill > 0) { if(!this.fluid.isFluidEqual(resource)){ this.fluid = copy(resource, fluid.amount+tofill); }else{ this.fluid.amount+=tofill; } onLiquidChanged(); } Console.println("Fluid amout after : " +this.getFluidAmount()); return tofill; } @Override public FluidStack drain(int maxDrain, boolean doDrain) { if(fluid.amount == 0 || maxDrain <= 0) return null; int todrain = Math.min(maxDrain, fluid.amount); if(doDrain && todrain > 0) { fluid.amount-=todrain; onLiquidChanged(); } return FluidUtils.copy(fluid, todrain); } public FluidStack drain(FluidStack resource, boolean doDrain) { if (resource == null || !resource.isFluidEqual(fluid)) return null; return drain(resource.amount, doDrain); } public void onLiquidChanged() { } public boolean canAccept(FluidStack type){ return type == null || type.fluidID <= 0 || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type); } public static FluidStack copy(FluidStack liquid, int quantity) { liquid = liquid.copy(); liquid.amount = quantity; return liquid; } public NBTTagCompound toTag() { return FluidUtils.write(fluid, new NBTTagCompound()); } public void fromTag(NBTTagCompound tag) { fluid = FluidUtils.read(tag); } @Override public int getFluidAmount() { return this.fluid.amount; } } And now my class for my gui @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { // TODO Auto-generated method stub GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(background); int var5 = (this.width - this.xSize) / 2; int var6 = (this.height - this.ySize) / 2; this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize); // Progress Bar int x = (this.width - this.xSize) / 2; int y = (this.height - this.ySize) / 2; double ratioPixelBar = (double) 112/tileEntity.getCapacity(); int stored = tileEntity.tank.getFluidAmount(); Console.println("Fluid amount for gui :" +stored); //int stored = (int)(tileEntity.( ) *ratioPixelBar); //int stored = 0; this.drawTexturedModalRect(x + 32, y + 24, 0, 166, stored, 7); } Well, now i ll show you the output So when i don't open the machine block, we can see the fluid amount up 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 0 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 0 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 0 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 90 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 90 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 90 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 90 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 180 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 180 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 180 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 180 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout after : 268 2014-06-14 14:44:11 [iNFOS] [sTDOUT] Fluid amout before : 268 ... 2014-06-14 14:44:34 [iNFOS] [sTDOUT] Fluid amout after : 12000 2014-06-14 14:44:34 [iNFOS] [sTDOUT] Fluid amout before : 12000 I get the fluidamount by the function in my GenericTankFluid (getFluidAmount); But the probleme is when i open the gui 2014-06-14 14:44:42 [iNFOS] [sTDOUT] Fluid amount for gui :0 Somebody can tell me where my fluid is gone? i don't realy understand why i don't get the good value. While i open the gui, i can already see this line 2014-06-14 14:44:42 [iNFOS] [sTDOUT] Fluid amount for gui :0 2014-06-14 14:44:42 [iNFOS] [sTDOUT] Fluid amout before : 12000 2014-06-14 14:44:42 [iNFOS] [sTDOUT] Fluid amout after : 12000 Tanks if people read all my post ^^
June 14, 201411 yr Server/Client syncing issues I would presume. Time for packet handling. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 14, 201411 yr Author I don't understand why i need packet handler. Cause if i set : public int famount = 10000; And in my gui i set my function getFluidAmount from : public int getFluidAmount(){ return tank.getFluidAmount(); } to public int getFluidAmount(){ return famout; } My function return to my gui 10000. So packet handler is needed for my tileentity to get the value of one of his var? That s something strange..?
June 14, 201411 yr All variables in your class will have 2 instances: sevrer, and client side, if you set it manually it will be the same, but all stuff you do (like smelt) are done server side (no cheating), so you need to sync the 2 vars when you change them servervar-->clientvar.
June 14, 201411 yr Author Sorry, i don't resolve my problem. I change this to my function: public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are) { StrikingMachineTileEntity tileEntity = (StrikingMachineTileEntity) world.getBlockTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()){ return false; } ByteArrayOutputStream bos = new ByteArrayOutputStream(; DataOutputStream outputStream = new DataOutputStream(bos); try { outputStream.writeInt(x); outputStream.writeInt(y); outputStream.writeInt(z); } catch (Exception ex) { ex.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = Utilities.CHANNEL; packet.data = bos.toByteArray(); packet.length = bos.size(); player.openGui(Utilities.instance, GUIHandler.GUI_STRINKINGMACHINE, world, x, y, z); return true; } And to update, i make my packet handler and i try to copy the tile entity from the server to the client. @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data)); try{ int x = inputStream.readInt(); int y = inputStream.readInt(); int z = inputStream.readInt(); EntityPlayerMP playerMP = (EntityPlayerMP)player; TileEntity te = playerMP.worldObj.getBlockTileEntity(x, y, z); if(te != null){ if(te instanceof StrikingMachineTileEntity){ StrikingMachineTileEntity tet = (StrikingMachineTileEntity)te; playerMP.worldObj.markBlockForUpdate(x, y, z); } } } catch (IOException e){ e.printStackTrace(); } } But it doesn't work. What's wrong in my code???
June 14, 201411 yr What's wrong with your code? A LOT of things. I would suggest reading the tutorials on the SimpleNetworkWrapper that are in the tutorials section of the modder support forums. But then again, your working with a tile entity and shouldn't need custom packets. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 14, 201411 yr Author I don't see this tutorial. Only tutorial on packetHanlder. I ll search on google
June 14, 201411 yr You're joking right? Because of your incompetence, here is the link. It's the first two tutorials. http://www.minecraftforge.net/forum/index.php/board,120.0.html We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 14, 201411 yr Author i was looking the wiki => http://www.minecraftforge.net/wiki/Category:Tutorial
June 15, 201411 yr I did say MODDER SUPPORT didn't I? Oh well, no matter. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 15, 201411 yr Author SimpleNetworkWrapper work on minecraft forge 1.6.4 or it implements with forge 1.7? My IDE don't know this class, IMessage, IMessageHandler, and method for register a channel
June 15, 201411 yr * blinks in surprise * * looks at title * * facepalms * It's 1.7... Why aren't you using forge1.7.x by the way? Update your forge and then continue from there maybe? We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 15, 201411 yr Author Cause i wanna make mod for minecraft 1.6.4. There is no 1.7.2 mod pack on FTB. So i must make a custom packet to get the tile entity of server and copy it over the tile entity client?
June 15, 201411 yr Yeah, pretty much. Look through this code for how to do packet handling I guess. You should be able to pull what you need from it. https://github.com/ModderPenguin/MinePG/tree/master/source/minepg/rpg_common/rpg We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 20, 201411 yr Author So, i never succeed in doing sync my tile entity in 1.6.4... But in 1.7.2 with the simple network wrapper, i sync my tile entity well. Thanks for your help anyway
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.