Jump to content

[SOLVED] [1.12] Help with TESRS and RenderEntityItem


IceMetalPunk

Recommended Posts

SOLVED! The solution to the rotation issue is to call EntityItem#onUpdate manually, since it's not called automatically unless the entity is spawned in the world (and thus the age of the entity, which controls its rotation, doesn't get updated). The solution to the black-rendering issue is to use the setLightmapDisabled method instead of GlStateManager.disableLighting(), as there's apparently a texture map used for lighting when rendering, and that needs to be disabled to get a full-color render regardless of lighting conditions.

 

Original Post:

 

Let me start by saying that rendering has always been my weakest area of programming. In any language, ever. I don't know why, but it's always been difficult for me.

 

So now I'm playing around with TESRs, trying to learn how to use them, and immediately I've hit a roadblock.

 

The idea was simple: use a RenderEntityItem in a TESR bound to (for now) the TileEntityDropper to display a Totem of Undying floating above the droppers. So I created this TESR:

 

public class AltarPedestalTESR extends TileEntitySpecialRenderer<TileEntityDropper> {

	RenderEntityItem rei = null;

	public AltarPedestalTESR() {
		super();
		rei = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(),
				Minecraft.getMinecraft().getRenderItem()) {
			@Override
			public boolean shouldSpreadItems() {
				return false;
			}
		};
	}

	@Override
	public void render(TileEntityDropper te, double x, double y, double z, float partialTicks, int destroyStage,
			float alpha) {
		EntityItem entity = new EntityItem(te.getWorld());
		entity.setItem(new ItemStack(Items.TOTEM_OF_UNDYING, 1));

		GlStateManager.pushMatrix();
		GlStateManager.pushAttrib();
		GlStateManager.color(1.0f, 1.0f, 1.0f);
		GlStateManager.disableLighting();
		rei.doRender(entity, x + 0.5, y + 1.0f, z + 0.5, 0, partialTicks);
		GlStateManager.enableLighting();
		GlStateManager.popAttrib();
		GlStateManager.popMatrix();

		super.render(te, x, y, z, partialTicks, destroyStage, alpha);

	}

}

And I'm registering it in my Client Proxy's Init event handler with this:

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDropper.class, new AltarPedestalTESR());

 

It is rendering the totem above the droppers, but it's rendering it totally black and spinning very, very quickly.

 

I tried to fix the black color by adding the GlStateManager method calls you see in the code (setting the color to (1.0,1.0,1.0), which is white, right? And disabling the lighting), but it didn't fix the problem, and I don't really understand rendering enough to know what to try next.

 

As for the rotation, I looked into the rendering code a bit more and it seemed like the rotation was based on the EntityItem's age. I reasoned that, therefore, creating a new EntityItem each render tick was probably a bad idea, so I moved the EntityItem initialization out of the method and into the class itself, resulting in this code:

 

public class AltarPedestalTESR extends TileEntitySpecialRenderer<TileEntityDropper> {

	RenderEntityItem rei = null;
	EntityItem entity = new EntityItem(Minecraft.getMinecraft().world, 0, 0, 0,
			new ItemStack(Items.TOTEM_OF_UNDYING, 1));

	public AltarPedestalTESR() {
		super();
		rei = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(),
				Minecraft.getMinecraft().getRenderItem()) {
			@Override
			public boolean shouldSpreadItems() {
				return false;
			}
		};
	}

	@Override
	public void render(TileEntityDropper te, double x, double y, double z, float partialTicks, int destroyStage,
			float alpha) {
		entity.setWorld(te.getWorld());

		GlStateManager.pushMatrix();
		GlStateManager.pushAttrib();
		GlStateManager.color(1.0f, 1.0f, 1.0f);
		GlStateManager.disableLighting();
		rei.doRender(entity, x + 0.5, y + 1.0f, z + 0.5, 0, partialTicks);
		GlStateManager.enableLighting();
		GlStateManager.popAttrib();
		GlStateManager.popMatrix();

		super.render(te, x, y, z, partialTicks, destroyStage, alpha);

	}

}

 

It stopped the crazy spinning, but it also stopped the spinning completely, so the item doesn't turn anymore. I don't know where to go from here...

 

So the two questions are:

 

1) How do I get it to rotate at a normal EntityItem speed?

2) How do I get it to render normal-colored instead of black?

Edited by IceMetalPunk

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

8 hours ago, IceMetalPunk said:

1) How do I get it to rotate at a normal EntityItem speed?

This one's easy. Do dick with it. No really, stop messing with its rotation. The EntityItemRenderer already rotates it based on how many ticks old the EntityItem is, so all you have to do is nothing but let it age up (getting it to not rotate is harder!).

8 hours ago, IceMetalPunk said:

2) How do I get it to render normal-colored instead of black?

Disable lighting, usually, but you're already doing that. Try not disabling lighting.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 hours ago, Draco18s said:

This one's easy. Do dick with it. No really, stop messing with its rotation. The EntityItemRenderer already rotates it based on how many ticks old the EntityItem is, so all you have to do is nothing but let it age up (getting it to not rotate is harder!).

Disable lighting, usually, but you're already doing that. Try not disabling lighting.

I'm *not* doing anything with its rotation... and it's just not rotating at all...

As for the lighting, I *didn't* disable lighting at first, and it was black; that's why I tried disabling lighting, but it's still black. Either way I tried that, it still turns out black.

 

*EDIT* A little bit of debug output shows me that the age of the EntityItem is *not* ticking up. I'm going to look into that more, but I assume that's because it's not spawned in the world? At the same time, I don't *want* it spawned in the world as an entity, I'm only using it for rendering, so... how do I get its age to tick up without spawning it?

 

*EDIT 2* Problem 1 is solved! Turns out that the age is ticked up in the onUpdate() method, and that's only called naturally for entities spawned in a world. So I just manually call onUpdate() now, immediately after setting the entity's world, and it spins perfectly normally! :D

Now I just need to figure out how to get the colors/lighting correct.... any ideas?

 

*EDIT 3* AHA! Solved it! :D I stumbled upon the solution completely accidentally, really xD I was going to remove the super.render() call, since I didn't want the nameplate to render, and I figured I should check that method to make sure it's not doing anything else important that I might need to keep. It's not, but in that method, before rendering the nameplate, it calls the setLightmapDisabled method. That method doesn't use GlStateManager.disableLighting() at all -- instead, it disables a lighting map texture.

 

So I removed the super.render() call and tried using setLightmapDisabled in my rendering code instead... and it worked! :D The item now renders perfectly fine :D

Thank you for your help, Draco! :)

Edited by IceMetalPunk
  • Like 2

Whatever Minecraft needs, it is most likely not yet another tool tier.

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

    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

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