Jump to content

Custom fluid tank deleting fluid, or gui not rendering fluid [SOLVED]


Recommended Posts

Posted

So, I have a custom fluid tank, and it seems that it is deleting the fluid when it receives it. Either that, or the gui isnt rendering the fluid correctly. but I think it is the tank deleting the fluid. I am using buildcraft pipes to pump the liquid into the tank.

 

This is my tank methods in the tileentity (very long class, so I am only showing the relevent code)

 

 

        public FluidTank tankInput = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 48);
public FluidTank tankOutput1 = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 12);
public FluidTank tankOutput2 = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 12);
public FluidTank tankOutput3 = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 12);
public FluidTank tankOutput4 = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 12);
public FluidTank tankBiproduct = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * ;


public BlockDistillationChamber blockThis = null;

public String inventoryName;
private ItemStack[] slots = new ItemStack[7];
private FluidStack[] tanks = new FluidStack[6];

public TileEntityDistillationChamberFrame() {

}

//Inventory tank methods

    
    /* IFluidHandler */
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
	return tankInput.drain(maxDrain, doDrain);
}

@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
	if (resource == null) {
		return null;
	} if (tankInput.getFluid() == resource) {
		return tankInput.drain(resource.amount, doDrain);
	}
	return null;
}

@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
	return true;
}

@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
	if (resource == null) {
		return 0;
	}
	return tankInput.fill(resource, doFill);
}

@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
	return true;
}

@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
	return new FluidTankInfo[] { tankInput.getInfo() };
}

public FluidStack getTankInput() {
	return tankInput.getFluid();
}

public float getFluidLevelScaled() {
	float level;
	if (tankInput.getFluid() == null) {
		return 0;
	}
	level = tankInput.getCapacity() / tankInput.getFluid().amount;
	return level;
}

 

 

 

What am I doing wrong?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Your client is desynchronized from the server. Use the getDescriptionPacket and the onDataPacket methods.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

So, does that mean that there isn't a problem with the tileentity fluid methods?

 

I'm pretty sure that that isn't the problem, because when I right click on the block with a bucket, it puts I think 1mB of liquid in it, and renders a weird bar in the gui, this is because I havnt done the gui right, and need to finish it (not sure how to) but my point is that it renders something in the gui when clicked with a bucket, but automation like pipes doesnt, so i think there is a problem with the way the tileentity accepts fluids.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

I think it is. In the onBlockActivated, you are probably not checking for which side it is used on, so it updates both the client and the server. But the buildcraft pipes are probably only putting fluids on the server side, but not on the client side. You need to tell the client what fluids the server has.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Also, im still fairly sure that the tileentity isnt working properly, because like I said before, I can only add 1mB of fluid to the tank, even if I click it with the bucket multiple times, it doesnt add anything.

 

You know, a good way to see if it is working would to have a tooltip telling me what fluid exists in the tank. How would I do a tooltip when the player mouses over the tank?

 

Also, my issue with the texture is fixed. your suggestion worked.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Actually, I think youre right, because I can put 50 universal fluid cells of fluid into the tank, then I can take 50 universal fluid cellls of fluid back out again. Also, after I take everything out with fluid cells, the buildcraft pipes put more in, and I can then take more out with the cells. So I guess it must be the server side client side sync issue. How would I solve this?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Here's some psuedo code:

void writeToNBT(NBTTagCompound)
{
    //call super method
    //write tank to nbt using tank.writeToNBT();
}
void readFromNBT(NBTTagCompound)
{
    //call super method
    //read tank from nbt using tank.readFromNBT();
}
Packet getDescriptionPacket()
{
    NBTTagCompound tag =  new NBTTagCompound();
    writeToNBT(tag);
    return new S35PacketUpdateTileEntity(x,y,z,1,tag);
}
void onDataPacket(NetworkManager, S35PacketUpdateTileEntity)
{
    readFromNBT(packet.func_148857_g());
}

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I don't understand.

 

I know what packets are, and what they are for, but that is about it, I dont know how to set them up (I know I should know this, but I am still new to mc modding and java). So far in my mod, I haven't used them, I haven't even got a PacketHandler. Where would this example code go? Im assuming from the nbt methods, that it would go in the tileentity, (just checking though)

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

That code needs to go into your TileEntity. You don't manually have to send them, Minecraft sends them for you. If you want to manually synchronize the TileEntity, use

worldObj.markBlockForUpdate(xCoord,yCoord,zCoord);

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I think now that the way I am rendering the fluid in the gui is wrong... how am I ment to render fluids in a gui?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

No, the markBlockForUpdate makes Minecraft call the getDescriptionPacket on the server, sends it to the client and calls onDataPacket on the client.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I am not sure if I am rendering fluids correctly in the gui.

 

This is my code so far:

 

 

package net.theepictekkit.generator.client.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.theepictekkit.generator.Reference;
import net.theepictekkit.generator.common.container.ContainerDistillationChamber;
import net.theepictekkit.generator.common.tileentity.TileEntityDistillationChamberFrame;
import net.theepictekkit.generator.utils.RenderUtils;


public class GuiDistillationChamber extends GuiContainer {

private TileEntityDistillationChamberFrame tileEntity;

private final String modid = Reference.MODID;
private final ResourceLocation texture = new ResourceLocation (modid + ":" + "textures/gui/guiDistillationChamber.png");

public GuiDistillationChamber(InventoryPlayer invPlayer, TileEntityDistillationChamberFrame tileEntityDistillationChamberFrame) {
	super(new ContainerDistillationChamber(invPlayer, tileEntityDistillationChamberFrame));

	this.tileEntity = tileEntityDistillationChamberFrame;

	this.xSize = 256; //276
	this.ySize = 183; //183
}

@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {

	fontRendererObj.drawString("Distillation Chamber", 8, 3, 4210752, false);
	fontRendererObj.drawString("Inventory", 8, 90, 4210752, false);

	FluidStack fluidStack = tileEntity.getTankInfo(null)[0].fluid;
	String str = "";

	if (tileEntity.getTankInput() != null && tileEntity.getTankInput().getFluid() != null) {
	str = tileEntity.getTankInput().toString() + ", " + tileEntity.getTankInput().amount;
	} else {
		str = "No fluid stored!";
	}
	fontRendererObj.drawString("Current Fluid Stored: " + str, 180, 100, 0, false);
}

public void drawFluid(FluidStack fluid, int x, int y, int width, int height, int maxCapacity) {
	if (fluid == null || fluid.getFluid() == null) {
		return;
	}
	IIcon icon = fluid.getFluid().getIcon(fluid);
	mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
	RenderUtils.setGLColorFromInt(fluid.getFluid().getColor(fluid));
	int fullX = width / 16;
	int fullY = height / 16;
	int lastX = width - fullX * 16;
	int lastY = height - fullY * 16;
	int level = fluid.amount * height / maxCapacity;
	int fullLvl = (height - level) / 16;
	int lastLvl = (height - level) - fullLvl * 16;
	for (int i = 0; i < fullX; i++) {
		for (int j = 0; j < fullY; j++) {
			if (j >= fullLvl) {
				drawFluidBox(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0);
			}
		}
	}
	for (int i = 0; i < fullX; i++) {
		drawFluidBox(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0);
	}
	for (int i = 0; i < fullY; i++) {
		if (i >= fullLvl) {
			drawFluidBox(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0);
		}
	}
	drawFluidBox(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0);
}

private void drawFluidBox(IIcon icon, int x, int y, int width, int height, int cut) {
	Tessellator tess = Tessellator.instance;
	tess.startDrawingQuads();
	tess.addVertexWithUV(x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height));
	tess.addVertexWithUV(x + width, y + height, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(height));
	tess.addVertexWithUV(x + width, y + cut, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(cut));
	tess.addVertexWithUV(x, y + cut, zLevel, icon.getMinU(), icon.getInterpolatedV(cut));
	tess.draw();
}

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

	float fluidLvl = tileEntity.getFluidLevelScaled();

	//this.drawTexturedModalRect(guiLeft + 15, guiTop + 70, 1, 56, 16, Math.round(fluidLvl) * 56);
	this.drawFluid(tileEntity.getTankInput(), guiLeft + 15, guiTop + 70, 16, 56, tileEntity.tankInput.getCapacity());
}
}

 

 

 

Now, I dont know if this is the correct way to render the fluids, I looked at how buildcraft rendered fluids in the combustune engine to figure out what I have so far, but I don't know if I have missed anything, what they have is spread across several classes. Buildcraft github: https://github.com/BuildCraft/BuildCraft/tree/6.1.x/common/buildcraft/energy

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

You do this

[url=www.google.com]Word you want to be highlighted here![/url]

That's gonna result in this:

Word you want to be highlighted here!

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Here's some psuedo code:

void writeToNBT(NBTTagCompound)
{
    //call super method
    //write tank to nbt using tank.writeToNBT();
}
void readFromNBT(NBTTagCompound)
{
    //call super method
    //read tank from nbt using tank.readFromNBT();
}
Packet getDescriptionPacket()
{
    NBTTagCompound tag =  new NBTTagCompound();
    writeToNBT(tag);
    return new S35PacketUpdateTileEntity(x,y,z,1,tag);
}
void onDataPacket(NetworkManager, S35PacketUpdateTileEntity)
{
    readFromNBT(packet.func_148857_g());
}

 

Where would I put this? in the tileentity? where in the tileentity? anywhere? what do I have to change, I dont understand packets as I said before.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay.... so, I have finally got this fluid drawing in the gui working, now to add multiple tanks... how do I make it so that if I put a certain fluid in a certain tank, it uses up some of that fluid to fill the other 5 tanks each with a different fluid? basically a fluid recipe

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

  • 4 weeks later...
Posted

What if I were to use an A-Star path finding algorithm? Something that actually has tutorials. Currently, this energy grid system has no tutorials. So with A-Star, I could restrict it to the cables. Think this will work?

 

Well... This is awkward. Wrong topic xD I accidently clicked on the wrong faverouts tab as I save my posts to faverouts. This was ment to be in my scanning down a line of blocks topic.

Ignore this.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.