Jump to content

Recommended Posts

Posted

I've created a block that stores the rotation data inside the tileentity.

 

The problem I'm having is when I right click the custom block I want it to create the same block 4 blocks away.

When I right click the block it places the block but facing North not any of the other directions.

 

The code I've tried to use inside the block code:

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) 
    {
        Block testBlock = ModBlocks.testBlock;
        IBlockState testState = testBlock.getStateFromMeta(getFabricType(state));

        //attempts to get the block placed with right property
        worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));

        worldIn.setBlockState(new BlockPos(pos.getX() + 4, pos.getY(), pos.getZ()), ModBlocks.testBlock.getDefaultState().withProperty(FACING, EnumFacing.WEST));


        return true;
    }

 

The tileEntity code: I think the problem is caused by this line "private EnumFacing facing = EnumFacing.NORTH" not sure how I could alter this code to not change a placed block to North rotation.

 

 

public class TileEntityTest extends TileEntity
{
    [color=red]private EnumFacing facing = EnumFacing.NORTH;[/color]

    public EnumFacing getFacing()
    {
        return facing;
    }

    public void setFacing(EnumFacing facing)
    {
        this.facing = facing;
        markDirty();
    }

    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);
        facing = EnumFacing.getFront(compound.getInteger("facing"));
    }

    @Override
    public void writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);
        compound.setInteger("facing", facing.getIndex());
    }

    @Override
    public Packet getDescriptionPacket()
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        this.writeToNBT(nbttagcompound);
        return new S35PacketUpdateTileEntity(this.getPos(), this.getBlockMetadata(), nbttagcompound);
    }

    @Override
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
    {
        readFromNBT(packet.getNbtCompound());
        getWorld().markBlockForUpdate(getPos());
    }

    @Override
    public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
    {
        return oldState.getBlock() != newSate.getBlock();
    }
}

Posted

If you are storing property in TileEntity - what sets that property? Fields don't get magically assigned, you need to use them somewhere. Does your Block class do this?

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

this is the block code, the facing property gets assigned when the block is placed.

public class BlockTest extends Block
{
    public static final IProperty<EnumFacing> FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
    public static final PropertyEnum BLOCKTYPE = PropertyEnum.create("block", EnumBlockType.class);


    public BlockTest(String unlocalizedName)
    {
        super(Material.stone);
    }

    @Override @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list)
    {
        for(EnumBlockType EnumBlockType : EnumBlockType.values())
        {
            list.add(new ItemStack(item, 1, EnumBlockType.getMetadata()));
        }
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(BLOCKTYPE, EnumBlockType.byMetaData(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumBlockType)state.getValue(BLOCKTYPE)).getMetadata();
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, BLOCKTYPE, FACING);
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return state.withProperty(FACING, getFacing(worldIn, pos));
    }

    @Override
    public boolean hasTileEntity(IBlockState state)
    {
        return true;
    }

    @Override
    public TileEntity createTileEntity(World world, IBlockState state)
    {
        return new TileEntityBlockTest();
    }

    public TileEntityBlockTest getTileEntity(IBlockAccess world, BlockPos pos)
    {
        return (TileEntityBlockTest) world.getTileEntity(pos);
    }

    public EnumFacing getFacing(IBlockAccess world, BlockPos pos)
    {
        return getTileEntity(world, pos).getFacing();
    }

    public void setFacing(IBlockAccess world, BlockPos pos, EnumFacing facing)
    {
        getTileEntity(world, pos).setFacing(facing);
    }

    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        setFacing(worldIn, pos, BlockPistonBase.getFacingFromEntity(worldIn, pos, placer));
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        Block testBlock = ModBlocks.testBlock;
        IBlockState testState = testBlock.getDefaultState();

        //attempts to get the block placed with right property
        worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));

        worldIn.setBlockState(new BlockPos(pos.getX() + 4, pos.getY(), pos.getZ()), ModBlocks.testBlock.getDefaultState().withProperty(FACING, EnumFacing.WEST));


        return true;
    }
}

Posted
  On 7/17/2016 at 7:26 AM, TheRedDevil said:

The tileEntity code: I think the problem is caused by this line "private EnumFacing facing = EnumFacing.NORTH" not sure how I could alter this code to not change a placed block to North rotation.

 

That line is likely the problem.  Do what Diesieben07 says and get rid of the TE.

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

I've removed the tileEntity and managed to place blocks with the correct blockType property but having few problems merging the facing property together.

 

Believe I need to combine these two lines together but having trouble merging both returns into one

 

Method I'm having trouble getting both property to work together.

@Override
    public int getMetaFromState(IBlockState state)
    {
        return  state.getValue(FACING).getIndex();
        //return state.getValue(BLOCKTYPE).getMetadata();
    }

Posted

Metadata is only 4 bits worth of data.  Facing takes (minimum) 2 of those bits, leaving you 2 (four possible values) for BLOCKTYPE.

 

Show your BLOCKTYPE property declaration/definition.

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

That could be the problem then as BLOCKTYPE uses 10 values :/

Thought facing might of taken 1 bit, as I'm just using horizontal properties with 4 values, my mistake xD

 

I could go back to storing the block face in the tileEntity and figure a way to fix my first post problem.

 

 

Posted

Should I still use getStateFromMeta/getMetaFromState to store the "BLOCKTYPE"?

@Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(BLOCKTYPE, EnumBlockType.byMetaData(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumBlockType)state.getValue(BLOCKTYPE)).getMetadata();
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, BLOCKTYPE, FACING);
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return state.withProperty(FACING, getFacing(worldIn, pos));
    }

 

When I place to block ingame it has the correct block type / facing n/e/s/w,

but when I right click the block it's placing the block in the north face not west.

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        Block testBlock = ModBlocks.testBlock;
        IBlockState testState = testBlock.getDefaultState();

        worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));
return true;
}

 

 

 

 

Posted
  On 7/17/2016 at 3:35 PM, TheRedDevil said:

That could be the problem then as BLOCKTYPE uses 10 values :/

Thought facing might of taken 1 bit, as I'm just using horizontal properties with 4 values, my mistake xD

 

I could go back to storing the block face in the tileEntity and figure a way to fix my first post problem.

 

I would store the FACING in the metadata (so many blocks already do, if a mod comes along with a tool that can rotate blocks, your block would be automatically rotatable with no effort if you do) and the BLOCKTYPE in the TileEntity.

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

If I did store the BlockType inside the tileEntity is it possible to create recipes that uses each blockType?

Was main reason I stored the BlockType inside the metadata so I could create recipes for each metadata version.

 

I've not looked into 1.8/1.9 recipes wasn't sure if it was possible.

 

I have all code working now will keep it how it is :)

Posted

Is there any forge documentations on custom ItemBlock or examples of basic ItemBlocks?

 

never used, best if i did some research before I break my mod for the tenth time this week :D

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

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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