Jump to content

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


TheEpicTekkit

Recommended Posts

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

The methods you are interested in are these. That is all you need to draw the fluids.

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/

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So I saw that mixin is shipped as a library with forge, but is it available for 1.7.10 ?  
    • So I've read the EULA, and lets be straight...     If I split my modpack(of my mods, yeah I'm nuts) into several(many) individual mods(like just one boss) with minor additions(plus not working together), then have a complete/modpack version on patreon/onlyfans having each addon work together... Would people buy my idea?
    • German A1 – C1, TestDAF, Goethe B1, B2, C1, C2, valid GOETHE certificate German A1 – C1, TestDAF, Goethe B1, B2, C1, C2, valid GOETHE certificate(+27(838-80-8170
    • Done, it still crashed. New log https://paste.ee/p/kYv6e
    • I am migrating a mod from 1.16.5 to 1.20.2 The version for 1.16.5 can be found here https://github.com/beothorn/automataCraft For the block called automata_start, it uses TileEntities and has blockstates, model/block and textures on json files. This is currently working fine on 1.16.5 https://github.com/beothorn/automataCraft/tree/master/src/main/resources/assets/automata For 1.20.2 I migrated the logic from TileEntities to BlockEntity. The mod is working fine. All blocks and Items are working with the correct textures except for the textures for each state of the automata_start block. No changes where made to the json files. This is the branch I am working on (there were some refactorings, but all is basically the same): https://github.com/beothorn/automataCraft/tree/1_20/src/main/resources/assets/automata The only difference I can think that may be related is that i had to implement createBlockStateDefinition on the BaseEntityBlock: https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L43 This is driving me crazy. I know the jsons are being loaded as I put a breakpoint at `net.minecraft.client.resources.model.ModelBakery#loadModel` and I can see BlockModelDefinition.fromJsonElement being called with automata_start. I also printed the state from the arguments of the tick function call and they look correct (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/Ticker.java#L32 ): blockState Block{automata:automata_start}[state=loadreplaceables] In game, all I see is the no textures. I think it is weird it is not the "missing texture" texture so I think it may be related to the material, but I had no success tweaking it (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L37).   public static final Property<AutomataStartState> state = EnumProperty.create("state", AutomataStartState.class); private final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType; private final Map<String, RegistryObject<Block>> registeredBlocks; public AutomataStartBlock( final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType, final Map<String, RegistryObject<Block>> registeredBlocks ) { super(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.5F, 6.0F)); this.blockEntityType = blockEntityType; this.registeredBlocks = registeredBlocks; this.registerDefaultState(this.getStateDefinition().any().setValue(state, AutomataStartState.LOAD_REPLACEABLES)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateBuilder) { stateBuilder.add(state); }     So my cry for help is, anyone has any ideas? Is there a way to easily debug this, for example somewhere where I can list the textures for a given state, or make sure this is loaded?   Thanks in advance for the hints
  • Topics

×
×
  • Create New...

Important Information

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