Fix schematicannons consuming a single item for group items (#7058)

This commit is contained in:
IThundxr 2025-01-10 12:08:51 -05:00 committed by GitHub
parent c765b00c77
commit e065bb386b
Failed to generate hash of commit

View file

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