diff --git a/gradle.properties b/gradle.properties index 4f7fb8993..a53e8b198 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ modrinth_id=umyGl7zF minecraft_version=1.21 mod_version=2100.7.0 -neoforge_version=21.0.139-beta +neoforge_version=21.0.145 parchment_version=2024.07.07 rhino_version=2100.2.5-build.44 diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java index 20f77aae3..062607d1c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java @@ -13,7 +13,7 @@ import dev.latvian.mods.kubejs.block.callbacks.CanBeReplacedCallbackJS; import dev.latvian.mods.kubejs.block.callbacks.EntityFallenOnBlockCallbackJS; import dev.latvian.mods.kubejs.block.callbacks.EntitySteppedOnBlockCallbackJS; -import dev.latvian.mods.kubejs.block.entity.BlockEntityJS; +import dev.latvian.mods.kubejs.block.entity.KubeBlockEntity; import dev.latvian.mods.kubejs.level.BlockContainerJS; import dev.latvian.mods.kubejs.script.ScriptType; import net.minecraft.core.BlockPos; @@ -338,7 +338,7 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level @Override public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean bl) { if (!state.is(newState.getBlock())) { - if (level.getBlockEntity(pos) instanceof BlockEntityJS entity) { + if (level.getBlockEntity(pos) instanceof KubeBlockEntity entity) { if (level instanceof ServerLevel) { for (var attachment : entity.attachments) { attachment.onRemove(newState); @@ -354,7 +354,7 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new @Override public void setPlacedBy(Level level, BlockPos blockPos, BlockState blockState, @Nullable LivingEntity livingEntity, ItemStack itemStack) { - if (livingEntity != null && !level.isClientSide() && level.getBlockEntity(blockPos) instanceof BlockEntityJS e) { + if (livingEntity != null && !level.isClientSide() && level.getBlockEntity(blockPos) instanceof KubeBlockEntity e) { e.placerId = livingEntity.getUUID(); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachment.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachment.java index 9ae0d01c6..c37451daf 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachment.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachment.java @@ -11,7 +11,7 @@ public interface BlockEntityAttachment { BlockEntityAttachment[] EMPTY_ARRAY = new BlockEntityAttachment[0]; interface Factory { - BlockEntityAttachment create(BlockEntityJS entity); + BlockEntityAttachment create(KubeBlockEntity entity); } interface FactoryProvider { diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityEventCallback.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityEventCallback.java index 13de2e1b3..5687dfd2d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityEventCallback.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityEventCallback.java @@ -1,5 +1,5 @@ package dev.latvian.mods.kubejs.block.entity; public interface BlockEntityEventCallback { - void accept(BlockEntityJS entity, int data); + void accept(KubeBlockEntity entity, int data); } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityInfo.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityInfo.java index c33807c37..0dd7bba11 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityInfo.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityInfo.java @@ -101,7 +101,7 @@ public void eventHandler(int eventId, BlockEntityEventCallback callback) { public void rightClickOpensInventory() { blockBuilder.rightClick = e -> { - if (e.getBlock().getEntity() instanceof BlockEntityJS entity && entity.inventory != null) { + if (e.getBlock().getEntity() instanceof KubeBlockEntity entity && entity.inventory != null) { ((ServerPlayerKJS) e.getPlayer()).kjs$openInventoryGUI(entity.inventory, blockBuilder.get().getName()); } }; @@ -109,15 +109,15 @@ public void rightClickOpensInventory() { @HideFromJS public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { - return new BlockEntityJS(pos, state, this); + return new KubeBlockEntity(pos, state, this); } @HideFromJS public BlockEntityTicker getTicker(Level level) { if (level.isClientSide()) { - return clientTicking ? (BlockEntityTicker) BlockEntityJS.TICKER : null; + return clientTicking ? (BlockEntityTicker) KubeBlockEntity.TICKER : null; } else { - return serverTicking ? (BlockEntityTicker) BlockEntityJS.TICKER : null; + return serverTicking ? (BlockEntityTicker) KubeBlockEntity.TICKER : null; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityTickKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityTickKubeEvent.java index 97ba3cf1f..28a2fa6ca 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityTickKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityTickKubeEvent.java @@ -5,9 +5,9 @@ import net.minecraft.world.level.Level; public class BlockEntityTickKubeEvent implements KubeLevelEvent { - private final BlockEntityJS entity; + private final KubeBlockEntity entity; - public BlockEntityTickKubeEvent(BlockEntityJS entity) { + public BlockEntityTickKubeEvent(KubeBlockEntity entity) { this.entity = entity; } diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/InventoryAttachment.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/InventoryAttachment.java index 256110ac7..66ba908cf 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/InventoryAttachment.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/InventoryAttachment.java @@ -35,16 +35,16 @@ public class InventoryAttachment extends SimpleContainer implements BlockEntityA private record InventoryAttachmentFactory(int width, int height, @Nullable ItemPredicate inputFilter) implements Factory { @Override - public BlockEntityAttachment create(BlockEntityJS entity) { + public BlockEntityAttachment create(KubeBlockEntity entity) { return new InventoryAttachment(entity, width, height, inputFilter); } } public final int width, height; - public final BlockEntityJS blockEntity; + public final KubeBlockEntity blockEntity; public final ItemPredicate inputFilter; - public InventoryAttachment(BlockEntityJS blockEntity, int width, int height, @Nullable ItemPredicate inputFilter) { + public InventoryAttachment(KubeBlockEntity blockEntity, int width, int height, @Nullable ItemPredicate inputFilter) { super(width * height); this.width = width; this.height = height; diff --git a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityJS.java b/src/main/java/dev/latvian/mods/kubejs/block/entity/KubeBlockEntity.java similarity index 95% rename from src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityJS.java rename to src/main/java/dev/latvian/mods/kubejs/block/entity/KubeBlockEntity.java index 7ffdd7419..c983f0190 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/entity/KubeBlockEntity.java @@ -21,8 +21,8 @@ import java.util.UUID; -public class BlockEntityJS extends BlockEntity { - public static final BlockEntityTicker TICKER = (level, pos, state, entity) -> entity.tick(); +public class KubeBlockEntity extends BlockEntity { + public static final BlockEntityTicker TICKER = (level, pos, state, entity) -> entity.tick(); public final BlockEntityInfo info; public final ResourceKey blockKey; @@ -35,7 +35,7 @@ public class BlockEntityJS extends BlockEntity { public UUID placerId; private BlockEntityTickKubeEvent tickEvent; - public BlockEntityJS(BlockPos blockPos, BlockState blockState, BlockEntityInfo entityInfo) { + public KubeBlockEntity(BlockPos blockPos, BlockState blockState, BlockEntityInfo entityInfo) { super(entityInfo.entityType, blockPos, blockState); this.info = entityInfo; this.blockKey = blockState.kjs$getKey(); diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/TagEmptyConditionMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/TagEmptyConditionMixin.java new file mode 100644 index 000000000..d9cab4e80 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/TagEmptyConditionMixin.java @@ -0,0 +1,27 @@ +package dev.latvian.mods.kubejs.core.mixin; + +import dev.latvian.mods.kubejs.util.RegistryAccessContainer; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TagEmptyCondition; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(TagEmptyCondition.class) +public abstract class TagEmptyConditionMixin { + @Shadow + @Final + private TagKey tag; + + @Inject(method = "test", at = @At("HEAD"), cancellable = true, remap = false) + private void kjs$test(ICondition.IContext ctx, CallbackInfoReturnable cir) { + if (ctx instanceof RegistryAccessContainer c && c.cachedItemTags != null) { + cir.setReturnValue(c.cachedItemTags.isEmpty(tag)); + } + } +} \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/CachedTagLookup.java b/src/main/java/dev/latvian/mods/kubejs/recipe/CachedTagLookup.java index 2dd040790..132d3ec93 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/CachedTagLookup.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/CachedTagLookup.java @@ -45,6 +45,7 @@ public void visitOptionalDependencies(Consumer visitor) { public final Registry registry; public final Map> originalMap; + private Map>> tagMap; private Map, Set> keyToValue; private Map>> valueToKey; @@ -88,7 +89,7 @@ public Collection tag(ResourceLocation id) { return map; } - private Map, Set> keyToValue() { + public Map, Set> keyToValue() { if (keyToValue == null) { var map = build(originalMap); keyToValue = new Reference2ObjectOpenHashMap<>(map.size()); @@ -143,4 +144,25 @@ public Map, List>> bindingMap() { return map; } + + public Map>> tagMap() { + if (tagMap == null) { + tagMap = new HashMap<>(); + var k2v = keyToValue(); + + for (var entry : k2v.entrySet()) { + var list = new ArrayList>(entry.getValue().size()); + + for (var value : entry.getValue()) { + list.add(registry.wrapAsHolder(value)); + } + + tagMap.put(entry.getKey().location(), list); + } + + tagMap = Map.copyOf(tagMap); + } + + return tagMap; + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java b/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java index 8aac9fac7..5a19d4f87 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java @@ -511,7 +511,7 @@ public RecipeHolder createRecipe() { return new RecipeHolder<>(getOrCreateId(), originalRecipe.getValue()); } - return RecipeHelper.fromJson(type.event.registries.json(), getSerializationTypeFunction().schemaType.getSerializer(), getOrCreateId(), json, DevProperties.get().logErroringParsedRecipes); + return RecipeHelper.fromJson(type.event.jsonOps, getSerializationTypeFunction().schemaType.getSerializer(), getOrCreateId(), json, DevProperties.get().logErroringParsedRecipes); } @Nullable @@ -519,7 +519,7 @@ public Recipe getOriginalRecipe() { if (originalRecipe == null) { originalRecipe = new MutableObject<>(); try { - var holder = RecipeHelper.fromJson(type.event.registries.json(), type.schemaType.getSerializer(), getOrCreateId(), originalJson, DevProperties.get().logErroringParsedRecipes); + var holder = RecipeHelper.fromJson(type.event.jsonOps, type.schemaType.getSerializer(), getOrCreateId(), originalJson, DevProperties.get().logErroringParsedRecipes); if (holder != null) { originalRecipe.setValue(holder.value()); diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java index 0f7db1008..53c2ad6de 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java @@ -38,12 +38,14 @@ import dev.latvian.mods.rhino.util.HideFromJS; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeSerializer; +import net.neoforged.neoforge.common.conditions.ConditionalOps; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -120,6 +122,7 @@ private String recipeToString(Recipe recipe) { public final RecipeSchemaStorage recipeSchemaStorage; public final RegistryAccessContainer registries; + public final RegistryOps jsonOps; public final Map originalRecipes; public final Collection addedRecipes; private final BinaryOperator> mergeOriginal, mergeAdded; @@ -146,6 +149,7 @@ public RecipesKubeEvent(ServerScriptManager manager) { ConsoleJS.SERVER.info("Initializing recipe event..."); this.recipeSchemaStorage = manager.recipeSchemaStorage; this.registries = manager.getRegistries(); + this.jsonOps = new ConditionalOps<>(registries.json(), registries); this.originalRecipes = new HashMap<>(); this.addedRecipes = new ConcurrentLinkedQueue<>(); this.recipeFunctions = new HashMap<>(); @@ -235,7 +239,7 @@ public void post(RecipeManagerKJS recipeManager, Map Map>> getAllTags(ResourceKey> key) { + var cached = cachedRegistryTags.get(key); + + if (cached != null) { + return (Map) cached.lookup().tagMap(); + } + + return Map.of(); + } } diff --git a/src/main/resources/kubejs.mixins.json b/src/main/resources/kubejs.mixins.json index 4154e16ab..dcb3033b2 100644 --- a/src/main/resources/kubejs.mixins.json +++ b/src/main/resources/kubejs.mixins.json @@ -56,6 +56,7 @@ "SizedIngredientMixin", "StringRepresentableMixin", "StringTagMixin", + "TagEmptyConditionMixin", "TagLoaderMixin", "TagManagerMixin", "TextColorMixin",