So I am entirely new to modding, and for the most part I followed relevant tutorials on YouTube to get what I wanted into my mod. However, I haven't been able to get my block to function how I want it to.
To get to the point, I have what is essentially a custom lilypad that I want to place on water like a lilypad, and also have it be ticked randomly, and spread to a nearby block above water every time it is ticked. I also want it to break every time an entity comes in contact with it (I have that part more or less working).
If anybody could take a look at my code and tell me how to get it to spread correctly, I would appreciate it so much.
Thank you.
P.s. If any other part of code is required to help, I will be happy to provide it.
package jurassicfixx.jfmobs.blocks;
import java.util.Random;
import jurassicfixx.jfmobs.Main;
import jurassicfixx.jfmobs.init.BlockInit;
import jurassicfixx.jfmobs.init.ItemInit;
import jurassicfixx.jfmobs.util.IHasModel;
import net.minecraft.block.BlockLilyPad;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockAlgae extends BlockLilyPad implements IHasModel //indicator jurassicfixx.jfmobs
{
public static AxisAlignedBB ALGAE_AABB;
public BlockAlgae(String name, Material material)
{
super();
ALGAE_AABB = new AxisAlignedBB(1D, 0.0D, 1D, 0D, 0.09375D, 0D);
this.getTickRandomly();
setUnlocalizedName(name);
setRegistryName(name);
setCreativeTab(Main.jfmobsblocks);
BlockInit.BLOCKS.add(this);
ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (!worldIn.isAreaLoaded(pos, 3)) return;
{
{
if ((worldIn.getBlockState(pos) == Blocks.WATER))
{
worldIn.setBlockState(pos.up(1), (IBlockState) BlockInit.ALGAE);
}
}
}
}
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return ItemInit.SWAMP_ALGAE;
}
public int quantityDropped(IBlockState state, int fortune, Random random) {
return random.nextInt(2);
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
if (entityIn instanceof Entity)
{
worldIn.destroyBlock(new BlockPos(pos), true);
}
}
@Override
public void registerModels()
{
Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
}
@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}