Jump to content

Help with rendering Tile Entities


CptTomm

Recommended Posts

I'm trying to Render a table but whenever I try to place it down it just is an invisible block, like a barrier.

 

I am new to Modding so help wold be greatly appreciated.

 

BlockTable.java:

 

package com.CptTomm.ms.blocks;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class BlockTable  extends Block{

 

public BlockTable() {

super(Material.wood);

 

this.setBlockName("table");

this.setCreativeTab(CreativeTabs.tabDecorations);

}

 

public TileEntity createNewTileEntity(World w) {

return new TileEntityTable();

}

 

public int getRenderType() {

return -1;

}

 

public boolean isOpaqueCube() {

return false;

}

 

public boolean renderAsNormalBlock() {

return false;

}

 

@SideOnly(Side.CLIENT)

public void regiaterIcons(IIconRegister icon) {

this.blockIcon = icon.registerIcon("ms:table");

}

 

}

 

 

TileEntityTable.java:

 

package com.CptTomm.ms.blocks;

 

import net.minecraft.tileentity.TileEntity;

 

public class TileEntityTable extends TileEntity {

 

}

 

 

ModelTable.java:

 

package com.CptTomm.ms.blocks;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelRenderer;

import net.minecraft.entity.Entity;

 

public class ModelTable extends ModelBase

{

  //fields

    ModelRenderer leg1;

    ModelRenderer leg2;

    ModelRenderer leg3;

    ModelRenderer leg4;

    ModelRenderer Shape1;

 

  public ModelTable()

  {

    textureWidth = 64;

    textureHeight = 32;

   

      leg1 = new ModelRenderer(this, 0, 0);

      leg1.addBox(0F, 0F, 0F, 2, 13, 2);

      leg1.setRotationPoint(4F, 11F, 4F);

      leg1.setTextureSize(64, 32);

      leg1.mirror = true;

      setRotation(leg1, 0F, 0F, 0F);

      leg2 = new ModelRenderer(this, 0, 0);

      leg2.addBox(0F, 0F, -2F, 2, 13, 2);

      leg2.setRotationPoint(4F, 11F, -4F);

      leg2.setTextureSize(64, 32);

      leg2.mirror = true;

      setRotation(leg2, 0F, 0F, 0F);

      leg3 = new ModelRenderer(this, 0, 0);

      leg3.addBox(-2F, 0F, -2F, 2, 13, 2);

      leg3.setRotationPoint(-4F, 11F, -4F);

      leg3.setTextureSize(64, 32);

      leg3.mirror = true;

      setRotation(leg3, 0F, 0F, 0F);

      leg4 = new ModelRenderer(this, 0, 0);

      leg4.addBox(-2F, 0F, 0F, 2, 13, 2);

      leg4.setRotationPoint(-4F, 11F, 4F);

      leg4.setTextureSize(64, 32);

      leg4.mirror = true;

      setRotation(leg4, 0F, 0F, 0F);

      Shape1 = new ModelRenderer(this, 5, 16);

      Shape1.addBox(-7F, 0F, -7F, 14, 2, 14);

      Shape1.setRotationPoint(0F, 9F, 0F);

      Shape1.setTextureSize(64, 32);

      Shape1.mirror = true;

      setRotation(Shape1, 0F, 0F, 0F);

  }

 

  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)

  {

    super.render(entity, f, f1, f2, f3, f4, f5);

    setRotationAngles(f, f1, f2, f3, f4, f5, entity);

    leg1.render(f5);

    leg2.render(f5);

    leg3.render(f5);

    leg4.render(f5);

    Shape1.render(f5);

  }

 

  private void setRotation(ModelRenderer model, float x, float y, float z)

  {

    model.rotateAngleX = x;

    model.rotateAngleY = y;

    model.rotateAngleZ = z;

  }

 

  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)

  {

    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);

  }

 

}

 

 

RendererTable.java:

 

package com.CptTomm.ms.blocks;

 

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.OpenGlHelper;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.entity.Entity;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

 

import org.lwjgl.opengl.GL11;

 

public class RendererTable extends TileEntitySpecialRenderer {

   

    //The model of your block

    private final ModelTable model;

   

    public RendererTable() {

            this.model = new ModelTable();

    }

   

    private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

            int meta = world.getBlockMetadata(x, y, z);

            GL11.glPushMatrix();

            GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

            GL11.glPopMatrix();

    }

   

    @Override

    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {

    //The PushMatrix tells the renderer to "start" doing something.

            GL11.glPushMatrix();

    //This is setting the initial location.

            GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

    //This is the texture of your block. It's pathed to be the same place as your other blocks here.

            //Outdated bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleRed.png");

  //Use in 1.6.2  this

            ResourceLocation textures = (new ResourceLocation("ms:textures/models/table.png"));

    //the ':' is very important

    //binding the textures

            Minecraft.getMinecraft().renderEngine.bindTexture(textures);

 

    //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                     

            GL11.glPushMatrix();

            GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

    //A reference to your Model file. Again, very important.

            this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

    //Tell it to stop rendering for both the PushMatrix's

            GL11.glPopMatrix();

            GL11.glPopMatrix();

    }

 

    //Set the lighting stuff, so it changes it's brightness properly.     

    private void adjustLightFixture(World world, int i, int j, int k, Block block) {

            Tessellator tess = Tessellator.instance;

            //float brightness = block.getBlockBrightness(world, i, j, k);

            //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue():

            float brightness = block.getLightValue(world, i, j, k);

            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

            int modulousModifier = skyLight % 65536;

            int divModifier = skyLight / 65536;

            tess.setColorOpaque_F(brightness, brightness, brightness);

            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);

    }

}

 

Link to comment
Share on other sites

You mean doing this in ClientProxy:

 

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTable.class, new RendererTable());

 

If it helps here is my ClientProxy and main class

 

Main.java

 

package com.CptTomm.ms;

 

import com.CptTomm.ms.blocks.*;

import com.CptTomm.ms.proxy.CommonProxy;

 

import cpw.mods.fml.client.registry.ClientRegistry;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

 

 

@Mod(modid = "ms", name = "Modern Stuff", version = "0")

public class Main {

 

@Instance(value = "ms")

public static Main instance;

 

@SidedProxy(clientSide = "com.CptTomm.ms.proxy.ClientProxy", serverSide = "com.CptTomm.ms.proxy.CommonProxy")

public static CommonProxy proxy;

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

 

GameRegistry.registerBlock(new BlockTable(), "table");

GameRegistry.registerTileEntity(TileEntityTable.class, "Table");

 

 

}

 

@EventHandler

public void load(FMLInitializationEvent event) {

proxy.registerRenderers();

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event) {

 

}

}

 

 

ClientProxy.java

 

package com.CptTomm.ms.proxy;

 

import com.CptTomm.ms.blocks.*;

 

import cpw.mods.fml.client.registry.ClientRegistry;

import net.minecraftforge.client.MinecraftForgeClient;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

 

public class ClientProxy extends CommonProxy {

       

        @Override

        public void registerRenderers() {

        ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTable.class, new RendererTable());

        }

       

}

 

Link to comment
Share on other sites

public class BlockTable  extends Block {

 

*Cough*

 

You might want to implement ITileEntityProvider or extend BlockContainer.

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

Maybe I don't understand since I'm also new, but why are you making this a TileEntity?  Does it contain items or other data?  Like, are you going to try to set items on the table?  or is it just a block?

 

If you do set stuff on the table and render it so it's visible, let me know how you do it!  :)

hw developer in a sw world

Link to comment
Share on other sites

public class BlockTable  extends Block {

 

*Cough*

 

You might want to implement ITileEntityProvider or extend BlockContainer.

Or override the
hasTileEntity

method to return true.

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/

Link to comment
Share on other sites

Or override the

hasTileEntity

method to return true.

 

Or that, yes.  But really one of the other two would be better (BlockContainer does the

hasTileEntity

for you, the interface makes sure you're providing all of the necessary functions, etc.)

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

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Wait guys, I still don't don't understand... I shall send my code -- Define the function to decrease hunger local function decreaseHunger(player)     local currentHunger = player.getHunger()          -- Check if hunger is not already zero     if currentHunger > 0 then         player.setHunger(currentHunger - 1)     end end -- Register event to decrease hunger over time script.registerEvent(EntityPlayer, function(player)     while true do         -- Decrease hunger every few seconds         decreaseHunger(player)         script.sleep(1000) -- Sleep for 1 second     end end)     Any help appriecated. It's been a while since I learnt Javascript or whatever Minecraft is made with... ... ... ... Nicknotname Hungerinpeaceful xx
    • good days  i get this error: java.lang.ClassCastException: class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer (net.minecraft.client.player.LocalPlayer is in module minecraft@1.20.4 of loader 'TRANSFORMER' @3e8b3b79; net.minecraftforge.common.extensions.IForgeServerPlayer is in module forge@49.0.26 of loader 'TRANSFORMER' @3e8b3b79)     at mercmod.blocks.classes.panel_whit_entity_inside.use(panel_whit_entity_inside.java:576) ~[main/:?] {re:classloading}     at net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase.use(BlockBehaviour.java:826) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.performUseItemOn(MultiPlayerGameMode.java:324) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.lambda$useItemOn$4(MultiPlayerGameMode.java:292) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.startPrediction(MultiPlayerGameMode.java:251) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.useItemOn(MultiPlayerGameMode.java:291) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.startUseItem(Minecraft.java:1799) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.handleKeybinds(Minecraft.java:2083) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.tick(Minecraft.java:1902) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.runTick(Minecraft.java:1216) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.run(Minecraft.java:801) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:234) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} ------------------------------------------------------------------------------------------------------------------   context:  im updating the briefcase from mi mod an i need to make a gui whit this image that gonna be launched from a block and from a item soo im using kapenjoe tutorials  ---------------------------------------------------------------------------------------- The problem is that tutorial is for 1.20.1 and im using 1.20.4 and i really dont get how to call and open the gui from the block nor from the item i made this based on post i made short ago everything seems find but when right click the block to open the gui it crash the game  @Override public InteractionResult use(BlockState blkstate, Level warudo, BlockPos pos, Player pe, InteractionHand hand, BlockHitResult hitresult) {     if(warudo.isClientSide()){         BlockEntity blkentity = warudo.getBlockEntity(pos);         if(blkentity instanceof Panel_BlockEntity){             //   ↓↓↓  open the menu from the block              IForgeServerPlayer ifpe = (IForgeServerPlayer)pe; //<--- this is wrong  "class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer"             ifpe.openMenu( (Panel_BlockEntity) blkentity, pos ); //<-- i need an example of how open a gui in 1.20.4         }     } return InteractionResult.sidedSuccess(warudo.isClientSide()); } Theres nothing highlighted in red in the code like everything where right an possible but dont works  ####################################################################################################### i need to see an example, just the piece of code for the use() method of the block whit the block entity for 1.20.4  and the same  but for the item     @Override     public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level warudo, @NotNull Player pe, @NotNull InteractionHand interactionHand)     {         if (!warudo.isClientSide())         {             ItemStack heldItem = pe.getItemInHand(interactionHand);                          if (heldItem.getCapability(ForgeCapabilities.ITEM_HANDLER).isPresent())             {                 //   ↓↓↓  open the menu from the item                 NetworkHooks.openScreen((ServerPlayer) pe, this);             }         }         return super.use(warudo, pe, interactionHand);     }   thanks for your attention           
    • It depends on the data you want to save, but generally speaking you should use some custom Player Capabilities, attach to the Player and use them to store/retrieve any kind of data you want. You can find how to make them work for 1.20.x in the documentation here: https://docs.minecraftforge.net/en/latest/datastorage/capabilities/
  • Topics

×
×
  • Create New...

Important Information

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