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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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