Jump to content

Recommended Posts

Posted

Alright, I am currently working on the fluid tanks that display how much fluid is the tile. The problem is I don't know how to display the fluid and render.

Here are some Codes

Tile Entity Code:

  Reveal hidden contents

 

Screen Code:

  Reveal hidden contents

 

Container Code:

  Reveal hidden contents

 

Posted

Yeah, but that texture needs to bind into the GUI which is the problem. I tried to use  Minecraft#getAltasSprtiteGettter but I get a mess of textures.

Posted
  On 5/10/2020 at 4:37 PM, diesieben07 said:

All block textures exist on one texture sheet. You can bind it using PlayerContainer.LOCATION_BLOCKS_TEXTURE. The TextureAtlasSprite then tells you the u v coordinates in that atlas texture.

Expand  

I tried using the method blit(int a, int b, int c, int d, int e, TextureAltasSprite f)but that did not work.

Posted

I used water as an example. The parameters were 16, 16, one, 16, 16, and water. Did I forget something?

private void addScreen() {
    @SuppressWarnings("resource")
    TextureAtlasSprite sprite = getSprite(new ResourceLocation("minecraft", "water"));
    // This is the one I used
    blit(16, 16, 1, 16, 16, sprite);
}

public TextureAtlasSprite getSprite(ResourceLocation resourceLocation) {
   return this.minecraft.getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(resourceLocation);
}
	
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    this.font.drawString(this.title.getFormattedText(), 8.0F, 7.0F, 4210752);
    this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 5), 4210752);
    addScreen();
}

 

Posted
  On 5/10/2020 at 6:59 PM, diesieben07 said:

What on earth are you doing... Nothing about what you are doing there makes any sense.

Expand  

I know it makes nonsense but I am trying to get the fluid texture into the tank screen. I used water as an example.

Posted (edited)
  On 5/10/2020 at 7:04 PM, Issac29 said:

I know it makes nonsense but I am trying to get the fluid texture into the tank screen. I used water as an example.

Expand  

Anyway Here is the better code. 

 

	@SuppressWarnings("resource")
	private void addScreen(int x, int y) {
		TextureAtlasSprite sprite = getSprite(new ResourceLocation("minecraft:water"));
		sprite.getAtlasTexture().bindTexture();
		blit(100, 50, 0, 32, 32, sprite);
	}

	public TextureAtlasSprite getSprite(ResourceLocation resourceLocation) {
		return this.minecraft.getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(resourceLocation);
	}
	
	@Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        this.font.drawString(this.title.getFormattedText(), 8.0F, 7.0F, 4210752);
        this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 5), 4210752);
        addScreen(mouseX, mouseY);
    }

 

Edit: For odd reason there still a invalid or missing texture.

Edited by Issac29
Posted
  On 5/10/2020 at 8:39 PM, diesieben07 said:

Why on earth is the method called "addScreen". That makes zero sense.

 

Do not use getAtlasSpriteGetter. You need to get the model from the block and then get the textures from the model. There can be multiple or there could even potentially be none at all.

Expand  

OK I renamed the method "addScreen" to "drawFluidTexture". Which makes more sense.

@SuppressWarnings("resource")
	private void drawFluidTexture(int x, int y) {
		TextureAtlasSprite texture = this.minecraft.getModelManager().getModel(new ResourceLocation("minecraft:water")).getParticleTexture(EmptyModelData.INSTANCE);
		texture.getAtlasTexture().bindTexture();
		blit(84, 12, 0, 32, 32, texture);
	}

	
	@Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        this.font.drawString(this.title.getFormattedText(), 8.0F, 7.0F, 4210752);
        this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 5), 4210752);
        drawFluidTexture(mouseX, mouseY);
    }

 

But still has a missing texture. Maybe I needed to soft code it into something better.

Posted
  On 5/10/2020 at 9:09 PM, diesieben07 said:

Have you verified that its actually returning a proper model and texture?

Expand  

The texture for weird reason returns "minecraft:missingno". This does not make any sense. As for the model it seems to have a number SimpleBakedModel@411933.

Posted

I figured out that to get the sprite texture, you needed the Fluid#getAttributes#getStillTexture to obtain that texture. No need for getting the model or the blockstate for just a simple four step code.

AtlasTexture texture = minecraft.getModelManager().getAtlasTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = texture.getSprite(Fluids.WATER.getAttributes().getStillTexture());
texture.bindTexture();
blit(70, 20, 0, 32, 32, sprite);

 

Posted

Alright most of the tank is synced but the only problem is the when I type this command /setblock x y z namespace:tankName{tankData: {FluidName: #fluidName, Amount: #amount}}, the server loads the data but the client does not load until reloading the world or chunk. That same applies to /data modify block x y z tankData set value {FluidName: #fluidName, Amount: #Amount}. I used every method to sync the client but some odd reason they don't sync when changing the tank value with commands.

Before Reloading Chunks:

2020-05-15_10_41_36.thumb.png.250b037d1649ee9d0b5c140384fce5cd.png

 

After Reloading Chunks:

2020-05-15_10_51_33.thumb.png.f852d9c66f565f8c0413600622be7f43.png

Posted
  On 5/15/2020 at 4:36 PM, diesieben07 said:

Show your code.

Expand  

 

  On 5/15/2020 at 3:53 PM, Issac29 said:

Alright most of the tank is synced but the only problem is the when I type this command /setblock x y z namespace:tankName{tankData: {FluidName: #fluidName, Amount: #amount}}, the server loads the data but the client does not load until reloading the world or chunk. That same applies to /data modify block x y z tankData set value {FluidName: #fluidName, Amount: #Amount}. I used every method to sync the client but some odd reason they don't sync when changing the tank value with commands.

Before Reloading Chunks:

2020-05-15_10_41_36.thumb.png.250b037d1649ee9d0b5c140384fce5cd.png

 

After Reloading Chunks:

2020-05-15_10_51_33.thumb.png.f852d9c66f565f8c0413600622be7f43.png

Expand  

What the Images don't give enough information. Fine here is the code.

public class TankTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity {

	ManualTank tank = new ManualTank(8000, this);
	private LazyOptional<FluidTank> optional = LazyOptional.of(() -> this.tank);

	public TankTileEntity() {
		super(INCTileEntityTypes.TANK);
	}

	@Override
	public void read(CompoundNBT compound) {
		super.read(compound);
		CompoundNBT nbtfluid = compound.getCompound("tank"); //$NON-NLS-1$
		this.tank.readFromNBT(nbtfluid);
	}

	@Override
	public CompoundNBT write(CompoundNBT compound) {
		compound.put("tank", this.tank.writeToNBT(new CompoundNBT())); //$NON-NLS-1$
		return super.write(compound);
	}
	
	@Override
	public CompoundNBT getUpdateTag() {
		CompoundNBT nbt = super.getUpdateTag();
		return this.write(nbt);
	}

	@Override
	public boolean receiveClientEvent(int id, int type) {
		return true;

	}
	
	@Override
	public void handleUpdateTag(CompoundNBT tag) {
		read(tag);
	}

	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap) {
		return cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ? this.optional.cast() : super.getCapability(cap);
	}

	@Override
	public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
		return new TankContainer(p_createMenu_1_, this.world, this.pos, p_createMenu_2_);
	}

	@Override
	public ITextComponent getDisplayName() {
		return new TranslationTextComponent("container.tank"); //$NON-NLS-1$
	}

	public FluidTank getTank() {
		return this.tank;
	}

	@Override
	public void tick() {
		return;
	}
}

 

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.