Jump to content

Recommended Posts

Posted

Sorry, but in my other thread, for some reason I cant see any replys after reply 24, I dont know why this happened, but it has also happened to one of my other threads

 

So I have decided to re create the thread (old thread: http://www.minecraftforge.net/forum/index.php/topic,22938.0.html

 

Yes it will. And yes, by direction i mean the ForgeDirection passed, which is the side the block is that inputs the fluid into the tank. If it's a multiblock structure, you can just get the tank from the master, and call the methods in the master TileEntity.

 

What if I wanted a specific block in the structure that I pump into and out of?

 

I want to pump into the master block (on any side) This is the only input for liquid. I then want to have 5 different blocks that can be pumped out of from any side (not 5 of the same block, but 5 different blocks, one for each liquid)

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

Posted

Please post here and not on the old thread, I cant see what you post on the old thread....

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

Posted

In each of the TileEntites of the output blocks, get the masters TileEntity and then the tank you need to get, and cll those methods on that tank. For the input it is almosdt the same.

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... how would I fill out something like these two methods to work with a certain block in the structure?

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

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

 

And this block can be anywhere on the structure, would that cause problems?

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

Posted

Drawing the fluids is the difficult part. Here's some code that you can use (don'tcopy/paste, you won't learn from it then):

 

In the drawGuiContainerBackgroundLayer method:

FluidStack fluid = tileentity.getTankInfo(null)[0].fluid;
        if (fluid != null)
        {
            TextureManager manager = Minecraft.getMinecraft().renderEngine;
            manager.bindTexture(manager.getResourceLocation(0));
            int fluidAmount = (int) (((float) fluid.amount / tileentity.tank.getCapacity()) * 60);
            drawFluid(guiLeft + xSize - 24, guiTop + 8 + 60 - fluidAmount, fluid.getFluid().getIcon(fluid), 16, fluidAmount);
        }

the drawFluid method:

private void drawFluid(int x, int y, IIcon icon, int width, int height)
    {
        int i = 0;
        int j = 0;
        
        int drawHeight = 0;
        int drawWidth = 0;
        
        for (i = 0; i < width; i += 16)
        {
            for (j = 0; j < height; j += 16)
            {
                drawWidth = Math.min(width - i, 16);
                drawHeight = Math.min(height - j, 16);
                drawScaledTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight);
            }
        }
    }

and the drawScaledTexturedModelRectFromIcon method:

private void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height)
    {
        if (icon == null)
        {
            return;
        }
        double minU = icon.getMinU();
        double maxU = icon.getMaxU();
        double minV = icon.getMinV();
        double maxV = icon.getMaxV();
        
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, minU, minV + (maxV - minV) * height / 16.0D);
        tessellator.addVertexWithUV(x + width, y + height, this.zLevel, minU + (maxU - minU) * width / 16.0D, minV + (maxV - minV) * height / 16.0D);
        tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, minU + (maxU - minU) * width / 16.0D, minV);
        tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, minU, minV);
        tessellator.draw();
    }

 

By the way, I don't quite understand how this works, can you please explain it in a bit more detail? what numbers do I have to customize to for example suite the hight of the tank in my inventory?

 

You have just given me a bunch of code that does stuff I want, but without an explanation of how it does what it does, I would like to learn how this work's and what I need to change.

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

Posted

Also, it hasnt worked... (yet) but I think that is because my gui isnt accepting the fluid, it just deletes it, I am adding fluid to it by right clicking on it with a universal fluid cell from ic2. What do I need to do to make the gui not delete the fluid (im not sure if it is, but that seems like what it is doing, if you cen see that it isnt, or why it is, please point it out to me)

 

My code in the tileentity (only the tank code):

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

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

    @Override
    public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
    {
        return tankInput.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[] {
        		tankInput.getInfo()
        		};
    }

 

What do I need to change?

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

Posted

In each of the TileEntites of the output blocks, get the masters TileEntity and then the tank you need to get, and cll those methods on that tank. For the input it is almosdt the same.

 

How do I get an instance of the masters tileentity from the valve tileentity?

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

Posted

Also, how can I get the distance from the master block the valve is? would it be possible to make the valve access one tank if it is 2 blocks above the master, access the second tank if it is 4 blocks above, access the third tank if it is 6 blocks above etc.

 

The reason I would like to do this is because my multiblock will output 4 fluids, 2 gases and 2 liquids, now logic says the gases are going to rise, and the liquids are going to sink (obviously this wont really happen in the game, but it is what would happen in real life), so the I want to be able to access a tank based on the height in the structure the valve is, the dense fluids output from the bottom valve and the low density fluids output from the top

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

Posted

Slow down: how are you telling the tank to fill? From gui like put cell in slot and it gets eaten up? Then when you eat it up do the tank#.fill(..).

To get the master tile just do world#.getTileEntity(x, y, z) and, if you are sure it's a master tile entity, cast MasterTile to it: MasterTile tile2 = (MasterTile) world.get...

Just do some math for the height (tileValve#.y-tileMaster#.y>6 then A, else if >4 then B, else if >2 then C...)

Check out my blog!

http://www.whov.altervista.org

Posted

Okay, so I just right click on the master block with a fluid cell from ic2, and it seems to use up the fluid cell, and turn it into an empty cell, I am not putting anything in any slots in the gui to fill it. I am not entirely sure if it is actually filling though... If I click on the master with a bucket of my fluid, but that doesnt seem to do anything, rather just dump the bucket of fluid in the world.

 

I suspect that it is deleting the fluid in the tank because I have done something wrong somewhere, but I cant be sure of that because I have no way of telling. I have tried System.out.println(tankInput.getFluid().toString()); but that seems to throe a nullPointerException I have also tried instead of .toString(), .fluidId() and some other integer values of the fluid.

 

Here is my code if you can see what I have done wrong:

 

 

ONLY the IFluidHandler methids in the tileentity:

 

 

        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 * ;

//Some irrelevant code....

        private FluidStack[] tanks = new FluidStack[6];

//More irrelevant code....

//All the IFluidHandler methods....

        @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 || resource.getFluid() == 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() };
}

//Custom method used in the gui to get the fluid to draw (not necessary)
public FluidStack getTankInput() {
	return tankInput.getFluid();
}

 

 

 

My gui class for the distillation chamber:

 

 

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, 0, false);
	fontRendererObj.drawString("Inventory", 8, 90, 0, 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) {
				drawScaledTextureRectFromIcon(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0);
			}
		}
	}
	for (int i = 0; i < fullX; i++) {
		drawScaledTextureRectFromIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0);
	}
	for (int i = 0; i < fullY; i++) {
		if (i >= fullLvl) {
			drawScaledTextureRectFromIcon(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0);
		}
	}
	drawScaledTextureRectFromIcon(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0);
}

private void drawScaledTextureRectFromIcon(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);
	//int i = this.tileEntityDistillationChamberFrame.getPowerScaled(57);
	//drawTexturedModalRect(guiLeft + 144, guiTop + 14 + 57 - i, 176, 57 - i, 16, i);

	this.drawFluid(tileEntity.getTankInput(), guiLeft + 15, guiTop + 70, 16, 56, tileEntity.tankInput.getCapacity());
}
}

 

 

 

 

 

Now im not sure where the problem is, I dont know if it is an issue with the gui, or the tileentity. Please help me locate the issue.

 

Anyone know any mods on github that can give a clear example of drawing fluids in a gui (without some fance guiFluidHandler, or something like that that I saw in buildcrafts github)

 

I would also like to know how to add a tooltip displaying the fluid name, and the amound, when the player mouses over the tank in the gui. (But to be honest, I would really like to solve actually getting the fluid in the inventory first, so this can come after that is working)

 

Thanks.

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 now added some code in the onBlockActivated method that takes the fluid from a bucket in the players hand, and puts it into the gui, and visa versa

 

This is that code:

 

 

ItemStack itemStack = player.inventory.getCurrentItem();

	if (itemStack != null) {
		FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(itemStack);
		TileEntity tileEntity1 = world.getTileEntity(x, y, z);

		if (tileEntity1 instanceof TileEntityDistillationChamberFrame) {
			TileEntityDistillationChamberFrame master = (TileEntityDistillationChamberFrame) tileEntity1;

			if (fluid != null && master.checkMultiBlockForm()) {
				int amount = master.fill(ForgeDirection.UNKNOWN, fluid, true);

				if (amount != 0 && !player.capabilities.isCreativeMode) {
					player.inventory.setInventorySlotContents(player.inventory.currentItem, consumeItem(itemStack));
				}
			} else {
				FluidStack fluid1 = master.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;

				if (fluid1 != null) {
					ItemStack itemStack1 = FluidContainerRegistry.fillFluidContainer(fluid1, itemStack);
					fluid = FluidContainerRegistry.getFluidForFilledItem(itemStack1);

					if (fluid != null) {
						if (!player.capabilities.isCreativeMode) {
							if (itemStack.stackSize > 1) {
								if (!player.inventory.addItemStackToInventory(itemStack1)) {
									return false;
								} else {
									player.inventory.setInventorySlotContents(player.inventory.currentItem, consumeItem(itemStack));
								}
							} else {
								player.inventory.setInventorySlotContents(player.inventory.currentItem, consumeItem(itemStack));
								player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack1);
							}
						}
						master.drain(ForgeDirection.UNKNOWN, fluid1.amount, true);
						return true;
					}
				}
			}
		}
	}
        return false;
//Some irrelevant code here for opening the gui and checking if the structure is formed...

        }

 

 

 

And now when I open the gui there is a crash:

 

 

These are the lines that interest me (not the whole crash report)

java.lang.NullPointerException: Rendering screen
at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawScaledTextureRectFromIcon(GuiDistillationChamber.java:123)
at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawFluid(GuiDistillationChamber.java:110)
at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawGuiContainerBackgroundLayer(GuiDistillationChamber.java:148)

 

 

Now I am fairly sure that my code to fill the tank works, because the crash report points to the gui, not the block class.

 

These are the lines of code in the gui that it points to:

 

 

at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawScaledTextureRectFromIcon(GuiDistillationChamber.java:123)

	tess.addVertexWithUV(x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height));

 

at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawFluid(GuiDistillationChamber.java:110)

		drawScaledTextureRectFromIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0);

 

at net.theepictekkit.generator.client.gui.GuiDistillationChamber.drawGuiContainerBackgroundLayer(GuiDistillationChamber.java:148)

	this.drawFluid(tileEntity.getTankInput(), guiLeft + 15, guiTop + 70, 16, 56, tileEntity.tankInput.getCapacity());

 

And here is all of the gui class:

 

 

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, 0, false);
	fontRendererObj.drawString("Inventory", 8, 90, 0, 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) {
				drawScaledTextureRectFromIcon(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0);
			}
		}
	}
	for (int i = 0; i < fullX; i++) {
		drawScaledTextureRectFromIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0);
	}
	for (int i = 0; i < fullY; i++) {
		if (i >= fullLvl) {
			drawScaledTextureRectFromIcon(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0);
		}
	}
	drawScaledTextureRectFromIcon(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0);
}

private void drawScaledTextureRectFromIcon(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);

	this.drawFluid(tileEntity.getTankInput(), guiLeft + 15, guiTop + 70, 16, 56, tileEntity.tankInput.getCapacity());
}
}

 

 

 

 

 

So this means that there isnt anything wrong with my block class or tileentity (yet... as far as I can tell), instead, it is a problem with the way I am drawing the fluid in the gui

 

I am not so great at debugging (I can figure out basic problems) this is really complicated, and I dont know where to start.

 

Please tell me if you can see the problem, or if you have a better / correct way of drawing fluids in the gui. untill then, I am going to attempt to figure this out also.

 

Thanks for your help.

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

Posted

I think I am registering my textures wrong... I put my crude oil fluid into a fluid transposer from te, and the fluid in the tank was invisible. I probably also registered the name wrong because it was fluid.fluidCrudeOil when I mouse over it. What is the proper way of registering fluid textures and names? this might have been the problem, the tank worked all along, but I didn't know because the fluid was invisible.... and there was no tooltip, because I dont know how to do that.

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

Posted

Now Im even more confused, I have no idea where I am going wrong. The tileentity class, the gui class, the block class.... really confused.

 

Also, there isnt any tutorials on fluids in guis there needs to a be a tutorial on this somewhere.

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

Posted

I had that problem too where the fluid was invisible in tanks. If you have a block implementation (for it to be placed in the world) with correct textures, you need to set

YourFluid#setIcons(stillIcon,flowingIcon)

so it has the proper textures.

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

The textures in the world are correct, just in tanks.

 

So do I add

YourFluid#setIcons(stillIcon,flowingIcon)

to the block class?

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

Posted

You probably have a static instance of the fluid, use that to call the

setIcons(stillIcon,flowingIcon)

method.

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

Ah, now I understand.

 

I added into the block class:

FluidHandler.fluidCrudeOil.setIcons(iconStationary, iconFlowing);

 

So I am registering the icon for the fluid not the block, but from the block class.

 

And yes, I do have a static instance of the fluid.

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

Posted

Actually, nevermind, that hasnt worked, the fluid is still invisible in the fluid transposer.

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

Posted

Where have you placed that? I did in the registerBlockIcons method after the initialization of the icons.

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/

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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