Jump to content

Recommended Posts

Posted

Through some hacky nifty ways I managed to come up with this, would it work?

	@SubscribeEvent
	public void onCropGrow(BonemealEvent event) {
		event.setCanceled(true);
		World world = event.getWorld();
		IBlockState state = event.getBlock();
		BlockPos pos = event.getPos();
		ItemStack stack = event.getEntityPlayer().getActiveItemStack();
		if (state.getBlock() instanceof IGrowable) {
			IGrowable igrowable = (IGrowable) state.getBlock();

			if (igrowable.canGrow(world, pos, state, world.isRemote)) {
				if (!world.isRemote) {
					igrowable.grow(world, world.rand, pos, state);
					if (igrowable instanceof BlockCrops) {
						world.setBlockState(pos, state.withProperty(BlockCrops.AGE, ((BlockCrops)igrowable).getMaxAge()));
					}
					stack.shrink(1);
				}
			}
		}
	}

 

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

Wow I had that idea in the beginning but thought Nah that wont work....

	@SubscribeEvent
	public void onCropGrow(BonemealEvent event) {
		event.setCanceled(true);
		World world = event.getWorld();
		IBlockState state = event.getBlock();
		BlockPos pos = event.getPos();
		ItemStack stack = event.getEntityPlayer().getActiveItemStack();
		if (state.getBlock() instanceof IGrowable) {
			IGrowable igrowable = (IGrowable) state.getBlock();

			if (igrowable.canGrow(world, pos, state, world.isRemote)) {
				if (!world.isRemote) {
					igrowable.grow(world, world.rand, pos, state);
					while (igrowable.canGrow(world, pos, state, world.isRemote)) {
						igrowable.grow(world, world.rand, pos, state);
					}
					stack.shrink(1);
				}
			}
		}
	}

Let's test this out

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

It gets stuck in an infinite loop at the while because it is using the same state everytime instead you should get the state from the World field and BlockPos field.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
	@SubscribeEvent
	public void onCropGrow(BonemealEvent event) {
		event.setCanceled(true);
		World world = event.getWorld();
		IBlockState state = event.getBlock();
		BlockPos pos = event.getPos();
		ItemStack stack = event.getEntityPlayer().getActiveItemStack();
		if (state.getBlock() instanceof IGrowable) {
			IGrowable igrowable = (IGrowable) state.getBlock();

			if (igrowable.canGrow(world, pos, state, world.isRemote)) {
				if (!world.isRemote) {
					igrowable.grow(world, world.rand, pos, state);
					while (igrowable.canGrow(world, pos, state, world.isRemote)) {
						igrowable.grow(world, world.rand, pos, state);
						igrowable = (IGrowable) world.getBlockState(pos).getBlock();
					}
					stack.shrink(1);
				}
			}
		}
	}

Doesn't work either

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted
3 minutes ago, Kokkie said:

Ah thanks it works, only thing is, it doesn't take away an item... And the tree gets well.. buggy... It isn't rendered until you update the blocks (right-click)...

You will need to mark the block for an update specifically the client. World#markBlockForUpdate (I think that is the name at least it is similar).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
	@SubscribeEvent
	public void onCropGrow(BonemealEvent event) {
		event.setCanceled(true);
		World world = event.getWorld();
		IBlockState state = event.getBlock();
		BlockPos pos = event.getPos();
		ItemStack stack = event.getEntityPlayer().getActiveItemStack();
		if (state.getBlock() instanceof IGrowable) {
			IGrowable igrowable = (IGrowable) state.getBlock();
			if (igrowable.canGrow(world, pos, state, world.isRemote)) {
				if (!world.isRemote) {
					while (igrowable.canGrow(world, pos, state, world.isRemote)) {
						igrowable.grow(world, world.rand, pos, state);
						state = world.getBlockState(pos);
					}
					world.markAndNotifyBlock(pos, world.getChunkFromBlockCoords(pos), state, world.getBlockState(pos), 2);
					stack.shrink(1);
				}
			}
		}
	}

Nope...

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

Also, I get this error in the console

[14:16:20] [Server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.player.BonemealEvent@75452f75:
java.lang.IllegalArgumentException: Cannot get property PropertyInteger{name=stage, clazz=class java.lang.Integer, values=[0, 1]} as it does not exist in BlockStateContainer{block=minecraft:log, properties=[axis, variant]}
	at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:201) ~[BlockStateContainer$StateImplementation.class:?]
	at net.minecraft.block.BlockSapling.grow(BlockSapling.java:71) ~[BlockSapling.class:?]
	at net.minecraft.block.BlockSapling.grow(BlockSapling.java:251) ~[BlockSapling.class:?]
	at com.Egietje.degeweldigemod.handler.CheeseCommonHandler.onCropGrow(CheeseCommonHandler.java:80) ~[CheeseCommonHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_18_CheeseCommonHandler_onCropGrow_BonemealEvent.invoke(.dynamic) ~[?:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) [EventBus.class:?]
	at net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(ForgeEventFactory.java:355) [ForgeEventFactory.class:?]
	at net.minecraft.item.ItemDye.applyBonemeal(ItemDye.java:118) [ItemDye.class:?]
	at net.minecraft.item.ItemDye.onItemUse(ItemDye.java:62) [ItemDye.class:?]
	at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:812) [ForgeHooks.class:?]
	at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:179) [ItemStack.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:516) [PlayerInteractionManager.class:?]
	at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:712) [NetHandlerPlayServer.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) [CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) [CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) [PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_77]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_77]
	at net.minecraft.util.Util.runTask(Util.java:26) [Util.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
[14:16:20] [Server thread/ERROR] [FML]: Index: 1 Listeners:
[14:16:20] [Server thread/ERROR] [FML]: 0: NORMAL
[14:16:20] [Server thread/ERROR] [FML]: 1: ASM: com.Egietje.degeweldigemod.handler.CheeseCommonHandler@63a5a05a onCropGrow(Lnet/minecraftforge/event/entity/player/BonemealEvent;)V
[14:16:20] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Cannot get property PropertyInteger{name=stage, clazz=class java.lang.Integer, values=[0, 1]} as it does not exist in BlockStateContainer{block=minecraft:log, properties=[axis, variant]}
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_77]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_77]
	at net.minecraft.util.Util.runTask(Util.java:27) [Util.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
Caused by: java.lang.IllegalArgumentException: Cannot get property PropertyInteger{name=stage, clazz=class java.lang.Integer, values=[0, 1]} as it does not exist in BlockStateContainer{block=minecraft:log, properties=[axis, variant]}
	at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:201) ~[BlockStateContainer$StateImplementation.class:?]
	at net.minecraft.block.BlockSapling.grow(BlockSapling.java:71) ~[BlockSapling.class:?]
	at net.minecraft.block.BlockSapling.grow(BlockSapling.java:251) ~[BlockSapling.class:?]
	at com.Egietje.degeweldigemod.handler.CheeseCommonHandler.onCropGrow(CheeseCommonHandler.java:80) ~[CheeseCommonHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_18_CheeseCommonHandler_onCropGrow_BonemealEvent.invoke(.dynamic) ~[?:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) ~[EventBus.class:?]
	at net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(ForgeEventFactory.java:355) ~[ForgeEventFactory.class:?]
	at net.minecraft.item.ItemDye.applyBonemeal(ItemDye.java:118) ~[ItemDye.class:?]
	at net.minecraft.item.ItemDye.onItemUse(ItemDye.java:62) ~[ItemDye.class:?]
	at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:812) ~[ForgeHooks.class:?]
	at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:179) ~[ItemStack.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:516) ~[PlayerInteractionManager.class:?]
	at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:712) ~[NetHandlerPlayServer.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_77]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_77]
	at net.minecraft.util.Util.runTask(Util.java:26) ~[Util.class:?]
	... 5 more

 

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted (edited)

So.. this?

	@SubscribeEvent
	public void onBonemeal(BonemealEvent event) {
		event.setCanceled(true);
		World world = event.getWorld();
		BlockPos pos = event.getPos();
		IBlockState state = world.getBlockState(pos);
		ItemStack stack = event.getEntityPlayer().getHeldItemMainhand();
		if (stack.getItem() != Items.DYE) {
			stack = event.getEntityPlayer().getHeldItemOffhand();
			if (stack.getItem() != Items.DYE) {
				return;
			}
		}
		if (state.getBlock() instanceof IGrowable) {
			IGrowable igrowable = (IGrowable) state.getBlock();
			if (!world.isRemote) {
				while (igrowable.canGrow(world, pos, state, world.isRemote)) {
					igrowable.grow(world, world.rand, pos, state);
					state = world.getBlockState(pos);
					if (state.getBlock() instanceof IGrowable) {
						igrowable = (IGrowable) state.getBlock();
					} else {
						stack.shrink(1);
					}
				}
			}
		}
	}

 

Edited by Kokkie
Other solution

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

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.