Jump to content

Custom rendered block renders weird


gmod622

Recommended Posts

Hello! Today i made a custom modeled block and it came out like this:

 

NHqQdmK.png

 

 

I really dont know why.

 

 

Here is my code:

 

Main file

 

 

 package mod.gmod622.main;

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import mod.gmod622.Provider.WorldProviderZeCraft;
import mod.gmod622.biome.BiomeGenZecraft;
import mod.gmod622.block.TestBlockClass;
import mod.gmod622.block.ZeDirtBlockClass;
import mod.gmod622.block.ZeFireBlockClass;
import mod.gmod622.block.ZeGrassBlockClass;
import mod.gmod622.block.ZePortalBlockClass;
import mod.gmod622.block.ZeStoneBlockClass;
import mod.gmod622.block.ZeTableBlockClass;
import mod.gmod622.item.EnchaterItemClass;
import mod.gmod622.item.ZeAndSteelItemClass;
import mod.gmod622.item.ZePortalItemClass;
import mod.gmod622.main.client.ClientProxy;
import mod.gmod622.renderer.TileEntityZeTableRenderer;
import mod.gmod622.tile.TileEntityZeTableEntity;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.Property;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@Mod(modid = mod_ZeCraft.modid, name = "ZeCraft", version = "0.0.0.1a")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class mod_ZeCraft
{
       public static final String modid = "ZeCraft";
       
       public static int DimID = 2;

       
       public static final int ZeGrassID = 253;
       public static final int ZeDirtID = 252;
       public static final int ZeStoneID = 251;
public static final int TestBlockID = 3615;
    public static final int ZeTableID = 3621;
    public static final int ZePortalID = 3616;
    public static final int ZePortalItemID = 3617;
    public static final int EnchaterItemID = 3618;
    public static final int ZeAndSteelID = 3619;
    public static final int ZeFireID = 3620;


    
    public static BiomeGenBase ZeBiome;

       public static Block TestBlock;
       public static Block ZeGrass;
       public static Block ZeFire;
       public static Block ZeDirt;
       public static Block ZeTable;
       public static Block ZeStone;
       public static Block ZePortal;
       public static Item ZePortalItem;
       public static Item ZeAndSteel;
       public static Item Enchanter;
       


    	   

       
   
       

      
       @Init
       public void load(FMLInitializationEvent event)
       {
    	   
    	   //Block implemtation 
   		TestBlock = new TestBlockClass(TestBlockID, Material.rock).setUnlocalizedName("ZeCraft:TestBlock").setStepSound(Block.soundMetalFootstep).setHardness(0.2F).setResistance(10.0F);

   		ZeDirt = new ZeDirtBlockClass(ZeDirtID, Material.ground).setUnlocalizedName("ZeCraft:ZeDirt").setHardness(0.9F).setStepSound(Block.soundGrassFootstep);              
   		ZeGrass = new ZeGrassBlockClass(ZeGrassID, Material.grass).setUnlocalizedName("ZeCraft:ZeGrass").setHardness(0.9F).setStepSound(Block.soundGrassFootstep);              
   		ZeStone = new ZeStoneBlockClass(ZeStoneID, Material.ground).setUnlocalizedName("ZeCraft:ZeStone").setHardness(0.9F).setStepSound(Block.soundStoneFootstep);              
   		ZeTable = new ZeTableBlockClass(ZeTableID).setUnlocalizedName("ZeCraft:ZeTable").setHardness(1.5F);

   		
    	//Item implematation
    	ZePortalItem = new ZePortalItemClass(ZePortalItemID).setUnlocalizedName("ZeCraft:ZePortalItem");
    	ZeAndSteel = new ZeAndSteelItemClass(ZeAndSteelID).setUnlocalizedName("ZeCraft:ZeAndSteel");
   		Enchanter = new EnchaterItemClass(EnchaterItemID).setUnlocalizedName("ZeCraft:EnchanterItem");
   		
   		   //Block Registry
   		
    	   GameRegistry.registerBlock(TestBlock, "Test Block");
    	   LanguageRegistry.addName(TestBlock, "Test Block");
    	   
    	   GameRegistry.registerBlock(ZeGrass, "Ze-Grass");
    	   LanguageRegistry.addName(ZeGrass, "Ze-Grass");
    	   
    	   GameRegistry.registerBlock(ZeStone, "Ze-Stone");
    	   LanguageRegistry.addName(ZeStone, "Ze-Stone");
    	   
    	   GameRegistry.registerBlock(ZeDirt, "Ze-Dirt");
    	   LanguageRegistry.addName(ZeDirt, "Ze-Dirt");
    	   
    	   GameRegistry.registerBlock(ZeTable, "ZeTable");
    	   LanguageRegistry.addName(ZeTable, "ZeTable");
    	   
    	 //  GameRegistry.registerBlock(ZePortal, "Ze-Portal");
    	//   LanguageRegistry.addName(ZePortal, "Ze-Portal");
    	   
    	//   GameRegistry.registerBlock(ZeFire, "ZeFire");
    	//   LanguageRegistry.addName(ZeFire, "ZeFire");
    	   
    	   //Item Registry
    	   GameRegistry.registerItem(ZePortalItem, "Ze-Portal Item");
    	   LanguageRegistry.addName(ZePortalItem, "Ze-Portal Item");
    	   
    	   GameRegistry.registerItem(ZeAndSteel, "Ze And Steel");
    	   LanguageRegistry.addName(ZeAndSteel, "Ze And Steel");
    	   
    	   
    	   //Other Registry
    	   
    	   ZeBiome = new BiomeGenZecraft(DimID).setBiomeName("Ze-Biome");
           GameRegistry.registerTileEntity(TileEntityZeTableEntity.class, "tileEntityZeTable");
           ClientProxy.registerRenderThings();
           
    	   //Randoms
    	   
    	   someConfigFlag = false;
    	   
    	   
    	   
    	   //Dim
    	   /**Register WorldProvider for Dimension **/
    	   DimensionManager.registerProviderType(DimID, WorldProviderZeCraft.class, true);
    	   DimensionManager.registerDimension(DimID, DimID);
       
       }
       

       
       
       @PreInit
       public void preInit(FMLPreInitializationEvent event) {
               Configuration config = new Configuration(event.getSuggestedConfigurationFile());

               config.load();

               int randomBlockID = config.getBlock("TestBlock", TestBlockID).getInt();

//               int randomItemID = config.getItem("RandomItem", 20000).getInt();

               // Since this flag is a boolean, we can read it into the variable directly from the config.
               someConfigFlag = config.get(Configuration.CATEGORY_GENERAL, "SomeConfigFlag", false).getBoolean(false);
               
               //Notice there is nothing that gets the value of this property so the expression results in a Property object.
               Property someProperty = config.get(Configuration.CATEGORY_GENERAL, "SomeConfigString", "nothing");
               
               // Here we add a comment to our new property.
               someProperty.comment = "IDK CONFIG";
               
             //  String someConfigString = someProperty.value;
               // this could also be:
               // int someInt = someProperty.getInt();
               // boolean someBoolean = someProperty.getBoolean(true);

               config.save();
       }
    	 
       
       
       

       
       
       //Sounds
    /*   
       @ForgeSubscribe
       public void onSound(SoundLoadEvent event)
       {
           try 
           {
               event.manager.soundPoolSounds.addSound("");            
           
           } 
           catch (Exception e)
           {
               System.err.println("Failed to register one or more sounds.");
           }
       }
       
       */
       
       //--

       
       public static boolean someConfigFlag;
}

 

 

Block Class:

 

 

 package mod.gmod622.block;

import mod.gmod622.tile.TileEntityZeTableEntity;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;


public class ZeTableBlockClass extends BlockContainer {

        //Treat it like a normal block here. The Block Bounds are a good idea - the first three are X Y and Z of the botton-left corner,
        //And the second three are the top-right corner.
        public ZeTableBlockClass(int id) {
                super(id, Material.iron);
                this.setCreativeTab(CreativeTabs.tabBlock);
                this.setBlockBounds(0.4F, 0.0F, 0.4F, 0.6F, 3.0F, 0.6F);
        }

        //Make sure you set this as your TileEntity class relevant for the block!
        @Override
        public TileEntity createNewTileEntity(World world) {
                return new TileEntityZeTableEntity();
        }
        
        //You don't want the normal render type, or it wont render properly.
        @Override
        public int getRenderType() {
                return -1;
        }
        
        //It's not an opaque cube, so you need this.
        @Override
        public boolean isOpaqueCube() {
                return false;
        }
        
        //It's not a normal block, so you need this too.
        public boolean renderAsNormalBlock() {
                return false;
        }
        
        //This is the icon to use for showing the block in your hand.
        public void registerIcons(IconRegister icon) {
                this.blockIcon = icon.registerIcon("ZeCraft:ZeTableTexture");
        }

} 

 

 

TileEntity :

 

 

 package mod.gmod622.tile;

import net.minecraft.tileentity.TileEntity;

public class TileEntityZeTableEntity extends TileEntity {

}

 

 

TileEntityRenderer:

 

 

 package mod.gmod622.renderer;

import org.lwjgl.opengl.GL11;

import mod.gmod622.model.ZeTableModel;
import net.minecraft.block.Block;
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.world.World;

public class TileEntityZeTableRenderer extends TileEntitySpecialRenderer {
    
    //The model of your block
    private final ZeTableModel model;
    
    public TileEntityZeTableRenderer() {
            this.model = new ZeTableModel();
    }
    
    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.
         //   bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleRed.png");
    //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);
            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);
    }
} 

 

 

 

And then the model:

 

 

 package mod.gmod622.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ZeTableModel extends ModelBase
{
  //fields
    ModelRenderer Leg4;
    ModelRenderer Leg3;
    ModelRenderer Leg2;
    ModelRenderer Leg1;
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
  
  public ZeTableModel()
  {
    textureWidth = 64;
    textureHeight = 64;
    
      Leg4 = new ModelRenderer(this, 0, 0);
      Leg4.addBox(0F, 0F, 0F, 1, 13, 1);
      Leg4.setRotationPoint(-8F, 11F, -8F);
      Leg4.setTextureSize(64, 64);
      Leg4.mirror = true;
      setRotation(Leg4, 0F, 0F, 0F);
      Leg3 = new ModelRenderer(this, 5, 15);
      Leg3.addBox(0F, 0F, 0F, 1, 13, 1);
      Leg3.setRotationPoint(7F, 11F, -8F);
      Leg3.setTextureSize(64, 64);
      Leg3.mirror = true;
      setRotation(Leg3, 0F, 0F, 0F);
      Leg2 = new ModelRenderer(this, 5, 0);
      Leg2.addBox(0F, 0F, 0F, 1, 13, 1);
      Leg2.setRotationPoint(7F, 11F, 7F);
      Leg2.setTextureSize(64, 64);
      Leg2.mirror = true;
      setRotation(Leg2, 0F, 0F, 0F);
      Leg1 = new ModelRenderer(this, 0, 15);
      Leg1.addBox(0F, 0F, 0F, 1, 13, 1);
      Leg1.setRotationPoint(-8F, 11F, 7F);
      Leg1.setTextureSize(64, 64);
      Leg1.mirror = true;
      setRotation(Leg1, 0F, 0F, 0F);
      Shape1 = new ModelRenderer(this, 0, 36);
      Shape1.addBox(0F, 0F, 0F, 16, 2, 16);
      Shape1.setRotationPoint(-8F, 10F, -8F);
      Shape1.setTextureSize(64, 64);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
      Shape2 = new ModelRenderer(this, 0, 0);
      Shape2.addBox(0F, 0F, 0F, 1, 3, 1);
      Shape2.setRotationPoint(0F, 12F, 0F);
      Shape2.setTextureSize(64, 64);
      Shape2.mirror = true;
      setRotation(Shape2, 0F, 0F, 0F);
      Shape3 = new ModelRenderer(this, 0, 0);
      Shape3.addBox(0F, 0F, 0F, 1, 1, 5);
      Shape3.setRotationPoint(0F, 14F, 1F);
      Shape3.setTextureSize(64, 64);
      Shape3.mirror = true;
      setRotation(Shape3, 0F, 0F, 0F);
      Shape4 = new ModelRenderer(this, 0, 0);
      Shape4.addBox(0F, 0F, 0F, 1, 1, 5);
      Shape4.setRotationPoint(0F, 14F, -5F);
      Shape4.setTextureSize(64, 64);
      Shape4.mirror = true;
      setRotation(Shape4, 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);
    Leg4.render(f5);
    Leg3.render(f5);
    Leg2.render(f5);
    Leg1.render(f5);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape2.render(f5);
    Shape2.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);
  }

} 

 

Not new to java >> New to modding.

Link to comment
Share on other sites

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();
    }

^ this method does nothing

 

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

this line is commented so its using the last texture binded to openGL

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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

    • im stuck in a problem whit BlockEntities i cannot solve so im trying to work around it but in the less complex way possible  i think is posible to store data to the minecraft world  in older versions people talk about  WordDataSave i dont find anything about it for 1.20.4  i find a tutorial for player capability in 1.19    here is an event      //########## ########## ########## ##########     @SubscribeEvent     public static void onAttachCapabilitiesPlayer(AttachCapabilitiesEvent<Entity> event) {         if(event.getObject() instanceof Player) {             if(!event.getObject().getCapability(PlayerThirstProvider.PLAYER_THIRST).isPresent()) {                 event.addCapability(new ResourceLocation(mercmod.MOD_ID, "properties"), new PlayerThirstProvider());             }         }     }  soo i made this      //########## ########## ########## ##########     @SubscribeEvent     public static void onAttachCapabilitiesLevel(AttachCapabilitiesEvent<Level> event) {     } i think i can do some witchcraft  here  but is many things don't understand  to start whit i dont get yet how to recall the saved data from a BlockEntity  the handler still in progress the plan is to make a Map to store nbt data using the block coordinates as index later store that map as a big nbt      ########## any way the question is if theres alredy a tutorial for 1.20.4 for this ?? or some alredy working code from someone else doing something similar ?           
    • I tried this, and found out that Oculus is the mod that is crashing the game. I have removed it, and it now works fine! Thanks!
    • Hi @DanielderErbauer, I arrived here as I have the "as it does not exist in Block{minecraft:air}" error in a modpack I am trying to start. It's a long-shot, I know, but as the post that led this to being solved is missing, can I ask if you may recall what it said? Thanks in advance
    • Hm yeah sorry, not seeing anything else that's sticking out, I'd need to debug myself probably. Do you have a github or bitbucket repo? I could poke around when I have time to see what the problem might be.
    • looking around for the capabilities thing i found a piece of code and find this piece of code  //########## ########## ########## ########## @SubscribeEvent public static void addCustomTrades(VillagerTradesEvent event) { if(event.getType() == VillagerProfession.FLETCHER) { System.out.println("\n\n### VillagerProfession.FLETCHER \n\n");//<----------- Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = event.getTrades(); ItemStack stack = new ItemStack(ItemInit.ARROW_STEEL.get(), 16); int villagerLevel = 1; trades.get(villagerLevel).add((trader, rand) -> new MerchantOffer( new ItemStack(Items.EMERALD, 2), stack,1,3,0.02F)); } if(event.getType() == VillagerProfession.TOOLSMITH) { System.out.println("\n\n### VillagerProfession.TOOLSMITH \n\n");//<----------- Int2ObjectMap<List<VillagerTrades.ItemListing>> trades = event.getTrades(); ItemStack stack = new ItemStack(ItemInit.INGOT_STEEL.get(), 1); int villagerLevel = 1; trades.get(villagerLevel).add((trader, rand) -> new MerchantOffer( new ItemStack(Items.EMERALD, 2), stack,10,8,0.02F)); } } //########## ########## ########## ########## the event is aknoledge and execute when the maps load  ### VillagerProfession.FLETCHER  ### VillagerProfession.TOOLSMITH  //########## But is not working      is a random piece of code is not working  could it be than this code is old 1.18 and no valid anymore for 1.20.4 or the thing are this numbers  stack,10,8,0.02F));  i dont know what this numbers means    ########## the question is ¿how to add things to the villager traders    thanks for your attention               
  • Topics

×
×
  • Create New...

Important Information

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