Jump to content

[SOLVED] [1.12.1] help with combined block placement of logs and pistons


Recommended Posts

Posted (edited)

I am trying to achieve blocking placement that when placed on the ground and ceiling, only flips its sides textures 180 degrees, kind of like a log. But then when placing it on a wall, it rotates the side texture 90 degrees with each direction. At the moment I have copied dispenser code to handle the rotation, but what is happening is that if I am placing the block on the ground, it will still rotate 90 degrees based on the direction instead of only doing so when placing it on a wall. Essentially what I want is rotation to act like pistons/dispensers when on walls, and to only invert the texture if its placed on the floor or ceiling. Any suggestions appreciated.

 

public class blockFreize extends blockBase {

	//public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
	public static final PropertyDirection FACING = BlockDirectional.FACING;

	
	public blockFreize(String name, Material material) {
		super(name, Material.IRON);
		 
		this.setHardness(3f);
		this.setResistance(5f);
	 
		this.setCreativeTab(menuTab.resBlocks);
	 
		this.blockSoundType = SoundType.METAL;
		this.setSoundType(blockSoundType);
		
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	}
	
	@Override
	public blockFreize setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}
	
	/**
     * Called after the block is set in the Chunk data, but before the Tile Entity is set
     */
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        super.onBlockAdded(worldIn, pos, state);
        this.setDefaultDirection(worldIn, pos, state);
    }
    
    private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
            boolean flag = worldIn.getBlockState(pos.north()).isFullBlock();
            boolean flag1 = worldIn.getBlockState(pos.south()).isFullBlock();

            if (enumfacing == EnumFacing.NORTH && flag && !flag1)
            {
                enumfacing = EnumFacing.SOUTH;
            }
            else if (enumfacing == EnumFacing.SOUTH && flag1 && !flag)
            {
                enumfacing = EnumFacing.NORTH;
            }
            else
            {
                boolean flag2 = worldIn.getBlockState(pos.west()).isFullBlock();
                boolean flag3 = worldIn.getBlockState(pos.east()).isFullBlock();

                if (enumfacing == EnumFacing.WEST && flag2 && !flag3)
                {
                    enumfacing = EnumFacing.EAST;
                }
                else if (enumfacing == EnumFacing.EAST && flag3 && !flag2)
                {
                    enumfacing = EnumFacing.WEST;
                }
            }

            worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
        }
        
    }
       
	
	
	protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }

    /**
     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    /**
     * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }

    /**
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
     * IBlockstate
     */
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
      
    	
    	return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer));//e.withProperty(AXIS, facing.getAxis());
    	
    	
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
              
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();


        return i;
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        //return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
    	return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
    	   
    }
}

 

Edited by daruskiy
solved
Posted
12 minutes ago, daruskiy said:

I am trying to achieve blocking placement that when placed on the ground and ceiling, only flips its sides textures 180 degrees, kind of like a log...

[Block class]

Aaaaand your blockstate json file?

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
55 minutes ago, Draco18s said:

Aaaaand your blockstate json file?

Copy of the dispenser 

{
	"variants": {
		"facing=down":  { "model": "respublica:freize0", "x": 180 },
        "facing=up":    { "model": "respublica:freize0" },
        "facing=north": { "model": "respublica:freize0" },
        "facing=south": { "model": "respublica:freize0", "y": 180 },
        "facing=west":  { "model": "respublica:freize0", "y": 270 },
        "facing=east":  { "model": "respublica:freize0", "y": 90 }
	}
}

However it is irrelevant as what is wrong is the actual action that being triggered in game. When i place anything on the ground, I want it to always be right side up. When I place anything on the ceiling or underneath a block, it needs to upside down. In the other cases wen placing on walls it needs to use the directional north east south west rules. At the moment what is happening is like piston placing and dispenser facing, when i place the block on the ground, it starts to follow the NSEW rules and rotates the block to look at me

Posted

If you want to use textures like the log, perhaps you should look at the log?

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
30 minutes ago, Draco18s said:

If you want to use textures like the log, perhaps you should look at the log?

I have, and as I said above the action that I need are a combination of the log and of the piston/dispenser. The BlockLog, BlockRotatedPillar, BlockHay all used the same logic where when you place it rotates the texture in the same way so if you had half a block blue and half a block red, regardless the direction NSEW you place it, the colors will be in the same order. I am trying to figure out how to make my code work for example: the bottom texture is solid blue, when I place it on the groudn regardless of direction facing, the the blue side is on the ground. when I place it on the ceiling, the blue texture is on the top. When i place on the wall, the blue texture needs to be facing the wall. At the moment with the code I got from the dispenser, what is happening even if i place the block on the ground, the blue side will rotate to match the axis that I am facing, i.e. like the dispenser facing the direction you placed it. Hopefully this is clear now. Any suggestinos appreciated

Posted

Post your model. Likely you want to use "parent": "block/cube_column" or "parent": "block/orientable"

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.