Fix banner schematic printing

- Banners will now be printed with the correct pattern
- To print a banner, the item with the exact same pattern is required
- Add ISpecialBlockEntityItemRequirement for BlockEntities
- Allow StackRequirements to check match with other stack
- Add StrictNbtStackRequirement that also checks the stack NBT
- Add banners tag to safe_nbt tag
This commit is contained in:
PepperCode1 2022-06-23 19:58:51 -07:00
parent 97da6be27f
commit a2ade69035
14 changed files with 133 additions and 107 deletions

View file

@ -5184,10 +5184,10 @@ d79c82bc6cf59b073b2f51f5fea9c98e81d14b68 data/create/recipes/weathered_copper_ti
ac265a674626e0e832330086fd18fe0be37fc327 data/create/recipes/weathered_copper_tile_stairs.json
5942a571f79c40524bbf408775cf91de4715f2b6 data/create/recipes/weathered_copper_tile_stairs_from_weathered_copper_tiles_stonecutting.json
6558ef43f28c92cc558fbfc572f38496f1ed479e data/create/tags/blocks/brittle.json
330bfb3850ba3964b10b1bccbc3cbb9b012cae54 data/create/tags/blocks/fan_heaters.json
57b942386a15c874d1ca9cd6a8032c11a5599fc2 data/create/tags/blocks/fan_transparent.json
418c6da531d6206e3cbe4049dce3db23c4270bed data/create/tags/blocks/fan_heaters.json
443f75adbf3d2f6fb0aad4b344372669470065b8 data/create/tags/blocks/fan_transparent.json
10781e8cfcbb3486327aace3aa00e437fb44b331 data/create/tags/blocks/ore_override_stone.json
557a29a61145b0f266760ef06256188a296739a7 data/create/tags/blocks/safe_nbt.json
2b56c19047accfbeeb4b07ba06a23d2d59d9d629 data/create/tags/blocks/safe_nbt.json
6cdeeac1689f7b5bfd9bc40b462143d8eaf3ad0b data/create/tags/blocks/seats.json
d063e12c9ef75f39518c6d129ea35d833464d547 data/create/tags/blocks/toolboxes.json
50936b211d94167a35ec78c89954082a336b6269 data/create/tags/blocks/valve_handles.json

View file

@ -3,11 +3,9 @@
"values": [
"create:blaze_burner",
"create:lit_blaze_burner",
"#minecraft:fire",
"#minecraft:campfires",
"minecraft:magma_block",
"minecraft:campfire",
"minecraft:lava",
"minecraft:fire",
"minecraft:soul_fire",
"minecraft:soul_campfire"
"minecraft:lava"
]
}

View file

@ -5,8 +5,7 @@
"create:lit_blaze_burner",
"create:sail_frame",
"#minecraft:fences",
"minecraft:iron_bars",
"minecraft:campfire",
"minecraft:soul_campfire"
"#minecraft:campfires",
"minecraft:iron_bars"
]
}

View file

@ -24,6 +24,7 @@
"create:analog_lever",
"create:pulse_repeater",
"create:pulse_extender",
"#minecraft:signs"
"#minecraft:signs",
"#minecraft:banners"
]
}

View file

@ -351,11 +351,15 @@ public class AllTags {
AllBlockTags.BRITTLE.add(Blocks.FLOWER_POT, Blocks.BELL, Blocks.COCOA);
AllBlockTags.FAN_TRANSPARENT.includeAll(BlockTags.FENCES);
AllBlockTags.FAN_TRANSPARENT.add(Blocks.IRON_BARS, Blocks.CAMPFIRE, Blocks.SOUL_CAMPFIRE);
AllBlockTags.FAN_TRANSPARENT.includeAll(BlockTags.CAMPFIRES);
AllBlockTags.FAN_TRANSPARENT.add(Blocks.IRON_BARS);
AllBlockTags.FAN_HEATERS.includeAll(BlockTags.FIRE);
AllBlockTags.FAN_HEATERS.includeAll(BlockTags.CAMPFIRES);
AllBlockTags.FAN_HEATERS.add(Blocks.MAGMA_BLOCK, Blocks.LAVA);
AllBlockTags.FAN_HEATERS.add(Blocks.MAGMA_BLOCK, Blocks.CAMPFIRE, Blocks.LAVA, Blocks.FIRE, Blocks.SOUL_FIRE,
Blocks.SOUL_CAMPFIRE);
AllBlockTags.SAFE_NBT.includeAll(BlockTags.SIGNS);
AllBlockTags.SAFE_NBT.includeAll(BlockTags.BANNERS);
AllBlockTags.WRENCH_PICKUP.includeAll(BlockTags.RAILS);
AllBlockTags.WRENCH_PICKUP.includeAll(BlockTags.BUTTONS);

View file

@ -115,21 +115,20 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
return;
List<ItemRequirement.StackRequirement> requiredItems = requirement.getRequiredItems();
ItemStack firstRequired = requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0).item;
ItemStack contextStack = requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0).stack;
if (!context.contraption.hasUniversalCreativeCrate) {
IItemHandler iItemHandler = context.contraption.inventory;
for (ItemRequirement.StackRequirement required : requiredItems) {
int amountFound = ItemHelper
.extract(iItemHandler, s -> ItemRequirement.validate(required.item, s), ExtractionCountMode.UPTO,
required.item.getCount(), true)
.getCount();
if (amountFound < required.item.getCount())
ItemStack stack = ItemHelper
.extract(iItemHandler, required::matches, ExtractionCountMode.EXACTLY,
required.stack.getCount(), true);
if (stack.isEmpty())
return;
}
for (ItemRequirement.StackRequirement required : requiredItems)
ItemHelper.extract(iItemHandler, s -> ItemRequirement.validate(required.item, s), ExtractionCountMode.UPTO,
required.item.getCount(), false);
contextStack = ItemHelper.extract(iItemHandler, required::matches, ExtractionCountMode.EXACTLY,
required.stack.getCount(), false);
}
CompoundTag data = null;
@ -142,7 +141,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
}
BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, pos);
BlockHelper.placeSchematicBlock(world, blockState, pos, firstRequired, data);
BlockHelper.placeSchematicBlock(world, blockState, pos, contextStack, data);
if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP))
blocksnapshot.restore(true, false);
}

View file

@ -255,10 +255,10 @@ public class CartAssemblerBlock extends BaseRailBlock
@Override
public ItemRequirement getRequiredItems(BlockState state, BlockEntity te) {
ArrayList<ItemStack> reuiredItems = new ArrayList<>();
reuiredItems.add(new ItemStack(getRailItem(state)));
reuiredItems.add(new ItemStack(asItem()));
return new ItemRequirement(ItemUseType.CONSUME, reuiredItems);
ArrayList<ItemStack> requiredItems = new ArrayList<>();
requiredItems.add(new ItemStack(getRailItem(state)));
requiredItems.add(new ItemStack(asItem()));
return new ItemRequirement(ItemUseType.CONSUME, requiredItems);
}
@Override

View file

@ -0,0 +1,11 @@
package com.simibubi.create.content.schematics;
import net.minecraft.world.level.block.state.BlockState;
public interface ISpecialBlockEntityItemRequirement {
default ItemRequirement getRequiredItems(BlockState state) {
return ItemRequirement.INVALID;
}
}

View file

@ -2,18 +2,18 @@ package com.simibubi.create.content.schematics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.AbstractBannerBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DirtPathBlock;
@ -21,41 +21,28 @@ import net.minecraft.world.level.block.FarmBlock;
import net.minecraft.world.level.block.SeaPickleBlock;
import net.minecraft.world.level.block.SnowLayerBlock;
import net.minecraft.world.level.block.TurtleEggBlock;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
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.SlabType;
public class ItemRequirement {
public static final ItemRequirement NONE = new ItemRequirement(Collections.emptyList());
public static final ItemRequirement INVALID = new ItemRequirement(Collections.emptyList());
public enum ItemUseType {
CONSUME, DAMAGE
}
public static class StackRequirement {
public final ItemStack item;
public final ItemUseType usage;
public StackRequirement(ItemUseType usage, ItemStack item) {
this.item = item;
this.usage = usage;
}
}
List<StackRequirement> requiredItems;
public static final ItemRequirement INVALID = new ItemRequirement();
public static final ItemRequirement NONE = new ItemRequirement();
private ItemRequirement() {
}
protected List<StackRequirement> requiredItems;
public ItemRequirement(List<StackRequirement> requiredItems) {
this.requiredItems = requiredItems;
}
public ItemRequirement(ItemUseType usage, ItemStack items) {
this(Arrays.asList(new StackRequirement(usage, items)));
public ItemRequirement(StackRequirement stackRequirement) {
this(List.of(stackRequirement));
}
public ItemRequirement(ItemUseType usage, ItemStack stack) {
this(new StackRequirement(stack, usage));
}
public ItemRequirement(ItemUseType usage, Item item) {
@ -63,28 +50,26 @@ public class ItemRequirement {
}
public ItemRequirement(ItemUseType usage, List<ItemStack> requiredItems) {
this(requiredItems.stream().map(req -> new StackRequirement(usage, req)).collect(Collectors.toList()));
this(requiredItems.stream().map(req -> new StackRequirement(req, usage)).collect(Collectors.toList()));
}
public static ItemRequirement of(BlockState state, BlockEntity te) {
Block block = state.getBlock();
ItemRequirement baseRequirement;
if (block instanceof ISpecialBlockItemRequirement) {
baseRequirement = ((ISpecialBlockItemRequirement) block).getRequiredItems(state, te);
ItemRequirement requirement;
if (block instanceof ISpecialBlockItemRequirement specialBlock) {
requirement = specialBlock.getRequiredItems(state, te);
} else {
baseRequirement = ofBlockState(state);
requirement = defaultOf(state, te);
}
// Behaviours can add additional required items
if (te instanceof SmartTileEntity)
baseRequirement = baseRequirement.with(((SmartTileEntity) te).getRequiredItems());
if (te instanceof ISpecialBlockEntityItemRequirement specialBE)
requirement = requirement.union(specialBE.getRequiredItems(state));
return baseRequirement;
return requirement;
}
private static ItemRequirement ofBlockState(BlockState state) {
private static ItemRequirement defaultOf(BlockState state, BlockEntity te) {
Block block = state.getBlock();
if (block == Blocks.AIR)
return NONE;
@ -95,22 +80,24 @@ public class ItemRequirement {
// double slab needs two items
if (state.hasProperty(BlockStateProperties.SLAB_TYPE) && state.getValue(BlockStateProperties.SLAB_TYPE) == SlabType.DOUBLE)
return new ItemRequirement(ItemUseType.CONSUME, Arrays.asList(new ItemStack(item, 2)));
return new ItemRequirement(ItemUseType.CONSUME, new ItemStack(item, 2));
if (block instanceof TurtleEggBlock)
return new ItemRequirement(ItemUseType.CONSUME, Arrays.asList(new ItemStack(item, state.getValue(TurtleEggBlock.EGGS).intValue())));
return new ItemRequirement(ItemUseType.CONSUME, new ItemStack(item, state.getValue(TurtleEggBlock.EGGS).intValue()));
if (block instanceof SeaPickleBlock)
return new ItemRequirement(ItemUseType.CONSUME, Arrays.asList(new ItemStack(item, state.getValue(SeaPickleBlock.PICKLES).intValue())));
return new ItemRequirement(ItemUseType.CONSUME, new ItemStack(item, state.getValue(SeaPickleBlock.PICKLES).intValue()));
if (block instanceof SnowLayerBlock)
return new ItemRequirement(ItemUseType.CONSUME, Arrays.asList(new ItemStack(item, state.getValue(SnowLayerBlock.LAYERS).intValue())));
return new ItemRequirement(ItemUseType.CONSUME, new ItemStack(item, state.getValue(SnowLayerBlock.LAYERS).intValue()));
if (block instanceof FarmBlock || block instanceof DirtPathBlock)
return new ItemRequirement(ItemUseType.CONSUME, Arrays.asList(new ItemStack(Items.DIRT)));
return new ItemRequirement(ItemUseType.CONSUME, Items.DIRT);
if (block instanceof AbstractBannerBlock && te instanceof BannerBlockEntity bannerBE)
return new ItemRequirement(new StrictNbtStackRequirement(bannerBE.getItem(), ItemUseType.CONSUME));
return new ItemRequirement(ItemUseType.CONSUME, item);
}
public static ItemRequirement of(Entity entity) {
if (entity instanceof ISpecialEntityItemRequirement)
return ((ISpecialEntityItemRequirement) entity).getRequiredItems();
if (entity instanceof ISpecialEntityItemRequirement specialEntity)
return specialEntity.getRequiredItems();
if (entity instanceof ItemFrame itemFrame) {
ItemStack frame = new ItemStack(Items.ITEM_FRAME);
@ -147,11 +134,7 @@ public class ItemRequirement {
return requiredItems;
}
public static boolean validate(ItemStack required, ItemStack present) {
return required.isEmpty() || required.getItem() == present.getItem();
}
public ItemRequirement with(ItemRequirement other) {
public ItemRequirement union(ItemRequirement other) {
if (this.isInvalid() || other.isInvalid())
return INVALID;
if (this.isEmpty())
@ -164,4 +147,32 @@ public class ItemRequirement {
);
}
public enum ItemUseType {
CONSUME, DAMAGE
}
public static class StackRequirement {
public final ItemStack stack;
public final ItemUseType usage;
public StackRequirement(ItemStack stack, ItemUseType usage) {
this.stack = stack;
this.usage = usage;
}
public boolean matches(ItemStack other) {
return stack.sameItem(other);
}
}
public static class StrictNbtStackRequirement extends StackRequirement {
public StrictNbtStackRequirement(ItemStack stack, ItemUseType usage) {
super(stack, usage);
}
@Override
public boolean matches(ItemStack other) {
return ItemStack.isSameItemSameTags(stack, other);
}
}
}

View file

@ -45,9 +45,9 @@ public class MaterialChecklist {
for (ItemRequirement.StackRequirement stack : requirement.requiredItems) {
if (stack.usage == ItemUseType.DAMAGE)
putOrIncrement(damageRequired, stack.item);
putOrIncrement(damageRequired, stack.stack);
if (stack.usage == ItemUseType.CONSUME)
putOrIncrement(required, stack.item);
putOrIncrement(required, stack.stack);
}
}

View file

@ -383,7 +383,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements MenuPro
List<ItemRequirement.StackRequirement> requiredItems = requirement.getRequiredItems();
if (!requirement.isEmpty()) {
for (ItemRequirement.StackRequirement required : requiredItems) {
if (!grabItemsFromAttachedInventories(required.item, required.usage, true)) {
if (!grabItemsFromAttachedInventories(required, true)) {
if (skipMissing) {
statusMsg = "skipping";
blockSkipped = true;
@ -394,7 +394,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements MenuPro
return;
}
missingItem = required.item;
missingItem = required.stack;
state = State.PAUSED;
statusMsg = "missingBlock";
return;
@ -402,12 +402,12 @@ public class SchematicannonTileEntity extends SmartTileEntity implements MenuPro
}
for (ItemRequirement.StackRequirement required : requiredItems)
grabItemsFromAttachedInventories(required.item, required.usage, false);
grabItemsFromAttachedInventories(required, false);
}
// Success
state = State.RUNNING;
ItemStack icon = requirement.isEmpty() || requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0).item;
ItemStack icon = requirement.isEmpty() || requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0).stack;
printer.handleCurrentTarget((target, blockState, tile) -> {
// Launch block
statusMsg = blockState.getBlock() != Blocks.AIR ? "placing" : "clearing";
@ -476,19 +476,21 @@ public class SchematicannonTileEntity extends SmartTileEntity implements MenuPro
return item == Items.AIR ? ItemStack.EMPTY : new ItemStack(item);
}
protected boolean grabItemsFromAttachedInventories(ItemStack required, ItemUseType usage, boolean simulate) {
protected boolean grabItemsFromAttachedInventories(ItemRequirement.StackRequirement required, boolean simulate) {
if (hasCreativeCrate)
return true;
attachedInventories.removeIf(cap -> !cap.isPresent());
ItemUseType usage = required.usage;
// Find and apply damage
if (usage == ItemUseType.DAMAGE) {
for (LazyOptional<IItemHandler> cap : attachedInventories) {
IItemHandler iItemHandler = cap.orElse(EmptyHandler.INSTANCE);
for (int slot = 0; slot < iItemHandler.getSlots(); slot++) {
ItemStack extractItem = iItemHandler.extractItem(slot, 1, true);
if (!ItemRequirement.validate(required, extractItem))
if (!required.matches(extractItem))
continue;
if (!extractItem.isDamageableItem())
continue;
@ -508,36 +510,36 @@ public class SchematicannonTileEntity extends SmartTileEntity implements MenuPro
return true;
}
}
return false;
}
// Find and remove
boolean success = false;
if (usage == ItemUseType.CONSUME) {
int amountFound = 0;
for (LazyOptional<IItemHandler> cap : attachedInventories) {
IItemHandler iItemHandler = cap.orElse(EmptyHandler.INSTANCE);
amountFound += ItemHelper
.extract(iItemHandler, s -> ItemRequirement.validate(required, s), ExtractionCountMode.UPTO,
required.getCount(), true)
.getCount();
int amountFound = 0;
for (LazyOptional<IItemHandler> cap : attachedInventories) {
IItemHandler iItemHandler = cap.orElse(EmptyHandler.INSTANCE);
amountFound += ItemHelper
.extract(iItemHandler, required::matches, ExtractionCountMode.UPTO,
required.stack.getCount(), true)
.getCount();
if (amountFound < required.getCount())
continue;
if (amountFound < required.stack.getCount())
continue;
success = true;
break;
}
success = true;
break;
}
if (!simulate && success) {
int amountFound = 0;
amountFound = 0;
for (LazyOptional<IItemHandler> cap : attachedInventories) {
IItemHandler iItemHandler = cap.orElse(EmptyHandler.INSTANCE);
amountFound += ItemHelper
.extract(iItemHandler, s -> ItemRequirement.validate(required, s), ExtractionCountMode.UPTO,
required.getCount(), false)
.extract(iItemHandler, required::matches, ExtractionCountMode.UPTO,
required.stack.getCount(), false)
.getCount();
if (amountFound < required.getCount())
if (amountFound < required.stack.getCount())
continue;
break;
}

View file

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.function.Consumer;
import com.simibubi.create.api.event.TileEntityBehaviourEvent;
import com.simibubi.create.content.schematics.ISpecialBlockEntityItemRequirement;
import com.simibubi.create.content.schematics.ItemRequirement;
import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
import com.simibubi.create.foundation.utility.IInteractionChecker;
@ -23,7 +24,7 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
public abstract class SmartTileEntity extends CachedRenderBBTileEntity implements IPartialSafeNBT, IInteractionChecker {
public abstract class SmartTileEntity extends CachedRenderBBTileEntity implements IPartialSafeNBT, IInteractionChecker, ISpecialBlockEntityItemRequirement {
private final Map<BehaviourType<?>, TileEntityBehaviour> behaviours = new HashMap<>();
private boolean initialized = false;
@ -172,9 +173,10 @@ public abstract class SmartTileEntity extends CachedRenderBBTileEntity implement
behaviour.initialize();
}
public ItemRequirement getRequiredItems() {
@Override
public ItemRequirement getRequiredItems(BlockState state) {
return behaviours.values().stream()
.reduce(ItemRequirement.NONE, (r, b) -> r.with(b.getRequiredItems()), (r, r1) -> r.with(r1));
.reduce(ItemRequirement.NONE, (r, b) -> r.union(b.getRequiredItems()), (r, r1) -> r.union(r1));
}
protected void removeBehaviour(BehaviourType<?> type) {

View file

@ -124,8 +124,8 @@ public class SidedFilteringBehaviour extends FilteringBehaviour {
public ItemRequirement getRequiredItems() {
return sidedFilters.values().stream().reduce(
ItemRequirement.NONE,
(a, b) -> a.with(b.getRequiredItems()),
(a, b) -> a.with(b)
(a, b) -> a.union(b.getRequiredItems()),
(a, b) -> a.union(b)
);
}

View file

@ -236,7 +236,6 @@ public class BlockHelper {
if (world.dimensionType()
.ultraWarm()
&& state.getFluidState()
.getType()
.is(FluidTags.WATER)) {
int i = target.getX();
int j = target.getY();