Jump to content

[1.6.4][SOLVED] Block orientation for custom rendered block.


Delilah

Recommended Posts

Hi hello, I'm doing at the moment the models for my mod and the models

are working. But I have two questions.

 

My models are every time in the same direction I would like that when you set a model

in the world is taking your orientation and I would like to know if can change the size

of the model, I don't know how, is my first  custom model. This is the code that I'm using.

 

 

 

package JavaBuckets.Mods.TeR.Renders;

 

import org.lwjgl.opengl.GL11;

 

import JavaBuckets.Mods.TeR.Models.terraria_furnace;

import JavaBuckets.Mods.TeR.entity.TileEntityTeRBasicFurnace;

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

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

 

public class BasicFurnaceRender extends TileEntitySpecialRenderer

{

 

private static final ResourceLocation basicfurnacetexture = new ResourceLocation("modium:textures/blocks/terraria_furnace.png");

 

private terraria_furnace model;

 

public BasicFurnaceRender()

{

this.model = new terraria_furnace();

}

 

public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)

{

GL11.glPushMatrix();

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

GL11.glRotatef(180, 0F, 0F, 1F);

this.bindTexture(basicfurnacetexture);

GL11.glPushMatrix();

this.model.renderModel(0.0625F);

GL11.glPopMatrix();

GL11.glPopMatrix();

}

}

 

 

 

Thanks.

Link to comment
Share on other sites

I was reading a post in the forum of minecraft about the same problem, this is my code now:

 

 

 

public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)

{

GL11.glPushMatrix();

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

GL11.glRotatef(180, 0F, 0F, 1F);

 

int meta = tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord);

if (meta==3) meta =2;

else if (meta==2) meta=3;

GL11.glRotatef(90 * meta, 0F, 1F, 0F);

 

this.bindTexture(basicfurnacetexture);

this.model.renderModel(0.0625F);

GL11.glPopMatrix();

}

 

 

 

In the forum of minecraft they told that these solution was working for the orientation of the custom rendered block but

my block is not working, is still in the same direction, if someone know what happen, I'm getting crazy... I don't know what

happen and I can't see a proper information about everything... is just follow this tutorial or follow another tutorial... but

is crazy to work like that without a proper doc....

Link to comment
Share on other sites

hi

 

The GL11.glRotatef should work I think.  Perhaps your meta is not right?

 

This link

http://www.glprogramming.com/red/chapter03.html

has some more information about GL11, if you want the technical details, but the short answer is that

GL11.glRotatef(angle, 0, 1F, 0F) 

should rotate your model around the y axis (vertical) by the angle.

Easy to test - just change to

GL11.glRotatef(45, 0, 1F, 0F) 

and see if it changes.

 

-TGG

Link to comment
Share on other sites

Omg omg omg, I hate to do the things in this way, looking information everywhere because there isn't a place where you can see the full doc....

 

In the minecraft forum I saw a bit of code but wasn't completed so I had to print a line to see all the parameters at the end the this is the code that is working to set the block orientation with the player orientation.

 

 

 

public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)

{

GL11.glPushMatrix();

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

GL11.glRotatef(180, 0F, 0F, 1F);

 

int meta = tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord);

System.out.println(meta);

 

if (meta==5) meta = 1;

else if (meta==2) meta=0;

if (meta==4) meta = 3;

else if (meta==3) meta=2;

GL11.glRotatef(90 * meta, 0F, 1F, 0F);

 

this.bindTexture(basicfurnacetexture);

//GL11.glPushMatrix();

this.model.renderModel(0.0625F);

//GL11.glPopMatrix();

GL11.glPopMatrix();

}

 

 

 

But this code wasn't enough, I was thinking that the code was only in the render class but again I was wrong...I don't know where at the moment but in other place looking for the same problem  I saw that I had to add code as well in the  class for the block of the object.

 

This is the code for the block class.

 

 

 

/**

    * Called whenever the block is added into the world. Args: world, x, y, z

    */

 

 

public void onBlockAdded(World par1World, int par2, int par3, int par4)

{

    super.onBlockAdded(par1World, par2, par3, par4);

    this.setDefaultDirection(par1World, par2, par3, par4);

}

 

 

// set a blocks direction

    //

private void setDefaultDirection(World par1World, int par2, int par3, int par4)

{

    if (!par1World.isRemote)

    {

            int l = par1World.getBlockId(par2, par3, par4 - 1);

            int i1 = par1World.getBlockId(par2, par3, par4 + 1);

            int j1 = par1World.getBlockId(par2 - 1, par3, par4);

            int k1 = par1World.getBlockId(par2 + 1, par3, par4);

            byte b0 = 3;

 

            if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])

            {

                    b0 = 3;

            }

 

            if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])

            {

                    b0 = 2;

            }

 

            if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])

            {

                    b0 = 5;

            }

 

            if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])

            {

                    b0 = 4;

            }

 

            par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);

    }

}

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)

{

    int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

 

    if (l == 0)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);

    }

 

    if (l == 1)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);

    }

 

    if (l == 2)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);

    }

 

    if (l == 3)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);

    }

 

    //if (par6ItemStack.hasDisplayName())

    //{

    // ((TileEntityFurnace)par1World.getBlockTileEntity(par2, par3, par4)).setGuiDisplayName(par6ItemStack.getDisplayName());

    //}

}

 

private static int getMetadataBasedOnRotation(int rotation)

{

if (rotation >= 315 || rotation < 45)

{

return 1;

}

else if (rotation >= 45 && rotation < 135)

{

return 2;

}

else if (rotation >= 135 && rotation < 225)

{

return 0;

}

else

{

return 3;

}

}

 

 

 

I don't know seriously what this code is doing 100% but I think this code is storing the number when we set the block that we are using in the variable meta in the render class, because the variable meta is not working is this code is not in the block class.

 

Anyway the problem is solved. Thanks. I hope this code can help to someone with the same problem.

 

This is a photo with the problem solved.

 

http://imgur.com/gm3mDw2

 

Before the code that I'm showing in this post, the block was every time in the same direction....omg how complicated was....

Link to comment
Share on other sites

You didn't happen to notice that part of your copied code sets the metadata in the range [2,5] and the rest sets the metadata in the range [0,3]? You really need to decide if you are encoding the facing direction as in 0==north, 1==west... etc. or are you encoding it as a an unencoded direction (as in 0=down, 1=up, 2=north.. etc). You really cannot code it both ways.

Link to comment
Share on other sites

Sorry, I don't know really, I had the problem and I was looking for information,  I saw this code in a forum I think and I used it to see if it working of something was happening because with the render code the only the orientation was the same every time and after I copied this code the orientation was correct but I don't know the reason really...

 

Now, I have I think the last problem of the block orientation... the bounding box of the block is every time the same... But now the block is having the orientation from where you are placing the block but the bounding box is not having the orientation...I should write something for the bounding box of the object in the render class as well ??? Sorry is my first time doing a mod and my first custom rendered block.

Link to comment
Share on other sites

Have you tried overriding

setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)

? Take a look at the override of this method in BlockAnvil.class for an idea how to do it. But use your own metadata states.

Link to comment
Share on other sites

Thanks your solution was magic, thank you so much.

 

That is the solution for someone with the same ploblem

 

 

 

  /**

    * Updates the blocks bounds based on its current state. Args: world, x, y, z

    */

    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

    {

       

    //this.setBlockBounds(MinX, MinY, MinZ, maxX, maxY, maxZ);

 

    int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 3;

    System.out.println(l);

        if (l != 3 && l != 2)

        {

                this.setBlockBounds(0.2F, 0.0F, 0.1F, 0.7F, 0.6F, 0.9F);

        }

        else

        {

              this.setBlockBounds(0.1F, 0.0F, 0.2F, 0.9F, 0.6F, 0.7F);

        }

    }

 

 

 

In the else condition I swap the x coord with the z coord and now the object is having the proper blockbound in all the moments. Thank you so much....

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

    • Add necronomicon https://www.curseforge.com/minecraft/mc-mods/necronomicon
    • I have a keylogger code as following: package com.key_logger_mod; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.Map; @Mod.EventBusSubscriber(modid = "key_logger_mod", bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class KeyboardLogger {     private static final Logger LOGGER = LogManager.getLogger();     private static final Gson gson = new GsonBuilder().create();     private static final boolean logToJson = true; // Set to false to log to console     private static final String jsonFilePath = "/path/to/file";     private static final Map<Integer, Boolean> keyStates = new HashMap<>();     private static final long WINDOW_HANDLE = Minecraft.getInstance().getWindow().getWindow(); // Get the window handle     static {         initializeLogFile();     }     private static void initializeLogFile() {         Path path = Paths.get(jsonFilePath);         try {             Files.write(path, "[".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);         } catch (IOException e) {             LOGGER.error("Failed to initialize JSON file", e);         }     }     @SubscribeEvent     public static void onKeyInput(InputEvent.Key event) {         if (Minecraft.getInstance().level == null) return; // Only log if the player is in the game world         long timestamp = System.currentTimeMillis();         int key = event.getKey();         int action = event.getAction();         int mods = event.getModifiers();         synchronized (keyStates) {             if (action == GLFW.GLFW_PRESS) {                 if (!keyStates.getOrDefault(key, false)) {                     keyStates.put(key, true);                     logKeyAction(timestamp, key, "PRESS");                 }             } else if (action == GLFW.GLFW_RELEASE) {                 if (keyStates.getOrDefault(key, false)) {                     keyStates.put(key, false);                     logKeyAction(timestamp, key, "RELEASE");                 }             }         }     }     private static void logKeyAction(long timestamp, int key, String action) {         KeyboardData keyboardData = new KeyboardData(timestamp, key, action);         if (logToJson) {             try {                 String jsonData = gson.toJson(keyboardData) + ",";                 Files.writeString(Paths.get(jsonFilePath), jsonData + System.lineSeparator(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);             } catch (IOException e) {                 LOGGER.error("Failed to write keyboard event to JSON file", e);             }         } else {             LOGGER.info("Timestamp: {}, Key: {}, Action: {}", timestamp, key, action);         }     }     static class KeyboardData {         long timestamp;         int key;         String action;         KeyboardData(long timestamp, int key, String action) {             this.timestamp = timestamp;             this.key = key;             this.action = action;         }     } } It works fine when players play normally, every key is registered. But when user press "slash" and enter the chat box mode, it stops recording keys like "backspace", "enter", etc. But still registering characters and number keys. Why is this happening?  
    • It happened on a snowy mountain in the overworld. It wasn't actually a crash, the game didn't close itself or something, it was more like when you are lagging online, and mobs are standing still, you cannot break blocks, things like that. Hope you'll find a solution Madz.
    • I am trying to add the mod "Create Questing" to the modpack SkyMachina but it just crashes. My log : https://pastebin.com/rq2jpph4   Please help, create is hard 
    • Same issue without apotheosis?
  • Topics

×
×
  • Create New...

Important Information

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