From 3aec4f1c08bd003f3fdb1009cb9fb3fa53d6548f Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Wed, 13 Dec 2023 23:43:04 +0100 Subject: [PATCH] lavapad growing now --- gradle.properties | 2 +- .../quickiefabric/blocks/BlockSulforpad.java | 37 ++++++++++++++++++- .../quickiefabric/items/ItemSulphor.java | 21 +---------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index 08d1ed2..53f1478 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.15.1 # Mod Properties - mod_version = 1.20.4.1 + mod_version = 1.20.4.2 maven_group = de.jottyfan.minecraft archives_base_name = quickiefabric diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockSulforpad.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockSulforpad.java index d2c4c86..f2142e3 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockSulforpad.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockSulforpad.java @@ -2,6 +2,7 @@ package de.jottyfan.minecraft.quickiefabric.blocks; import java.util.Arrays; import java.util.List; +import java.util.Set; import com.mojang.serialization.MapCodec; @@ -19,6 +20,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.loot.context.LootContextParameterSet.Builder; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.ItemScatterer; @@ -47,6 +49,38 @@ public class BlockSulforpad extends CropBlock { super(FabricBlockSettings.create()); } + public static final Set getAllowedBlockHolder(){ + return Set.of(Blocks.LAVA, Blocks.LAVA_CAULDRON, Blocks.MAGMA_BLOCK); + } + + @Override + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + growNow(state, world, pos, random); + } + + private void generateNeighbor(ServerWorld world, BlockPos pos, Random random) { + int xOffset = random.nextInt(3) - 1; + int zOffset = random.nextInt(3) - 1; + BlockPos newPos = new BlockPos(pos).add(xOffset, 0, zOffset); + if (getAllowedBlockHolder().contains(world.getBlockState(newPos).getBlock()) && world.getBlockState(newPos.up()).isAir()) { + world.setBlockState(newPos, QuickieBlocks.SULFORPAD.getDefaultState(), Block.NOTIFY_LISTENERS); + } + } + + private void growNow(BlockState state, ServerWorld world, BlockPos pos, Random random) { + int i; + if ((i = this.getAge(state)) < this.getMaxAge()) { + world.setBlockState(pos, this.withAge(i + 1), Block.NOTIFY_LISTENERS); + } else { + generateNeighbor(world, pos, random); + } + } + + @Override + public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) { + growNow(state, world, pos, random); + } + @Override public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { return true; @@ -66,8 +100,7 @@ public class BlockSulforpad extends CropBlock { @Override protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) { - Boolean lavaBase = floor.getBlock().equals(Blocks.LAVA) || floor.getBlock().equals(Blocks.LAVA_CAULDRON); - return lavaBase && world.getBlockState(pos.up()).isAir(); + return getAllowedBlockHolder().contains(floor.getBlock()) && world.getBlockState(pos.up()).isAir(); } @Override diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemSulphor.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemSulphor.java index e99801f..9036993 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemSulphor.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemSulphor.java @@ -1,15 +1,12 @@ package de.jottyfan.minecraft.quickiefabric.items; +import de.jottyfan.minecraft.quickiefabric.blocks.BlockSulforpad; import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BoatItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; @@ -29,20 +26,6 @@ public class ItemSulphor extends Item { super(new FabricItemSettings()); } - @Override - public ActionResult useOnBlock(ItemUsageContext context) { - World world = context.getWorld(); - BlockPos pos = context.getBlockPos(); - Block block = world.getBlockState(pos).getBlock(); - if (Blocks.LAVA_CAULDRON.equals(block)) { - if (world.getBlockState(pos.up()).isAir()) { - world.setBlockState(pos.up(), QuickieBlocks.SULFORPAD.getDefaultState()); - context.getStack().decrement(1); - } - } - return ActionResult.PASS; - } - @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { ItemStack itemStack = user.getStackInHand(hand); @@ -53,7 +36,7 @@ public class ItemSulphor extends Item { if (((HitResult) hitResult).getType() == HitResult.Type.BLOCK) { if (!world.isClient) { BlockPos pos = hitResult.getBlockPos(); - if (world.getBlockState(pos).getBlock().equals(Blocks.LAVA) && world.getBlockState(pos.up()).isAir()) { + if (BlockSulforpad.getAllowedBlockHolder().contains(world.getBlockState(pos).getBlock()) && world.getBlockState(pos.up()).isAir()) { world.setBlockState(pos.up(), QuickieBlocks.SULFORPAD.getDefaultState()); itemStack.decrement(1); }