Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] TileEntityRenderer not accessing TileEntity inventory


bibouche_
 Share

Recommended Posts

Hi, so the thing is that I have a TileEntity for which I added a TileEntityRenderer, I already did this with two other TileEntities but this time it was not working and I found out that the Renderer class cannot reach TileEntity inventory, since when I have an ItemStack in a slot, it outputs Air. And also, my two other TileEntities uses ISidedInventory (which I know shouldn't be used but I will change this later), and this one uses IItemHandler. I don't know if it is what causes the issue or if I am networking bad or even if I am missing something, can someone help me please ?

 

TileEntityRenderer :

public class CelestialPowerPedestalTileEntityRenderer extends TileEntityRenderer<CelestialPowerPedestalTileEntity> {

	private Minecraft mc  = Minecraft.getInstance();

	public CelestialPowerPedestalTileEntityRenderer(
		TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}

	@Override
	public void render(
		CelestialPowerPedestalTileEntity te,
		float partialTicks,
		MatrixStack matrixStackIn,
		IRenderTypeBuffer bufferIn,
		int combinedLightIn,
		int combinedOverlayIn) {

		int lightLevel = getLightLevel(te.getWorld(), te.getPos());

		if (!te.isFillable()) {

			renderItem(te.inv.getStackInSlot(0), new double[] {0.48d, 0.83d, 0.42d},
			           90, 0, 0, matrixStackIn, bufferIn, partialTicks, combinedOverlayIn, lightLevel, 1.0f);

		}
	}

	private void renderItem(
		ItemStack stack, double[] translation, int rotX, int rotY, int rotZ, MatrixStack matrixStack, IRenderTypeBuffer buffer, float partialTicks, int combinedOverlay, int lightLevel, float scale) {

		matrixStack.push();
		matrixStack.translate(translation[0], translation[1], translation[2]);
		matrixStack.rotate(Vector3f.XP.rotationDegrees((float) rotX));
		matrixStack.rotate(Vector3f.YP.rotationDegrees((float) rotY));
		matrixStack.rotate(Vector3f.ZP.rotationDegrees((float) rotZ));
		matrixStack.scale(scale, scale, scale);

		IBakedModel model = mc.getItemRenderer().getItemModelWithOverrides(stack, null, null);
		mc.getItemRenderer().renderItem(stack,
		                                ItemCameraTransforms.TransformType.GROUND, true, matrixStack, buffer, lightLevel, combinedOverlay, model);
		matrixStack.pop();

	}

	private int getLightLevel(
		World world, BlockPos pos) {
		int blockLight = world.getLightFor(LightType.BLOCK, pos);
		int skyLight = world.getLightFor(LightType.SKY, pos);
		return LightTexture.packLight(blockLight, skyLight);
	}

}

TileEntity networking and writing :

public void read(
		BlockState state,
		CompoundNBT nbt) {
		super.read(
			state,
			nbt);

		NonNullList <ItemStack> inv = NonNullList.withSize(
			this.inv.getSlots(),
			ItemStack.EMPTY);
		ItemStackHelper.loadAllItems(
			nbt,
			inv);
		setItems(inv);
	}

	@Nonnull
	@Override
	public CompoundNBT write(
		CompoundNBT compound) {
		super.write(compound);

		ItemStackHelper.saveAllItems(
			compound,
			this.getItems());

		return compound;
	}

	@Nullable
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		CompoundNBT nbt = new CompoundNBT();
		this.write(nbt);
		return new SUpdateTileEntityPacket(
			this.pos,
			0,
			nbt);
	}

	@Override
	public void onDataPacket(
		NetworkManager net,
		SUpdateTileEntityPacket pkt) {
		this.read(
			world.getBlockState(pkt.getPos()),
			pkt.getNbtCompound());
	}

	@Override
	public CompoundNBT getUpdateTag() {
		CompoundNBT nbt = new CompoundNBT();
		this.write(nbt);
		return nbt;
	}

	@Override
	public void handleUpdateTag(
		BlockState state,
		CompoundNBT tag) {
		this.read(state, tag);
	}

 

Link to comment
Share on other sites

why do you use IItemHandler as inventory?
Edit: use ItemStackHandler instead, reason:

you use Capability#getDefaultInstance to get an IItemHandler,
why don't you use a new ItemStackHandler that contains the methods serializeNBT and deserializeNBT
which you can execute in read and write the TE, wich is very simple

Edited by Luis_ST
Link to comment
Share on other sites

55 minutes ago, diesieben07 said:

That is not at all what I said.

Yes, delete getItems, but use the proper alternative, don't just remove read and write.

Ok so I came up with this : https://pastebin.com/L01ZkFj2, however I think I did something wrong since it did not fixed it, for the Direction I put Direction#NORT but I don't know if it is ok to put a fixed direction like this.

 

49 minutes ago, Luis_ST said:

why do you use IItemHandler as inventory?
Edit: use ItemStackHandler instead, reason:

you use Capability#getDefaultInstance to get an IItemHandler,
why don't you use a new ItemStackHandler that contains the methods serializeNBT and deserializeNBT
which you can execute in read and write the TE, wich is very simple

I use the default instance since it creates a new IItemHandler with just one slot and it is to avoid creating more instances and classes

Link to comment
Share on other sites

22 minutes ago, bibouche_ said:

Ok so I came up with this : https://pastebin.com/L01ZkFj2, however I think I did something wrong since it did not fixed it, for the Direction I put Direction#NORT but I don't know if it is ok to put a fixed direction like this.

you can use null

22 minutes ago, bibouche_ said:

I use the default instance since it creates a new IItemHandler with just one slot and it is to avoid creating more instances and classes

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

Edit: another issue in your code, you call the write inside the getUpdatePacket method of your TE

Edited by Luis_ST
Link to comment
Share on other sites

19 minutes ago, Luis_ST said:

you can use null

 

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

Ok but I tried it and I keep having the same issue, I really don't see what is causing this

Link to comment
Share on other sites

56 minutes ago, Luis_ST said:

Edit: another issue in your code, you call the write inside the getUpdatePacket method of your TE

Yes, because I want it to write the data in the tileEntity on block update

Link to comment
Share on other sites

10 hours ago, bibouche_ said:

Yes, because I want it to write the data in the tileEntity on block update

post your updated code
and take a look at some vanilla TEs,
how they synchronize the TE data with the client

Link to comment
Share on other sites

1 hour ago, Luis_ST said:

post your updated code
and take a look at some vanilla TEs,
how they synchronize the TE data with the client

https://pastebin.com/DKKj7JNG

 

Yeah, I looked at some vanilla TEs, however they are using CompoundNBT, so I am a litte lost since IItemHandler uses INBT, and like the read and write methods are using CompoundNBT

Link to comment
Share on other sites

1 minute ago, bibouche_ said:

please post the full TE class

 

1 minute ago, bibouche_ said:

Yeah, I looked at some vanilla TEs, however they are using CompoundNBT, so I am a litte lost since IItemHandler uses INBT, and like the read and write methods are using CompoundNBT

that's basic java, INBT is an interfaces, and CompoundNBT is an implemention of INBT

Link to comment
Share on other sites

1 minute ago, bibouche_ said:

https://pastebin.com/SjjXivkK

Yeah I know that, but I did not found a way yet, so I will look at it, maybe add a new CompoundNBT and use it in the functions

You're still doing what you shouldn't

 

13 hours ago, Luis_ST said:

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

this is optional

 

13 hours ago, Luis_ST said:

another issue in your code, you call the write inside the getUpdatePacket method of your TE

that is required

Link to comment
Share on other sites

getUpdatePacket should use getUpdateTag and onDataPacket should call handleUpdateTag.

Then getUpdateTag needs to call super, not write. Then you need to write only the data that is necessary on the client in getUpdateTag. In handleUpdateTag you then read that data.

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

getUpdatePacket should use getUpdateTag and onDataPacket should call handleUpdateTag.

Then getUpdateTag needs to call super, not write. Then you need to write only the data that is necessary on the client in getUpdateTag. In handleUpdateTag you then read that data.

Like so ? https://pastebin.com/FuUvqppK

Link to comment
Share on other sites

41 minutes ago, diesieben07 said:

Well, you now need to tell the game to send the packet whenever the inventory changes.,

Oups, yeah of course, forgot that.

Yepp, got it to work, thank you :) !!!!

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.

Guest
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Thanks for the help everybody! I tried this and although the block did register, the fluid just appears as a flat plane you can only see if you break the block under it. I tried debugging it as much as I could but alas I couldn't solve it Here is the code for my "fixed" liquidblock as suggested by Luis_ST: package com.hotmail.majdroaydi.minitech.blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.sounds.SoundEvent; import net.minecraft.tags.FluidTags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import java.util.Optional; import java.util.function.Supplier; public class ForgeLiquidBlock extends LiquidBlock { public ForgeLiquidBlock(Supplier<? extends FlowingFluid> supplier, Properties properties) { super(supplier, properties); } @Override public VoxelShape getCollisionShape(BlockState p_54760_, BlockGetter p_54761_, BlockPos p_54762_, CollisionContext p_54763_) { return p_54763_.isAbove(STABLE_SHAPE, p_54762_, true) && p_54760_.getValue(LEVEL) == 0 && p_54763_.canStandOnFluid(p_54761_.getFluidState(p_54762_.above()), getFluid()) ? STABLE_SHAPE : Shapes.empty(); } @Override public boolean isPathfindable(BlockState p_54704_, BlockGetter p_54705_, BlockPos p_54706_, PathComputationType p_54707_) { return !getFluid().is(FluidTags.LAVA); } @Override public boolean skipRendering(BlockState p_54716_, BlockState p_54717_, Direction p_54718_) { return p_54717_.getFluidState().getType().isSame(getFluid()); } @Override public void onPlace(BlockState p_54754_, Level p_54755_, BlockPos p_54756_, BlockState p_54757_, boolean p_54758_) { if (this.shouldSpreadLiquid(p_54755_, p_54756_, p_54754_)) { p_54755_.getLiquidTicks().scheduleTick(p_54756_, p_54754_.getFluidState().getType(), getFluid().getTickDelay(p_54755_)); } } @Override public BlockState updateShape(BlockState p_54723_, Direction p_54724_, BlockState p_54725_, LevelAccessor p_54726_, BlockPos p_54727_, BlockPos p_54728_) { if (p_54723_.getFluidState().isSource() || p_54725_.getFluidState().isSource()) { p_54726_.getLiquidTicks().scheduleTick(p_54727_, p_54723_.getFluidState().getType(), getFluid().getTickDelay(p_54726_)); } //return super.updateShape(p_54723_, p_54724_, p_54725_, p_54726_, p_54727_, p_54728_); return p_54723_; // Calling super.updateShape will just call LiquidBlock's updateShape, not what we are looking for! Thankfully, Block.updateShape, simply enough, just returns the first parameter. } @Override public void neighborChanged(BlockState p_54709_, Level p_54710_, BlockPos p_54711_, Block p_54712_, BlockPos p_54713_, boolean p_54714_) { if (this.shouldSpreadLiquid(p_54710_, p_54711_, p_54709_)) { p_54710_.getLiquidTicks().scheduleTick(p_54711_, p_54709_.getFluidState().getType(), getFluid().getTickDelay(p_54710_)); } } private boolean shouldSpreadLiquid(Level p_54697_, BlockPos p_54698_, BlockState p_54699_) { if (getFluid().is(FluidTags.LAVA)) { boolean flag = p_54697_.getBlockState(p_54698_.below()).is(Blocks.SOUL_SOIL); for(Direction direction : POSSIBLE_FLOW_DIRECTIONS) { BlockPos blockpos = p_54698_.relative(direction.getOpposite()); if (p_54697_.getFluidState(blockpos).is(FluidTags.WATER)) { Block block = p_54697_.getFluidState(p_54698_).isSource() ? Blocks.OBSIDIAN : Blocks.COBBLESTONE; p_54697_.setBlockAndUpdate(p_54698_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_54697_, p_54698_, p_54698_, block.defaultBlockState())); this.fizz(p_54697_, p_54698_); return false; } if (flag && p_54697_.getBlockState(blockpos).is(Blocks.BLUE_ICE)) { p_54697_.setBlockAndUpdate(p_54698_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_54697_, p_54698_, p_54698_, Blocks.BASALT.defaultBlockState())); this.fizz(p_54697_, p_54698_); return false; } } } return true; } private void fizz(LevelAccessor p_54701_, BlockPos p_54702_) { p_54701_.levelEvent(1501, p_54702_, 0); } @Override public ItemStack pickupBlock(LevelAccessor p_153772_, BlockPos p_153773_, BlockState p_153774_) { if (p_153774_.getValue(LEVEL) == 0) { p_153772_.setBlock(p_153773_, Blocks.AIR.defaultBlockState(), 11); return new ItemStack(getFluid().getBucket()); } else { return ItemStack.EMPTY; } } @Override public Optional<SoundEvent> getPickupSound() { return getFluid().getPickupSound(); } } The code for my OilFluid can be found above.
    • Whoops! Sorry, my fault. But yes, a block entity (tile entity in 1.16-) *is* needed for storing data (i.e. furnace). But I think what OP is doing is making an item combiner, which doesn't need one
    • Looking to work with reliable Fabric & Forge developers to produce original mods for use on my YouTube channel! We'll be regularly working together and you'll be given a detailed brief for each commission that outlines exactly what I want. From there, you can give me a price that fits the scope of the project and we can get to work :thumbsup: Because these commissions are only for YouTube videos, you're essentially making vertical-slices / proof-of-concepts. They can have bugs, you can take shortcuts & we can use video editing to hide bugs & achieve some effects. With that in mind, turnaround speed depends on project complexity but for an average commission I'd expect delivery two days - five days Send me a email at either lmaololtbhhonest@gmail.com OR Business@tbhhonest.com if you're interested! preview of channel: https://imgur.com/a/bOVkiUo LINK:  https://www.youtube.com/channel/UCnwo3X3eCrUp7N1DZPc-MGQ  
    • If you want a tiny fraction of offset, use float.epsilon. 0.01 will actually be noticeable. It's about 1/6th of a texture pixel.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.