Jump to content

[1.8]rotate your custome blocks based on steve facing like Furnaces do<SOLVED>


Recommended Posts

Posted

Good days

this is a little long to explain to reach where mi questions are.

 

first , the 1.8 is using a new and more simple system to change the orientation of the blocks , i gonna use the furnace to explain whath i have

 

the Block state system

it let you just define how to rotate all the faces of a block in just one single json file, this mean that i have not anymore to define manually where go all te faces of block on every case of rotation like in 1.7 whith  getIcon

 

_______________________________________________
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {	
   
int tex=(meta*6)+(side);

//System.out.println("side="+side+" meta="+meta+" tex="+tex);
if (tex < icons.length ){return icons[tex];}
                     else{return icons[0];}

} // fin de IIcon getIcon
_______________________________________________

 

 

now go forth to 1.8

the furnace Blockstate file define 4 posible rotations simply rotating textures on the Y axix

 

~/.minecraft/versions/1.8/1.8/assets/minecraft/blockstates/furnace.json

{
    "variants": {
        "facing=north": { "model": "furnace" },
        "facing=south": { "model": "furnace", "y": 180 },
        "facing=west":  { "model": "furnace", "y": 270 },
        "facing=east":  { "model": "furnace", "y": 90 }
    }
}

 

the mojan's store this Values  in a custom  Object named "IBlockState" and this is the center point of this post

 

 

i create a custom multitexture block named girable looks like a red dice and i copy the furnace blockstate json for this block ,

~/Modding/forge-1.8-11.14.0.1261-1.8-src/src/main/resources/assets/modmercenario/blockstates/girable.json

{
    "variants": {
        "facing=north": { "model": "modmercenario:girable" },
        "facing=south": { "model": "modmercenario:girable", "y": 180 },
        "facing=west":  { "model": "modmercenario:girable", "y": 270 },
        "facing=east":  { "model": "modmercenario:girable", "y": 90 }
    }
}

 

the blocks load and all his textures are on place when i put it on the world and is a red dice

iwant this block to behabe like te furnace seting the face number 2 looking to the player no mather if a look to south or to the east

 

there comes again the Iblockstate object

 

if i wanna set in the world a furnace looking to south  i need the blocks.furnace object + the iblockstate of the furnace looking to south =  "facing=south"

 

thats the part i dont get and find hard to explain something i dont get

 

 

 

if there is a furnace looking to south in the world i can do a

IBlockState rot = worldIn.getBlockState(pos0);  //i alredy have the coordenates of the furnace stored in pos0

 

whith this i have a objet named rot which contains the blocks.furnace + the iblockstate="facing=south"

whit this i can put it wherever i wan whit

 

worldIn.setBlockState(posX, rot);

 

 

lets say i wanna put on world a furnace looking to east but there is not another east loking furnace in the world

or mi girable block

how i load the an object of iblockstate whit the value "facing=east"

 

IBlockState east = "facing=east" ; dont work, it contains Strings but not behave like an String object

soo idont find a suitable way to load IBlockState whit a custom value

 

 

or it musb be like

¿ how i get the fourth  IBlockState objets reprensenting the four states of mi customblock girable? 

 

 

 

 

 

 

 

 

 

 

 

Posted

this cost me a lot of time to figuret out

 

cos has become very more complex of what was in 1.7

 

to spawn this block in the world i must do call

 

		
IBlockState gira = MercenaryModBlocks.girable.getDefaultState();
worldIn.setBlockState(pos , gira);

// spawn it whith a custom orientation.

//looking south
worldIn.setBlockState(pos, gira.withProperty(FACING, EnumFacing.SOUTH), 2);

//looking east
worldIn.setBlockState(pos, gira.withProperty(FACING, EnumFacing.EAST), 2);

//looking up
worldIn.setBlockState(pos , gira.withProperty(FACING, EnumFacing.UP), 2);

 

 

this is the class of one simple multitexture block

 

package mercenarymod.blocks.multitextura;

import java.util.Random;

import org.apache.logging.log4j.core.config.Property;

import mercenarymod.Mercenary;
import mercenarymod.blocks.MercenaryModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import mercenarymod.utilidades.chat;
import net.minecraft.entity.EntityLivingBase;






public class girable extends Block
{
    public static String name = "girable";

    public static final PropertyDirection FACING = PropertyDirection.create("facing");

    public girable()
    {
    	super(Material.glass);
        setUnlocalizedName(Mercenary.MODID + "_" + name);
        GameRegistry.registerBlock(this, name);
        setCreativeTab(Mercenary.herramientas);
        //this.maxStackSize = 1;
    }

    
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(MercenaryModBlocks.girable);
    }
    
    
  //###########################################################3
    
    public boolean isOpaqueCube()
    {
        return false;
    }

   
    public boolean isFullCube()
    {
        return false;
    }
  //###########################################################3
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	
    	
    	System.out.println("NU SE QUE SERA \n YA tengo una idea de que es ="+FACING);
    	

    	Block fur = Blocks.furnace;
    	
    	fur.getActualState(state, worldIn, pos);
    	IBlockState state1 = fur.getDefaultState();
    	    	
    	//worldIn.setBlockState(pos, state);
    	
    	
	worldIn.setBlockState(pos, state.withProperty(FACING, side), 2);
    
    	    	
    	
    return false;}
    
  //###########################################################3

    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
    {
    	
    }
    
  //###########################################################3
    
    
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        worldIn.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(worldIn, pos, placer)), 2);

     
    }
    
  //###########################################################3    
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, getFacingFromEntity(worldIn, pos, placer));
    }
    
  //###########################################################3    
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

       
            float f = 0.25F;
            EnumFacing enumfacing = (EnumFacing)iblockstate.getValue(FACING);

            if (enumfacing != null)
            {
                switch (troncoMercenario.SwitchEnumFacing.FACING_LOOKUP[enumfacing.ordinal()])
                {
                    case 1:
                        this.setBlockBounds(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 2:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
                        break;
                    case 3:
                        this.setBlockBounds(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 4:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
                        break;
                    case 5:
                        this.setBlockBounds(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 6:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
                }
            }
        
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
    }

  //###########################################################3  
    public void setBlockBoundsForItemRender()
    {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }    
        
  //###########################################################3  
    
    public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
    {
        if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
        {
            double d0 = entityIn.posY + (double)entityIn.getEyeHeight();

            if (d0 - (double)clickedBlock.getY() > 2.0D)
            {
                return EnumFacing.UP;
            }

            if ((double)clickedBlock.getY() - d0 > 0.0D)
            {
                return EnumFacing.DOWN;
            }
        }

        return entityIn.getHorizontalFacing().getOpposite();
    } 
  
  //###########################################################3     
    
    @SideOnly(Side.CLIENT)
    public IBlockState getStateForEntityRender(IBlockState state)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.UP);
    }
    
    //###########################################################3
    
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {FACING});
    }
    
    //###########################################################3
    
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0 | ((EnumFacing)state.getValue(FACING)).getIndex();

       
        return i;
    }
    
    //###########################################################3
    
    static final class SwitchEnumFacing
    {
        static final int[] FACING_LOOKUP = new int[EnumFacing.values().length];
        private static final String __OBFID = "CL_00002037";

        static
        {
            try
            {
                FACING_LOOKUP[EnumFacing.DOWN.ordinal()] = 1;
            }
            catch (NoSuchFieldError var6)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.UP.ordinal()] = 2;
            }
            catch (NoSuchFieldError var5)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 3;
            }
            catch (NoSuchFieldError var4)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 4;
            }
            catch (NoSuchFieldError var3)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 5;
            }
            catch (NoSuchFieldError var2)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 6;
            }
            catch (NoSuchFieldError var1)
            {
                ;
            }
        }
    }
   
    //###########################################################3
    
    
    //###########################################################3
    
    
    
    
}//fin de la clase

 

 

el blockState

girable.json

{
    "variants": {
        "normal": { "model": "modmercenario:multicara" },

"facing=north": { "model": "modmercenario:multicara" },
        "facing=south": { "model": "modmercenario:multicara", "y": 180 },
        "facing=west":  { "model": "modmercenario:multicara", "y": 270 },
        "facing=east":  { "model": "modmercenario:multicara", "y": 90 },
"facing=down":  { "model": "modmercenario:multicara", "x": 90 },
"facing=up":    { "model": "modmercenario:multicara", "x": 270 }
    
}}

 

el block model y item model

 

girable.json

{
    "parent": "modmercenario:block/cube",
    "textures": {

"down":  "modmercenario:blocks/metablockes/metablockemercenario18",
"up":    "modmercenario:blocks/metablockes/metablockemercenario19",
"north": "modmercenario:blocks/metablockes/metablockemercenario20",
"south": "modmercenario:blocks/metablockes/metablockemercenario21",
"west":  "modmercenario:blocks/metablockes/metablockemercenario22",
"east":  "modmercenario:blocks/metablockes/metablockemercenario23"

    }
}

Posted

I have yet to see any sensible reason why BlockPostion and BlockState was adopted over x/y/z and metadata.  A modder still needs to translate from block state to metadata and back (or in some cases other states modifying values in a tile entity).

 

Texturing likewise got more complicated and as of yet there's no sensible way to register textures either.  I mean seriously:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(obliteratorAxe, 0, new ModelResourceLocation("perstools:obliteratorAxe", "inventory"));

 

WTF.

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

100% agree. I mean, I guess that it's cool someone can come along and edit the .json file and bam, suddenly your sword is 10x bigger and renders backwards, but I much preferred handling everything directly in code. Blocks are a complete nightmare now, and certainly do not appear 'optimized' - arguably the exact opposite of optimized. I'm hoping that we will see a return to common sense sometime in the future, but I fear we will be stuck with this nonsense...

Posted

E nop

i am the one suffering here but i get somethink

 

the are making it simply to not have to fuck up whith gl11 or tessellators but ,there is no documentation which would be very nice,  actualy i get the  idea, now is more simple to rotate and reescalated items, two days ago i found how to make layer textures whith the items and you can combine animated textures whith static textutes just defining in the layers in the json , i have the teory that is posible to use layers on block texturex and the key in the class snow layer but io have not realize yet how to set the layers in blocks json

 

 

suspensionderedstone.json

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "modmercenario:items/redstone/redstoneNIvel8"
        "layer1": "modmercenario:items/redstone/botellaVacia"

    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

 

 

in the other hand it will be nice if they make minecraft to atomatically register al the jsons in the models folder

and shorten the code to set which item/block has which texture in inventory

setTexture(ItemBlock,0 ,file.json);  //but this what i doit  in mi register class

Posted

100% agree. I mean, I guess that it's cool someone can come along and edit the .json file and bam, suddenly your sword is 10x bigger and renders backwards, but I much preferred handling everything directly in code. Blocks are a complete nightmare now, and certainly do not appear 'optimized' - arguably the exact opposite of optimized. I'm hoping that we will see a return to common sense sometime in the future, but I fear we will be stuck with this nonsense...

 

At least the rotation isn't handled in quaternions.

(If anyone legitimately understands how to rotate things in quaternions: you're abnormal)

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.

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



×
×
  • Create New...

Important Information

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