diff --git a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java index d1f01ccbfe..2a3c7969f8 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.utility; +import java.util.List; import java.util.function.Consumer; import javax.annotation.Nullable; @@ -45,6 +46,8 @@ import net.minecraft.world.level.block.SlimeBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.SlabType; import net.minecraft.world.level.chunk.LevelChunk; @@ -55,6 +58,24 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.level.BlockEvent; public class BlockHelper { + private static final List COUNT_STATES = List.of( + BlockStateProperties.EGGS, + BlockStateProperties.PICKLES, + BlockStateProperties.CANDLES + ); + + private static final List VINELIKE_BLOCKS = List.of( + Blocks.VINE, Blocks.GLOW_LICHEN + ); + + private static final List VINELIKE_STATES = List.of( + BlockStateProperties.UP, + BlockStateProperties.NORTH, + BlockStateProperties.EAST, + BlockStateProperties.SOUTH, + BlockStateProperties.WEST, + BlockStateProperties.DOWN + ); public static BlockState setZeroAge(BlockState blockState) { if (blockState.hasProperty(BlockStateProperties.AGE_1)) @@ -96,11 +117,21 @@ public class BlockHelper { if (needsTwo) amount *= 2; - if (block.hasProperty(BlockStateProperties.EGGS)) - amount *= block.getValue(BlockStateProperties.EGGS); + for (IntegerProperty property : COUNT_STATES) + if (block.hasProperty(property)) + amount *= block.getValue(property); - if (block.hasProperty(BlockStateProperties.PICKLES)) - amount *= block.getValue(BlockStateProperties.PICKLES); + if (VINELIKE_BLOCKS.contains(block.getBlock())) { + int vineCount = 0; + + for (BooleanProperty vineState : VINELIKE_STATES) { + if (block.hasProperty(vineState) && block.getValue(vineState)) { + vineCount++; + } + } + + amount += vineCount - 1; + } { // Try held Item first @@ -243,17 +274,17 @@ public class BlockHelper { CompoundTag data = null; if (blockEntity == null) return data; - + if (AllBlockTags.SAFE_NBT.matches(blockState)) { data = blockEntity.saveWithFullMetadata(); - + } else if (blockEntity instanceof IPartialSafeNBT) { data = new CompoundTag(); ((IPartialSafeNBT) blockEntity).writeSafe(data); - + } else if (Mods.FRAMEDBLOCKS.contains(blockState.getBlock())) data = FramedBlocksInSchematics.prepareBlockEntityData(blockState, blockEntity); - + return NBTProcessors.process(blockState, blockEntity, data, true); }