Jump to content

Recommended Posts

Posted

I want to have a normal Block that just auto-faces the player when placed, and tried using the code from the furnace but I couldnt get it to work. The Block gets textured right but it doesnt rotate

My Block Class:

 

public class BulkCore extends TEBlock {

    public static final PropertyDirection FACING = BlockHorizontal.FACING;
public BulkCore() {
	super(1);
}

    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);;
    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    }
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }
    public IBlockState getStateFromMeta(int meta)
    {
        EnumFacing enumfacing = EnumFacing.getFront(meta);
        if (enumfacing.getAxis() == EnumFacing.Axis.Y) enumfacing = EnumFacing.NORTH;
        return this.getDefaultState().withProperty(FACING, enumfacing);
    }
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }
    
}

 

 

blockstate file:

 

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

 

 

block model file:

 

{
    "parent": "block/orientable",
    "textures": {       
        "top":  "simpleautomation:blocks/bulkcrate",
        "front":"simpleautomation:blocks/bulkcore",
        "side": "simpleautomation:blocks/bulkcrate"
    }
}

 

Posted

@Override, as far as I know, doesnt actually do anything just lets you know that you override

TEBlock is just a Block that provides a TileEntity, here the Code to be clear:

 

public class TEBlock extends BlockContainer {

int type;
public TEBlock(int typ) {
	super(typ==1?Material.WOOD:Material.ROCK);
	setHardness(1.5F);
	setHarvestLevel("pickaxe", 0);
	type=typ;
}

public TileEntity createNewTileEntity(World world, int meta){
	switch(type){
	case 0: return new FarmerTE();
	case 1: return new BulkTE();
	}
	return null;
 }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){
    	player.openGui(main.instance, type, world, pos.getX(), pos.getY(), pos.getZ());
    	return true;
    }

    @Override
    public EnumBlockRenderType getRenderType(IBlockState state){
        return EnumBlockRenderType.MODEL;
    }
    
    @Override
    public void breakBlock(World world, BlockPos pos, IBlockState blockstate) {
        TEInventory te = (TEInventory) world.getTileEntity(pos);
        InventoryHelper.dropInventoryItems(world, pos, te);
        super.breakBlock(world, pos, blockstate);
    }


    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    	if (stack.hasDisplayName()) ((TEInventory)worldIn.getTileEntity(pos)).setCustomName(stack.getDisplayName());
    }
    
}

 

Posted

It lets you know if you duck up the method signature.

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.