Jump to content

Recommended Posts

Posted (edited)

So I have a custom plant that works perfectly normally when placed, and I can interact with it perfectly fine, and it renders just fine. This block has a custom blockstate called isflowered, when the player right clicks the plant the little fruit is removed. By default the fruit is always there when placed. However, when I go to generate this block when subscribed to the biome decoration event, this happens:

 

2020-07-13_11_09_22.thumb.png.b5c0485935569abe8a48743f9a5678e9.png

spacer.png

The block on the left is one I placed from the inventory, and the janky ones are the ones generated by the biome decoration event. I can still interact with the block, if I right click it it performs the effect that it's supposed to (it makes a slime sound and drops an item).

 

So two things that went wrong:

 

1. The block obviously doesn't render properly

 

2. The block disappears when I save and exit the game, and randomly shows up here and there.

 

Anyone have any idea what it might be?

 

The event:

    @SubscribeEvent
    public void onBiomeDecorate(DecorateBiomeEvent.Pre event)
    {
        World world = event.getWorld();
        Biome biome = world.getBiomeForCoordsBody(event.getPos());
        Random rand = event.getRand();

        if (rand.nextDouble() > 0.1) return;
        int x = rand.nextInt(16) + 8;
        int y = rand.nextInt(16) + 8;
        WorldGenRepitifleur gen = new WorldGenRepitifleur();
        gen.generate(world, rand, world.getHeight(event.getPos().add(x, 0, y)));
    }

 

The generator:

public class WorldGenRepitifleur extends WorldGenerator
{
    public WorldGenRepitifleur() {}
    @Override
    public boolean generate(World worldIn, Random rand, BlockPos position)
    {
        BlockRepitifleur tPlant = new BlockRepitifleur();

        for (int i = 0; i < 64; ++i)
        {
            BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

            if (worldIn.isAirBlock(blockpos) && (!worldIn.provider.isNether() || blockpos.getY() < 255) && tPlant.canBlockStay(worldIn, blockpos, tPlant.getDefaultState()))
            {
                worldIn.setBlockState(blockpos, tPlant.getDefaultState(), 2);
            }
        }

        return true;
    }
}

 

and the block:

public class BlockRepitifleur extends BlockBush
{
    public static final PropertyInteger IS_FLOWERED = PropertyInteger.create("isflowered", 0, 1);
    public BlockRepitifleur()
    {
        super(Material.PLANTS);
        this.setRegistryName("repitifleur");
        this.setDefaultState(this.blockState.getBaseState().withProperty(IS_FLOWERED, Integer.valueOf(1)));
        this.setCreativeTab(CreativeTabs.DECORATIONS);
        this.setUnlocalizedName("repitifleur");
        this.setTickRandomly(true);
        this.setSoundType(SoundType.PLANT);

    }
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (state.getValue(IS_FLOWERED) == 0)
        {
            worldIn.setBlockState(pos, state.withProperty(IS_FLOWERED, Integer.valueOf(1)), 3);
            if (playerIn.world.isRemote)
            {
                PlayerData data = (PlayerData) NecropolisPlayerData.get(playerIn);
                data.setPlayerStamina(400);
                playerIn.playSound(SoundEvents.BLOCK_SLIME_BREAK, 0.6F, 1.0F);
                return true;

            }
            playerIn.playSound(SoundEvents.BLOCK_SLIME_BREAK, 0.6F, 1.0F);
        }
        return true;
    }
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        super.updateTick(worldIn, pos, state, rand);
        if (!worldIn.isAreaLoaded(pos, 1)) return;
        if (state.getValue(IS_FLOWERED) == 1)
        {
            if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(3) == 0)
            {
                worldIn.setBlockState(pos, state.withProperty(IS_FLOWERED, Integer.valueOf(0)), 3);
            }
        }
    }
    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        IBlockState soil = worldIn.getBlockState(pos.down());
        return super.canPlaceBlockAt(worldIn, pos) && this.canSustainBush(soil);
    }
    @Override
    protected boolean canSustainBush(IBlockState state)
    {
        return state.getBlock() == Blocks.GRASS;
    }

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return null;
    }
    @Override
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
    {
        if (worldIn.isRemote)
            return;
        if (stack.getItem() == Items.SHEARS && state.getValue(IS_FLOWERED) == 0)
        {
            player.addStat(StatList.getBlockStats(this));
            worldIn.setBlockToAir(pos);
            spawnAsEntity(worldIn, pos, new ItemStack(BlockHandler.REPITIFLEUR, 1));
        }
        else
        {
            return;
            //super.harvestBlock(worldIn, player, pos, state, te, stack);
        }
    }
    @Nullable
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
    {
        return NULL_AABB;
    }
    @Override
    public boolean canPlaceTorchOnTop(IBlockState state, IBlockAccess world, BlockPos pos)
    {
        return false;
    }
    @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }
    @Override
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT_MIPPED;
    }
    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] {IS_FLOWERED});
    }
    @Override
    public IBlockState getStateFromMeta(int meta) {
        return this.getDefaultState().withProperty(IS_FLOWERED, Integer.valueOf(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state) {
            return ((Integer)state.getValue(IS_FLOWERED)).intValue();

    }
    public IBlockState getPlantState()
    {
        return this.blockState.getBaseState().withProperty(IS_FLOWERED, Integer.valueOf(1));
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return false;
    }

}

 

Edited by k-off
Posted

Post your log file.

Its not so much that your block isn't generating correctly, but that there's an error with its blockstate or model or texture.

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
1 hour ago, Draco18s said:

Post your log file.

Its not so much that your block isn't generating correctly, but that there's an error with its blockstate or model or texture.

Yup that's exactly what it was, the blockstate. I set up a proper block handler class for all my blocks, and now referencing that made it work.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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