From 30baef1740a2f9d90a92fea14a2c75910e26dfb1 Mon Sep 17 00:00:00 2001 From: TropheusJ <60247969+TropheusJ@users.noreply.github.com> Date: Fri, 21 Feb 2025 11:05:15 -0500 Subject: [PATCH] use tags for mounted item storage attributes (#16) --- .../f5350c6189acfbe5425c2432489f46008c69099a | 3 ++ .../fuel_blacklist.json | 5 ++ .../mounted_item_storage_type/internal.json | 5 ++ .../java/com/simibubi/create/AllTags.java | 28 +++++++++++ .../storage/item/MountedItemStorage.java | 23 --------- .../storage/item/MountedItemStorageType.java | 8 ++++ .../api/registry/CreateBuiltInRegistries.java | 2 +- .../registry/registrate/SimpleBuilder.java | 23 ++++----- .../contraptions/MountedStorageManager.java | 22 +++++---- .../dispenser/DropperMovementBehaviour.java | 4 +- .../storage/DispenserMountedStorage.java | 6 +-- .../vault/ItemVaultMountedStorage.java | 5 -- .../foundation/data/CreateRegistrate.java | 8 ++-- .../infrastructure/data/CreateDatagen.java | 1 + ...ateMountedItemStorageTypeTagsProvider.java | 47 +++++++++++++++++++ 15 files changed, 129 insertions(+), 61 deletions(-) create mode 100644 src/generated/resources/.cache/f5350c6189acfbe5425c2432489f46008c69099a create mode 100644 src/generated/resources/data/create/tags/create/mounted_item_storage_type/fuel_blacklist.json create mode 100644 src/generated/resources/data/create/tags/create/mounted_item_storage_type/internal.json create mode 100644 src/main/java/com/simibubi/create/infrastructure/data/CreateMountedItemStorageTypeTagsProvider.java diff --git a/src/generated/resources/.cache/f5350c6189acfbe5425c2432489f46008c69099a b/src/generated/resources/.cache/f5350c6189acfbe5425c2432489f46008c69099a new file mode 100644 index 0000000000..a185aa953b --- /dev/null +++ b/src/generated/resources/.cache/f5350c6189acfbe5425c2432489f46008c69099a @@ -0,0 +1,3 @@ +// 1.20.1 2025-02-20T19:36:44.18737762 Create's Mounted Item Storage Type Tags +c65f95f356db09e468847e5799a2cdd8e1417cac data/create/tags/create/mounted_item_storage_type/fuel_blacklist.json +fdadceec842a4cd12dd95f7e271645a52829ec6e data/create/tags/create/mounted_item_storage_type/internal.json diff --git a/src/generated/resources/data/create/tags/create/mounted_item_storage_type/fuel_blacklist.json b/src/generated/resources/data/create/tags/create/mounted_item_storage_type/fuel_blacklist.json new file mode 100644 index 0000000000..99eb273fe1 --- /dev/null +++ b/src/generated/resources/data/create/tags/create/mounted_item_storage_type/fuel_blacklist.json @@ -0,0 +1,5 @@ +{ + "values": [ + "create:vault" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/create/tags/create/mounted_item_storage_type/internal.json b/src/generated/resources/data/create/tags/create/mounted_item_storage_type/internal.json new file mode 100644 index 0000000000..f91fe16551 --- /dev/null +++ b/src/generated/resources/data/create/tags/create/mounted_item_storage_type/internal.json @@ -0,0 +1,5 @@ +{ + "values": [ + "create:dispenser" + ] +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index fe346733e5..48bc7c6cf6 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -9,6 +9,8 @@ import static com.simibubi.create.AllTags.NameSpace.TIC; import java.util.Collections; import com.simibubi.create.api.contraption.ContraptionType; +import com.simibubi.create.api.contraption.storage.item.MountedItemStorage; +import com.simibubi.create.api.contraption.storage.item.MountedItemStorageType; import com.simibubi.create.api.registry.CreateRegistries; import net.createmod.catnip.lang.Lang; @@ -423,6 +425,31 @@ public class AllTags { } } + public enum AllMountedItemStorageTypeTags { + INTERNAL, + FUEL_BLACKLIST; + + public final TagKey> tag; + public final boolean alwaysDatagen; + + AllMountedItemStorageTypeTags() { + ResourceLocation tagId = Create.asResource(Lang.asId(this.name())); + this.tag = TagKey.create(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE, tagId); + this.alwaysDatagen = true; + } + + public boolean matches(MountedItemStorage storage) { + return this.matches(storage.type); + } + + public boolean matches(MountedItemStorageType type) { + return type.is(this.tag); + } + + private static void init() { + } + } + public static void init() { AllBlockTags.init(); AllItemTags.init(); @@ -430,5 +457,6 @@ public class AllTags { AllEntityTags.init(); AllRecipeSerializerTags.init(); AllContraptionTypeTags.init(); + AllMountedItemStorageTypeTags.init(); } } diff --git a/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorage.java b/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorage.java index 8390b8a6f0..4b7ba3fe74 100644 --- a/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorage.java +++ b/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorage.java @@ -8,11 +8,8 @@ import java.util.function.Predicate; import org.jetbrains.annotations.Nullable; import com.mojang.serialization.Codec; -import com.simibubi.create.api.behaviour.movement.MovementBehaviour; import com.simibubi.create.api.contraption.storage.item.menu.MountedStorageMenus; import com.simibubi.create.content.contraptions.Contraption; -import com.simibubi.create.content.contraptions.MountedStorageManager; -import com.simibubi.create.content.contraptions.behaviour.MovementContext; import com.simibubi.create.foundation.utility.CreateLang; import net.minecraft.core.BlockPos; @@ -49,26 +46,6 @@ public abstract class MountedItemStorage implements IItemHandlerModifiable { */ public abstract void unmount(Level level, BlockState state, BlockPos pos, @Nullable BlockEntity be); - /** - * Internal mounted storages are not exposed to the larger contraption inventory. - * They are only for internal use, such as access from a {@link MovementBehaviour}. - * Internal storages are still accessible through {@link MovementContext#getItemStorage()} - * as well as {@link MountedStorageManager#getAllItemStorages()}. - * A storage being internal implies that it does not provide fuel either. - * This is only called once on assembly. - */ - public boolean isInternal() { - return false; - } - - /** - * Contraptions may search storage for fuel, such as for powering furnace minecarts - * and trains. Return false if this storage should - */ - public boolean providesFuel() { - return true; - } - /** * Handle a player clicking on this mounted storage. This is always called on the server. * The default implementation will try to open a generic GUI for standard inventories. diff --git a/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorageType.java b/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorageType.java index db7e36ba7b..9386173fc7 100644 --- a/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorageType.java +++ b/src/main/java/com/simibubi/create/api/contraption/storage/item/MountedItemStorageType.java @@ -13,6 +13,8 @@ import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; import net.minecraft.Util; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.tags.TagKey; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -27,9 +29,15 @@ public abstract class MountedItemStorageType { }); public final Codec codec; + public final Holder> holder; protected MountedItemStorageType(Codec codec) { this.codec = codec; + this.holder = CreateBuiltInRegistries.MOUNTED_ITEM_STORAGE_TYPE.createIntrusiveHolder(this); + } + + public final boolean is(TagKey> tag) { + return this.holder.is(tag); } @Nullable diff --git a/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java b/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java index 14107ebffd..7e5182cb85 100644 --- a/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java +++ b/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java @@ -33,7 +33,7 @@ public class CreateBuiltInRegistries { public static final Registry ITEM_ATTRIBUTE_TYPE = simple(CreateRegistries.ITEM_ATTRIBUTE_TYPE); public static final Registry DISPLAY_SOURCE = simple(CreateRegistries.DISPLAY_SOURCE); public static final Registry DISPLAY_TARGET = simple(CreateRegistries.DISPLAY_TARGET); - public static final Registry> MOUNTED_ITEM_STORAGE_TYPE = simple(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE); + public static final Registry> MOUNTED_ITEM_STORAGE_TYPE = withIntrusiveHolders(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE); public static final Registry> MOUNTED_FLUID_STORAGE_TYPE = simple(CreateRegistries.MOUNTED_FLUID_STORAGE_TYPE); public static final Registry CONTRAPTION_TYPE = withIntrusiveHolders(CreateRegistries.CONTRAPTION_TYPE); diff --git a/src/main/java/com/simibubi/create/api/registry/registrate/SimpleBuilder.java b/src/main/java/com/simibubi/create/api/registry/registrate/SimpleBuilder.java index 215d985648..81e6e9fbc2 100644 --- a/src/main/java/com/simibubi/create/api/registry/registrate/SimpleBuilder.java +++ b/src/main/java/com/simibubi/create/api/registry/registrate/SimpleBuilder.java @@ -2,6 +2,7 @@ package com.simibubi.create.api.registry.registrate; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; @@ -22,21 +23,21 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.material.Fluid; public class SimpleBuilder extends AbstractBuilder> { - private final T value; + private final Supplier value; private SimpleRegistryAccess byBlock; private SimpleRegistryAccess, R> byBlockEntity; private SimpleRegistryAccess, R> byEntity; private SimpleRegistryAccess byFluid; - public SimpleBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceKey> registryKey, T value) { + public SimpleBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceKey> registryKey, Supplier value) { super(owner, parent, name, callback, registryKey); this.value = value; } @Override protected T createEntry() { - return this.value; + return this.value.get(); } // for setup @@ -91,49 +92,49 @@ public class SimpleBuilder extends AbstractBuilder associate(Block block) { assertPresent(this.byBlock, "Block"); - this.byBlock.adder.accept(block, this.value); + this.onRegister(value -> this.byBlock.adder.accept(block, value)); return this; } public SimpleBuilder associateBlockTag(TagKey tag) { assertPresent(this.byBlock, "Block"); - this.byBlock.tagAdder.accept(tag, this.value); + this.onRegister(value -> this.byBlock.tagAdder.accept(tag, value)); return this; } public SimpleBuilder associate(BlockEntityType type) { assertPresent(this.byBlockEntity, "BlockEntityType"); - this.byBlockEntity.adder.accept(type, this.value); + this.onRegister(value -> this.byBlockEntity.adder.accept(type, value)); return this; } public SimpleBuilder associateBeTag(TagKey> tag) { assertPresent(this.byBlockEntity, "BlockEntityType"); - this.byBlockEntity.tagAdder.accept(tag, this.value); + this.onRegister(value -> this.byBlockEntity.tagAdder.accept(tag, value)); return this; } public SimpleBuilder associate(EntityType type) { assertPresent(this.byEntity, "EntityType"); - this.byEntity.adder.accept(type, this.value); + this.onRegister(value -> this.byEntity.adder.accept(type, value)); return this; } public SimpleBuilder associateEntityTag(TagKey> tag) { assertPresent(this.byEntity, "EntityType"); - this.byEntity.tagAdder.accept(tag, this.value); + this.onRegister(value -> this.byEntity.tagAdder.accept(tag, value)); return this; } public SimpleBuilder associate(Fluid fluid) { assertPresent(this.byFluid, "Fluid"); - this.byFluid.adder.accept(fluid, this.value); + this.onRegister(value -> this.byFluid.adder.accept(fluid, value)); return this; } public SimpleBuilder associateFluidTag(TagKey tag) { assertPresent(this.byFluid, "Fluid"); - this.byFluid.tagAdder.accept(tag, this.value); + this.onRegister(value -> this.byFluid.tagAdder.accept(tag, value)); return this; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/MountedStorageManager.java b/src/main/java/com/simibubi/create/content/contraptions/MountedStorageManager.java index e3f51871c1..1ce9554475 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/MountedStorageManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/MountedStorageManager.java @@ -16,6 +16,7 @@ import com.google.common.collect.Sets; import com.google.common.collect.Sets.SetView; import com.mojang.datafixers.util.Pair; import com.simibubi.create.AllPackets; +import com.simibubi.create.AllTags.AllMountedItemStorageTypeTags; import com.simibubi.create.Create; import com.simibubi.create.api.contraption.storage.SyncedMountedStorage; import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorage; @@ -96,16 +97,12 @@ public class MountedStorageManager { this.allItemStorages = ImmutableMap.copyOf(this.itemsBuilder); - this.items = new MountedItemStorageWrapper(subMap( - this.allItemStorages, storage -> !storage.isInternal() - )); + this.items = new MountedItemStorageWrapper(subMap(this.allItemStorages, this::isExposed)); this.allItems = this.items; this.itemsBuilder = null; - ImmutableMap fuelMap = subMap( - this.allItemStorages, storage -> !storage.isInternal() && storage.providesFuel() - ); + ImmutableMap fuelMap = subMap(this.allItemStorages, this::canUseForFuel); this.fuelItems = fuelMap.isEmpty() ? null : new MountedItemStorageWrapper(fuelMap); ImmutableMap fluids = ImmutableMap.copyOf(this.fluidsBuilder); @@ -118,6 +115,14 @@ public class MountedStorageManager { this.syncedFluidsBuilder = null; } + private boolean isExposed(MountedItemStorage storage) { + return !AllMountedItemStorageTypeTags.INTERNAL.matches(storage); + } + + private boolean canUseForFuel(MountedItemStorage storage) { + return this.isExposed(storage) && !AllMountedItemStorageTypeTags.FUEL_BLACKLIST.matches(storage); + } + private boolean isInitialized() { return this.itemsBuilder == null; } @@ -363,10 +368,7 @@ public class MountedStorageManager { } /** - * Gets a map of all MountedItemStorages in the contraption, irrelevant of them - * being internal or providing fuel. - * @see MountedItemStorage#isInternal() - * @see MountedItemStorage#providesFuel() + * Gets a map of all MountedItemStorages in the contraption, irrelevant of them being internal or providing fuel. */ public ImmutableMap getAllItemStorages() { this.assertInitialized(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/DropperMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/DropperMovementBehaviour.java index cfb5b9fc56..581ed17556 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/DropperMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/DropperMovementBehaviour.java @@ -59,8 +59,8 @@ public class DropperMovementBehaviour implements MovementBehaviour { if (stack.getCount() == 1 && stack.getMaxStackSize() != 1) { stack = tryTopOff(stack, contraptionInventory); - if (stack == null) { - continue; + if (stack != null) { + storage.setStackInSlot(i, stack); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/storage/DispenserMountedStorage.java b/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/storage/DispenserMountedStorage.java index b20c5cd906..e085b22c47 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/storage/DispenserMountedStorage.java +++ b/src/main/java/com/simibubi/create/content/contraptions/behaviour/dispenser/storage/DispenserMountedStorage.java @@ -16,6 +16,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; + import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -30,11 +31,6 @@ public class DispenserMountedStorage extends SimpleMountedStorage { this(AllMountedStorageTypes.DISPENSER.get(), handler); } - @Override - public boolean isInternal() { - return true; - } - @Override @Nullable protected MenuProvider createMenuProvider(Component name, IItemHandlerModifiable handler, diff --git a/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultMountedStorage.java b/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultMountedStorage.java index 244c533f79..035f80b337 100644 --- a/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultMountedStorage.java +++ b/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultMountedStorage.java @@ -45,11 +45,6 @@ public class ItemVaultMountedStorage extends WrapperMountedItemStorage { public > SimpleBuilder, T, CreateRegistrate> mountedItemStorage(String name, Supplier supplier) { return this.entry(name, callback -> new SimpleBuilder<>( - this, this, name, callback, CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE, supplier.get() + this, this, name, callback, CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE, supplier ).byBlock(MountedItemStorageType.REGISTRY)); } public > SimpleBuilder, T, CreateRegistrate> mountedFluidStorage(String name, Supplier supplier) { return this.entry(name, callback -> new SimpleBuilder<>( - this, this, name, callback, CreateRegistries.MOUNTED_FLUID_STORAGE_TYPE, supplier.get() + this, this, name, callback, CreateRegistries.MOUNTED_FLUID_STORAGE_TYPE, supplier ).byBlock(MountedFluidStorageType.REGISTRY)); } public SimpleBuilder displaySource(String name, Supplier supplier) { return this.entry(name, callback -> new SimpleBuilder<>( - this, this, name, callback, CreateRegistries.DISPLAY_SOURCE, supplier.get() + this, this, name, callback, CreateRegistries.DISPLAY_SOURCE, supplier ).byBlock(DisplaySource.BY_BLOCK).byBlockEntity(DisplaySource.BY_BLOCK_ENTITY)); } public SimpleBuilder displayTarget(String name, Supplier supplier) { return this.entry(name, callback -> new SimpleBuilder<>( - this, this, name, callback, CreateRegistries.DISPLAY_TARGET, supplier.get() + this, this, name, callback, CreateRegistries.DISPLAY_TARGET, supplier ).byBlock(DisplayTarget.BY_BLOCK).byBlockEntity(DisplayTarget.BY_BLOCK_ENTITY)); } diff --git a/src/main/java/com/simibubi/create/infrastructure/data/CreateDatagen.java b/src/main/java/com/simibubi/create/infrastructure/data/CreateDatagen.java index f40866cfe8..85f901f519 100644 --- a/src/main/java/com/simibubi/create/infrastructure/data/CreateDatagen.java +++ b/src/main/java/com/simibubi/create/infrastructure/data/CreateDatagen.java @@ -44,6 +44,7 @@ public class CreateDatagen { generator.addProvider(event.includeServer(), new CreateRecipeSerializerTagsProvider(output, lookupProvider, existingFileHelper)); generator.addProvider(event.includeServer(), new CreateContraptionTypeTagsProvider(output, lookupProvider, existingFileHelper)); + generator.addProvider(event.includeServer(), new CreateMountedItemStorageTypeTagsProvider(output, lookupProvider, existingFileHelper)); generator.addProvider(event.includeServer(), new DamageTypeTagGen(output, lookupProvider, existingFileHelper)); generator.addProvider(event.includeServer(), new AllAdvancements(output)); generator.addProvider(event.includeServer(), new StandardRecipeGen(output)); diff --git a/src/main/java/com/simibubi/create/infrastructure/data/CreateMountedItemStorageTypeTagsProvider.java b/src/main/java/com/simibubi/create/infrastructure/data/CreateMountedItemStorageTypeTagsProvider.java new file mode 100644 index 0000000000..3e314f0a48 --- /dev/null +++ b/src/main/java/com/simibubi/create/infrastructure/data/CreateMountedItemStorageTypeTagsProvider.java @@ -0,0 +1,47 @@ +package com.simibubi.create.infrastructure.data; + +import java.util.concurrent.CompletableFuture; + +import org.jetbrains.annotations.Nullable; + +import com.simibubi.create.AllMountedStorageTypes; +import com.simibubi.create.AllTags.AllMountedItemStorageTypeTags; +import com.simibubi.create.Create; +import com.simibubi.create.api.contraption.storage.item.MountedItemStorageType; +import com.simibubi.create.api.registry.CreateRegistries; + +import net.minecraft.core.HolderLookup.Provider; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.TagsProvider; +import net.minecraft.tags.TagEntry; + +import net.minecraftforge.common.data.ExistingFileHelper; + +public class CreateMountedItemStorageTypeTagsProvider extends TagsProvider> { + public CreateMountedItemStorageTypeTagsProvider(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { + super(output, CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE, lookupProvider, Create.ID, existingFileHelper); + } + + @Override + protected void addTags(Provider pProvider) { + tag(AllMountedItemStorageTypeTags.INTERNAL.tag).add( + TagEntry.element(AllMountedStorageTypes.DISPENSER.getId()) + ); + tag(AllMountedItemStorageTypeTags.FUEL_BLACKLIST.tag).add( + TagEntry.element(AllMountedStorageTypes.VAULT.getId()) + ); + + // VALIDATE + + for (AllMountedItemStorageTypeTags tag : AllMountedItemStorageTypeTags.values()) { + if (tag.alwaysDatagen) { + getOrCreateRawBuilder(tag.tag); + } + } + } + + @Override + public String getName() { + return "Create's Mounted Item Storage Type Tags"; + } +}