Posted February 3, 20196 yr 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; } }
February 3, 20196 yr 2 hours ago, JurassicFixx said: implements IHasModel Don't. IHasModel is stupid cargo-cult programming. All items need models, no exceptions, and nothing about model registration requires you to access private/protected data. Register your models directly in the ModelRegistryEvent. 2 hours ago, JurassicFixx said: BlockInit.BLOCKS.add(this); This screams static initializers. Don't ever use static initializers since then you lose control over loading order and can introduce all sorts of bugs. 2 hours ago, JurassicFixx said: ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); Same here. Instantinate your stuff in the appropriate registry event. 2 hours ago, JurassicFixx said: if (!worldIn.isAreaLoaded(pos, 3)) This will always be false. If the block at the given position receives a tick then the chunk is loaded. 2 hours ago, JurassicFixx said: { { Why do you have these all over the place? They don't do anything in your code. 3 hours ago, JurassicFixx said: if ((worldIn.getBlockState(pos) == Blocks.WATER)) This will always be false because IBlockState will never be equal to a Block. A block at the position passed will be your lily pad, it can't be water. 3 hours ago, JurassicFixx said: if (entityIn instanceof Entity) This will always be true since the argument passed is of an Entity type. You don't need this comparason at all. 3 hours ago, JurassicFixx said: new BlockPos(pos) ...why? 3 hours ago, JurassicFixx said: If anybody could take a look at my code and tell me how to get it to spread correctly Well you are kinda close to the solution yourself, you just need to offset the position given to you in the method. And fix all those other issues.
February 3, 20196 yr Author Thank you, I will work on all of these things. As I said I am very new to Java, and have no idea what I am doing
February 3, 20196 yr Author Spoiler ---- Minecraft Crash Report ---- // I let you down. Sorry Time: 2/3/19 10:05 PM Description: Exception ticking world java.lang.ClassCastException: jurassicfixx.jfmobs.blocks.BlockAlgae cannot be cast to net.minecraft.block.state.IBlockState at jurassicfixx.jfmobs.blocks.BlockAlgae.updateTick(BlockAlgae.java:51) at net.minecraft.block.Block.randomTick(Block.java:625) at net.minecraft.world.WorldServer.updateBlocks(WorldServer.java:497) at net.minecraft.world.WorldServer.tick(WorldServer.java:234) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace: at jurassicfixx.jfmobs.blocks.BlockAlgae.updateTick(BlockAlgae.java:51) at net.minecraft.block.Block.randomTick(Block.java:625) at net.minecraft.world.WorldServer.updateBlocks(WorldServer.java:497) at net.minecraft.world.WorldServer.tick(WorldServer.java:234) -- Affected level -- Details: Level name: New World All players: 1 total; [EntityPlayerMP['Player227'/236, l='New World', x=86.06, y=6.49, z=205.83]] Chunk stats: ServerChunkCache: 625 Drop: 0 Level seed: 1464878753198353783 Level generator: ID 01 - flat, ver 0. Features enabled: true Level generator options: Level spawn location: World: (75,4,246), Chunk: (at 11,0,6 in 4,15; contains blocks 64,0,240 to 79,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 86650 game time, 5000 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 1 (now: false), thunder time: 1 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) at java.lang.Thread.run(Unknown Source) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_191, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 605959464 bytes (577 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP 9.42 Powered by Forge 14.23.5.2768 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:-------------- |:--------- |:------------ |:-------------------------------- |:--------- | | UCHIJAAAAAAAAA | minecraft | 1.12.2 | minecraft.jar | None | | UCHIJAAAAAAAAA | mcp | 9.42 | minecraft.jar | None | | UCHIJAAAAAAAAA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2768.jar | None | | UCHIJAAAAAAAAA | forge | 14.23.5.2768 | forgeSrc-1.12.2-14.23.5.2768.jar | None | | UCHIJAAAAAAAAA | jfmobs | 0.0.1 | bin | None | Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 1 / 8; [EntityPlayerMP['Player227'/236, l='New World', x=86.06, y=6.49, z=205.83]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' I was cleaning it up and I tested it out, the game crashed - if there is any chance you would like to have a look at the report and help me out some more, please let me know Edited February 3, 20196 yr by JurassicFixx Added Crash report as a spoiler
February 3, 20196 yr Author 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) { { worldIn.setBlockState(pos, (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); { 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; } }
February 3, 20196 yr Author Alright, I don't believe I changed anything to do with IBlockState though. As I said, I learned most of what I know off basic YouTube tutorials.
February 3, 20196 yr Author Maybe I did, owell. I will be going and learning java to the best of my ability now. Thank you
February 3, 20196 yr 15 hours ago, JurassicFixx said: this.getTickRandomly(); Get tick randomly? Surely you mean Set tick randomly. 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.