lavapad growing now

This commit is contained in:
Jottyfan 2023-12-13 23:43:04 +01:00
parent 5396cefbb3
commit 3aec4f1c08
3 changed files with 38 additions and 22 deletions

View File

@ -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

View File

@ -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<Block> 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

View File

@ -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<ItemStack> 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);
}