Jump to content

Recommended Posts

Posted

There are bits and pieces of up-to-date information about Tile Entities here, on the wiki, on YouTube videos, and of course in Minecraft's source itself, but while I have been looking through all these things for hours I can't get a clear picture of how I'm supposed to make and use Tile Entities.

 

Can someone tell me the fundamentals of making and using them?

 

As an example, I'd like to make a block that, when right-clicked, will open up a trade window that's essentially identical to a villager's trade window.

Posted

I think more information might help me get an answer while I'm AFK so hopefully when I come back I can progress.

 

I've already made a block, and I've got a tile entity class for it (but I don't know if the tile entity class is functional or even written properly).  I've read about "containers" but I don't think the word "container" means the same thing when making a tile entity that it does in game.  I think I have a container class, but I don't really know what it does.  And I don't know how to draw the gui.

 

The only reason I'm asking such broad questions here is because I can't find any good, up-to-date, and comprehensive information anywhere else.  I am not a total noob; I know how to do use Forge and I know intermediate Java.  I already have done some significant work on my mod, I just need to know the procedure for making and using tile entities to do what I mentioned in the original post.

 

Any help at all would be appreciated.  Thanks :)

Posted

Step 1:

 

class MyTileEntityBlock extends BlockContainer

 

Yes, it creates a container but that's because the original vanilla TE objects have inventories.  You don't need to utilize this fact, nor do you need to utilize the NBT data that can easily get saved via entities.

 

Step 2:

 

class MyTileEntityEntity extends TileEntity

 

This class is what's created when you place the block.  The parent class (BlockContainer) will throw an "add unimplemented methods" error, one of which will be function that returns a tile entity.  You'd add "return new MyTileEntityEntity()" there.  WARNING: do not pass parameters or change properties of the TE at this point, as you will want to read these values from the NBT data or they'll get reset on world load.

 

Step 3

 

public class MyTileEntityRenderer extends TileEntitySpecialRenderer

 

This will handle your TE rendering.  You may also have a model that you're using or you might use the tessalator directly.  I've done both.

 

Step 4

 

In your base mod class:

RenderingRegistry.registerBlockHandler(new MyTileEntityRenderer());

You should also use RenderingRegistry.getNextAvailableRenderId() to get a rendering ID and pass it to both your block and render class.

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.

Posted

Eurgh. I think it's more readable if you name those ContainerMyBlock, TileEntityMyBlock, and RenderMyBlock respectively. In fact, I need to get my partner atrain99 to rename our classes like that :P

 

Whichever.  A lot of tutorials and such always do it as MyFoo and MyBar

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.

Posted

Step 1:

 

class MyTileEntityBlock extends BlockContainer

 

Yes, it creates a container but that's because the original vanilla TE objects have inventories.  You don't need to utilize this fact, nor do you need to utilize the NBT data that can easily get saved via entities.

 

Step 2:

 

class MyTileEntityEntity extends TileEntity

 

This class is what's created when you place the block.  The parent class (BlockContainer) will throw an "add unimplemented methods" error, one of which will be function that returns a tile entity.  You'd add "return new MyTileEntityEntity()" there.  WARNING: do not pass parameters or change properties of the TE at this point, as you will want to read these values from the NBT data or they'll get reset on world load.

 

Step 3

 

public class MyTileEntityRenderer extends TileEntitySpecialRenderer

 

This will handle your TE rendering.  You may also have a model that you're using or you might use the tessalator directly.  I've done both.

 

Step 4

 

In your base mod class:

RenderingRegistry.registerBlockHandler(new MyTileEntityRenderer());

You should also use RenderingRegistry.getNextAvailableRenderId() to get a rendering ID and pass it to both your block and render class.

 

Thanks so much.  Just understanding the basic structure of what I'm trying to do here will help a good deal.  In this example, should MyTileEntityRenderer also implement IMerchant and IInventory?  Rendering a gui is still a little confusing to me, but I know I need at least one of those two.

Posted

Thanks so much.  Just understanding the basic structure of what I'm trying to do here will help a good deal.  In this example, should MyTileEntityRenderer also implement IMerchant and IInventory?  Rendering a gui is still a little confusing to me, but I know I need at least one of those two.

 

Maybe?  I don't recognize those two classes at the moment.

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.

Posted

Thanks so much.  Just understanding the basic structure of what I'm trying to do here will help a good deal.  In this example, should MyTileEntityRenderer also implement IMerchant and IInventory?  Rendering a gui is still a little confusing to me, but I know I need at least one of those two.

Your TileEntity, *not* your TESR, should extend IInventory. I don't know about IMerchant.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

Actually now that I have a chance to work on this some more, this whole bit just confuses me.  Why do I need a special renderer?  Can I just have a block, a tile entity, and have that tile entity called in onBlockActivated()?

 

The whole point is to draw a GUI when a block is right-clicked, and I'm not seeing much information about drawing a gui anywhere really.

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

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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