From 682961ab253fc50fd48d529dbe9dae92d9957755 Mon Sep 17 00:00:00 2001 From: Mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Sun, 12 Nov 2023 23:08:20 +0100 Subject: [PATCH] Fixes on 1.19 (#544) * Whoops! You Have To Put The CD In Your Computer! * GOD WHY WON'T YOU WORK * fix: hulls are no longer counted as energy inputs in cleanrooms (#543) * fix: injecting packs now works on 1.19 --------- Co-authored-by: screret <68943070+screret@users.noreply.github.com> --- CHANGELOG.md | 2 +- .../gtceu/api/item/TagPrefixItem.java | 1 + .../renderer/block/MaterialBlockRenderer.java | 13 ++--- .../renderer/block/OreBlockRenderer.java | 1 - .../renderer/item/TagPrefixItemRenderer.java | 9 ++-- .../renderer/item/ToolItemRenderer.java | 4 +- .../renderer/machine/QuantumTankRenderer.java | 1 + .../gtceu/common/cover/PumpCover.java | 1 + .../gtceu/common/data/GTBlocks.java | 1 + .../multiblock/electric/CleanroomMachine.java | 32 +++++++++--- .../common/pipelike/cable/Insulation.java | 10 +++- .../gregtechceu/gtceu/core/MixinHelpers.java | 33 +++++++++++- .../gtceu/core/mixins/MinecraftMixin.java | 22 -------- .../core/mixins/PackRepositoryMixin.java | 19 +++++++ .../gtceu/data/lang/LangHandler.java | 3 ++ .../gtceu/data/pack/GTDynamicDataPack.java | 1 + .../data/pack/GTDynamicResourcePack.java | 52 +++++++++---------- .../main/resources/gtceu-common.mixins.json | 2 +- settings.gradle | 5 +- 19 files changed, 132 insertions(+), 80 deletions(-) delete mode 100644 common/src/main/java/com/gregtechceu/gtceu/core/mixins/MinecraftMixin.java create mode 100644 common/src/main/java/com/gregtechceu/gtceu/core/mixins/PackRepositoryMixin.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 837b0f68cb..a9cb27cc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,4 +18,4 @@ Version: 1.0.15 * fix item pipes stopping transfer after their transfer rate per second has been reached once * fix capability IO directions * fix laser pipes not connecting to hatches -* fix diodes being counted as energy input in cleanrooms \ No newline at end of file +* fix diodes and hulls being counted as energy input in cleanrooms \ No newline at end of file diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/item/TagPrefixItem.java b/common/src/main/java/com/gregtechceu/gtceu/api/item/TagPrefixItem.java index 707bba5673..4b8e9623fd 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/item/TagPrefixItem.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/item/TagPrefixItem.java @@ -8,6 +8,7 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; +import com.lowdragmc.lowdraglib.Platform; import com.lowdragmc.lowdraglib.client.renderer.IItemRendererProvider; import com.lowdragmc.lowdraglib.client.renderer.IRenderer; import dev.architectury.injectables.annotations.ExpectPlatform; diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/MaterialBlockRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/MaterialBlockRenderer.java index 0e5320e7cc..7bfa9b9b85 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/MaterialBlockRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/MaterialBlockRenderer.java @@ -10,7 +10,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.metadata.animation.AnimationFrame; import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.Registry; import net.minecraft.data.models.BlockModelGenerators; import net.minecraft.data.models.model.*; import net.minecraft.resources.ResourceLocation; @@ -37,20 +37,20 @@ public static void create(Block block, MaterialIconType type, MaterialIconSet ic public static void reinitModels() { for (MaterialBlockRenderer model : MODELS) { - ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(model.block); - ResourceLocation modelId = blockId.withPrefix("block/"); + ResourceLocation blockId = Registry.BLOCK.getKey(model.block); + ResourceLocation modelId = new ResourceLocation(blockId.getNamespace(), "block/" + blockId.getPath()); GTDynamicResourcePack.addBlockModel(modelId, new DelegatedModel(model.type.getBlockModelPath(model.iconSet, true))); GTDynamicResourcePack.addBlockState(blockId, BlockModelGenerators.createSimpleBlock(model.block, modelId)); // ModelTemplates.CUBE_ALL.create(model.block, // cubeTwoLayer(model.type.getBlockTexturePath(model.iconSet, true), model.type.getBlockTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX)), // GTDynamicResourcePack::addBlockModel))); - GTDynamicResourcePack.addItemModel(BuiltInRegistries.ITEM.getKey(model.block.asItem()), new DelegatedModel(ModelLocationUtils.getModelLocation(model.block))); + GTDynamicResourcePack.addItemModel(Registry.ITEM.getKey(model.block.asItem()), new DelegatedModel(ModelLocationUtils.getModelLocation(model.block))); } } public static void initTextures() { for (MaterialBlockRenderer model : MODELS) { - ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(model.block); + ResourceLocation blockId = Registry.BLOCK.getKey(model.block); Resource file1 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getBlockTexturePath(model.iconSet, true)/*.withSuffix("_layer1")*/)).orElse(null); if (file1 == null) continue; @@ -68,7 +68,8 @@ public static void initTextures() { } if (materialBlock.material.getMaterialSecondaryRGB() != -1) { int materialSecondaryRGBA = GradientUtil.argbToRgba(materialBlock.material.getMaterialSecondaryARGB()); - Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getBlockTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX))).orElse(null); + ResourceLocation path = model.type.getBlockTexturePath(model.iconSet, true); + Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, new ResourceLocation(path.getNamespace(), path.getPath() + LAYER_2_SUFFIX))).orElse(null); if (file2 != null) { try(InputStream stream2 = file2.open()) { NativeImage image2 = NativeImage.read(stream2); diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java index 78c935eddb..2c448f347b 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java @@ -25,7 +25,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/TagPrefixItemRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/TagPrefixItemRenderer.java index 2f9db1b31e..67b0a80c6f 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/TagPrefixItemRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/TagPrefixItemRenderer.java @@ -9,7 +9,7 @@ import com.gregtechceu.gtceu.utils.GradientUtil; import com.mojang.blaze3d.platform.NativeImage; import net.minecraft.client.Minecraft; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.Registry; import net.minecraft.data.models.model.DelegatedModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.Resource; @@ -36,7 +36,7 @@ public static void create(Item item, MaterialIconType type, MaterialIconSet icon public static void reinitModels() { for (TagPrefixItemRenderer model : MODELS) { - ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(model.item); + ResourceLocation itemId = Registry.ITEM.getKey(model.item); GTDynamicResourcePack.addItemModel(itemId, new DelegatedModel(model.type.getItemModelPath(model.iconSet, true))); //ModelTemplates.FLAT_ITEM.create(GTDynamicResourcePack.getItemModelLocation(itemId), TextureMapping.layer0(itemId.withPrefix("item/")), GTDynamicResourcePack::addItemModel); } @@ -44,7 +44,7 @@ public static void reinitModels() { public static void initTextures() { for (TagPrefixItemRenderer model : MODELS) { - ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(model.item); + ResourceLocation itemId = Registry.ITEM.getKey(model.item); Resource file1 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getItemTexturePath(model.iconSet, true)/*.withSuffix("_layer1")*/)).orElse(null); if (file1 == null) continue; @@ -62,7 +62,8 @@ public static void initTextures() { } } if (prefixItem.material.getMaterialSecondaryRGB() != -1) { - Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getItemTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX))).orElse(null); + ResourceLocation path = model.type.getItemTexturePath(model.iconSet, true); + Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, new ResourceLocation(path.getNamespace(), path.getPath() + LAYER_2_SUFFIX))).orElse(null); if (file2 != null) { try(InputStream stream2 = file2.open()) { NativeImage image2 = NativeImage.read(stream2); diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java index 86220c9694..53574e429f 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java @@ -4,7 +4,7 @@ import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.Registry; import net.minecraft.data.models.model.DelegatedModel; import net.minecraft.world.item.Item; @@ -21,7 +21,7 @@ public class ToolItemRenderer { public static void reinitModels() { for (ToolItemRenderer model : MODELS) { - GTDynamicResourcePack.addItemModel(BuiltInRegistries.ITEM.getKey(model.item), new DelegatedModel(model.toolType.modelLocation)); + GTDynamicResourcePack.addItemModel(Registry.ITEM.getKey(model.item), new DelegatedModel(model.toolType.modelLocation)); } } diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/machine/QuantumTankRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/machine/QuantumTankRenderer.java index 75d92f109c..65c98d8981 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/machine/QuantumTankRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/machine/QuantumTankRenderer.java @@ -17,6 +17,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.Sheets; +import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.resources.model.BakedModel; diff --git a/common/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java b/common/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java index 46c7fb80cf..4c48c18141 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java +++ b/common/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java @@ -36,6 +36,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java b/common/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java index 4dc1b47cb7..4e41c2432a 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java +++ b/common/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.common.data; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; diff --git a/common/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CleanroomMachine.java b/common/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CleanroomMachine.java index 0c8dc42ea8..5c29e0d03c 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CleanroomMachine.java +++ b/common/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CleanroomMachine.java @@ -7,8 +7,6 @@ import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; import com.gregtechceu.gtceu.api.capability.ICleanroomReceiver; import com.gregtechceu.gtceu.api.capability.IEnergyContainer; -import com.gregtechceu.gtceu.common.machine.multiblock.part.DiodePartMachine; -import com.gregtechceu.gtceu.common.machine.trait.CleanroomLogic; import com.gregtechceu.gtceu.api.capability.recipe.EURecipeCapability; import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; @@ -19,14 +17,23 @@ import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine; import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMufflerMachine; import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart; -import com.gregtechceu.gtceu.api.machine.multiblock.*; +import com.gregtechceu.gtceu.api.machine.multiblock.CleanroomType; +import com.gregtechceu.gtceu.api.machine.multiblock.PartAbility; +import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine; +import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; import com.gregtechceu.gtceu.api.misc.EnergyContainerList; -import com.gregtechceu.gtceu.api.pattern.*; +import com.gregtechceu.gtceu.api.pattern.BlockPattern; +import com.gregtechceu.gtceu.api.pattern.FactoryBlockPattern; +import com.gregtechceu.gtceu.api.pattern.Predicates; +import com.gregtechceu.gtceu.api.pattern.TraceabilityPredicate; import com.gregtechceu.gtceu.common.data.GTBlocks; +import com.gregtechceu.gtceu.common.machine.electric.HullMachine; +import com.gregtechceu.gtceu.common.machine.multiblock.part.DiodePartMachine; import com.gregtechceu.gtceu.common.machine.multiblock.primitive.CokeOvenMachine; import com.gregtechceu.gtceu.common.machine.multiblock.primitive.PrimitiveBlastFurnaceMachine; import com.gregtechceu.gtceu.common.machine.multiblock.primitive.PrimitivePumpMachine; +import com.gregtechceu.gtceu.common.machine.trait.CleanroomLogic; import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -53,7 +60,8 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.*; -import static com.gregtechceu.gtceu.api.pattern.Predicates.*; +import static com.gregtechceu.gtceu.api.pattern.Predicates.abilities; +import static com.gregtechceu.gtceu.api.pattern.Predicates.states; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @@ -158,9 +166,9 @@ protected void initializeAbilities() { List energyContainers = new ArrayList<>(); Map ioMap = getMultiblockState().getMatchContext().getOrCreate("ioMap", Long2ObjectMaps::emptyMap); for (IMultiPart part : getParts()) { - if (part instanceof DiodePartMachine) continue; + if (isPartIgnored(part)) continue; IO io = ioMap.getOrDefault(part.self().getPos().asLong(), IO.BOTH); - if(io == IO.NONE || io == IO.OUT) continue; + if (io == IO.NONE || io == IO.OUT) continue; for (var handler : part.getRecipeHandlers()) { // If IO not compatible if (io != IO.BOTH && handler.getHandlerIO() != IO.BOTH && io != handler.getHandlerIO()) continue; @@ -176,6 +184,14 @@ protected void initializeAbilities() { getRecipeLogic().setEnergyContainer(this.inputEnergyContainers); } + @SuppressWarnings("RedundantIfStatement") // `return false` being a separate statement is better for readability + private static boolean isPartIgnored(IMultiPart part) { + if (part instanceof DiodePartMachine) return true; + if (part instanceof HullMachine) return true; + + return false; + } + /** * Scans for blocks around the controller to update the dimensions */ @@ -376,7 +392,7 @@ protected BlockState getGlassState() { @Nonnull protected static TraceabilityPredicate doorPredicate() { return Predicates.custom(blockWorldState -> blockWorldState.getBlockState().getBlock() instanceof DoorBlock, - () -> new BlockInfo[] {new BlockInfo(Blocks.IRON_DOOR.defaultBlockState()), new BlockInfo(Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER))}); + () -> new BlockInfo[]{new BlockInfo(Blocks.IRON_DOOR.defaultBlockState()), new BlockInfo(Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER))}); } @Nonnull diff --git a/common/src/main/java/com/gregtechceu/gtceu/common/pipelike/cable/Insulation.java b/common/src/main/java/com/gregtechceu/gtceu/common/pipelike/cable/Insulation.java index cf3471e587..e18fe94655 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/common/pipelike/cable/Insulation.java +++ b/common/src/main/java/com/gregtechceu/gtceu/common/pipelike/cable/Insulation.java @@ -79,8 +79,14 @@ public ResourceLocation type() { } public PipeModel createPipeModel(Material material) { - Supplier wireSideTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true).withSuffix("_side"); - Supplier wireEndTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true).withSuffix("_end"); + Supplier wireSideTexturePath = () -> { + ResourceLocation location = MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true); + return new ResourceLocation(location.getNamespace(), location.getPath() + "_side"); + }; + Supplier wireEndTexturePath = () -> { + ResourceLocation location = MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true); + return new ResourceLocation(location.getNamespace(), location.getPath() + "_end"); + }; Supplier<@Nullable ResourceLocation> wireSideOverlayTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), "side_overlay", true); Supplier<@Nullable ResourceLocation> wireEndOverlayTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), "end_overlay", true); PipeModel model = new PipeModel(thickness, isCable ? () -> GTCEu.id("block/cable/insulation_5") : wireSideTexturePath, wireEndTexturePath, wireSideOverlayTexturePath, wireEndOverlayTexturePath); diff --git a/common/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java b/common/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java index e4c827eb01..9505c16e37 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java +++ b/common/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java @@ -9,20 +9,26 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; +import com.gregtechceu.gtceu.api.fluids.GTFluid; import com.gregtechceu.gtceu.api.fluids.store.FluidStorage; +import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey; +import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.client.renderer.block.MaterialBlockRenderer; import com.gregtechceu.gtceu.client.renderer.item.TagPrefixItemRenderer; import com.gregtechceu.gtceu.client.renderer.item.ToolItemRenderer; -import com.gregtechceu.gtceu.common.data.GTModels; import com.gregtechceu.gtceu.common.data.GTRecipes; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.core.mixins.BlockBehaviourAccessor; import com.gregtechceu.gtceu.data.pack.GTDynamicDataPack; import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack; import com.gregtechceu.gtceu.data.recipe.CustomTags; +import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; +import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.tterrag.registrate.util.entry.BlockEntry; import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.core.Registry; import net.minecraft.data.loot.BlockLoot; +import net.minecraft.data.models.model.DelegatedModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackResources; import net.minecraft.tags.BlockTags; @@ -30,6 +36,7 @@ import net.minecraft.tags.TagKey; import net.minecraft.tags.TagLoader; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; @@ -108,7 +115,7 @@ public static List addDynamicResourcePack(Collection addDynamicResourcePack(Collection"}, - at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/repository/PackRepository;openAllSelected()Ljava/util/List;") - ) - private List gtceu$loadPacks(List resources) { - return MixinHelpers.addDynamicResourcePack(resources); - } -} diff --git a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/PackRepositoryMixin.java b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/PackRepositoryMixin.java new file mode 100644 index 0000000000..19d3078d76 --- /dev/null +++ b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/PackRepositoryMixin.java @@ -0,0 +1,19 @@ +package com.gregtechceu.gtceu.core.mixins; + +import com.gregtechceu.gtceu.core.MixinHelpers; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.repository.PackRepository; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(value = PackRepository.class, priority = 900) +public class PackRepositoryMixin { + @Inject(method = "openAllSelected", cancellable = true, at = @At(value = "RETURN")) + private void gtceu$loadPacks(CallbackInfoReturnable> cir) { + cir.setReturnValue(MixinHelpers.addDynamicResourcePack(cir.getReturnValue())); + } +} diff --git a/common/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java b/common/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java index 39e1aa28f1..0e1612e713 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java +++ b/common/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.data.lang; +import com.gregtechceu.gtceu.common.data.GTCreativeModeTabs; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.lowdragmc.lowdraglib.utils.LocalizationUtils; import com.tterrag.registrate.providers.RegistrateLangProvider; @@ -12,6 +13,8 @@ import java.util.List; import java.util.stream.Collectors; +import static com.gregtechceu.gtceu.utils.FormattingUtil.toEnglishName; + /** * @author KilaBash * @date 2023/3/19 diff --git a/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicDataPack.java b/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicDataPack.java index 0dead29b47..e12130b446 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicDataPack.java +++ b/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicDataPack.java @@ -15,6 +15,7 @@ import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.MetadataSectionSerializer; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.io.*; diff --git a/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicResourcePack.java b/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicResourcePack.java index 9e108e1350..ec60bf79e8 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicResourcePack.java +++ b/common/src/main/java/com/gregtechceu/gtceu/data/pack/GTDynamicResourcePack.java @@ -7,6 +7,7 @@ import com.lowdragmc.lowdraglib.Platform; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; +import lombok.Getter; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.SharedConstants; import net.minecraft.network.chat.Component; @@ -15,24 +16,23 @@ import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.MetadataSectionSerializer; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; -import net.minecraft.server.packs.resources.IoSupplier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; +import java.util.Collections; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.function.Predicate; import java.util.function.Supplier; +import java.util.stream.Collectors; import static com.gregtechceu.gtceu.data.pack.GTDynamicDataPack.writeJson; @@ -44,6 +44,7 @@ public class GTDynamicResourcePack implements PackResources { @ApiStatus.Internal public static final ConcurrentMap DATA = new ConcurrentHashMap<>(); + @Getter private final String name; static { @@ -136,30 +137,32 @@ public static void writeByteArray(ResourceLocation id, @Nullable String subdir, @Nullable @Override - public IoSupplier getRootResource(String... elements) { - return null; + public InputStream getRootResource(String elements) { + throw new UnsupportedOperationException("Dynamic Resource Pack cannot have root resources"); } @Override - public IoSupplier getResource(PackType type, ResourceLocation location) { + public InputStream getResource(PackType type, ResourceLocation location) { if (type == PackType.CLIENT_RESOURCES) { if (DATA.containsKey(location)) - return () -> new ByteArrayInputStream(DATA.get(location)); + return new ByteArrayInputStream(DATA.get(location)); } - return null; + return new ByteArrayInputStream(new byte[0]); + } + + @Override + public Collection getResources(PackType type, String namespace, String path, Predicate filter) { + if (type == PackType.CLIENT_RESOURCES) + return DATA.keySet().stream().filter(loc -> loc.getPath().startsWith(path.endsWith("/") ? path : path + "/") && filter.test(loc)).collect(Collectors.toList()); + return Collections.emptyList();//LANG.keySet().stream().filter(loc -> loc.getPath().startsWith(path) && filter.test(loc.getPath())).collect(Collectors.toList()); } @Override - public void listResources(PackType packType, String namespace, String path, ResourceOutput resourceOutput) { - if (packType == PackType.CLIENT_RESOURCES) { - if (!path.endsWith("/")) path += "/"; - final String finalPath = path; - DATA.keySet().stream().filter(Objects::nonNull).filter(loc -> loc.getPath().startsWith(finalPath)).forEach((id) -> { - IoSupplier resource = this.getResource(packType, id); - if (resource != null) { - resourceOutput.accept(id, resource); - } - }); + public boolean hasResource(PackType type, ResourceLocation location) { + if (type == PackType.SERVER_DATA) { + return false; + } else { + return DATA.containsKey(location); } } @@ -171,17 +174,12 @@ public Set getNamespaces(PackType type) { @Nullable @Override public T getMetadataSection(MetadataSectionSerializer metaReader) { - if(metaReader == PackMetadataSection.TYPE) { - return (T) new PackMetadataSection(Component.literal("GTCEu dynamic assets"), SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES)); + if(metaReader == PackMetadataSection.SERIALIZER) { + return (T) new PackMetadataSection(Component.literal("GTCEu dynamic assets"), SharedConstants.getCurrentVersion().getPackVersion(com.mojang.bridge.game.PackType.RESOURCE)); } return null; } - @Override - public String packId() { - return this.name; - } - @Override public void close() { //NOOP diff --git a/common/src/main/resources/gtceu-common.mixins.json b/common/src/main/resources/gtceu-common.mixins.json index 774ad030b3..5b8fe89f85 100644 --- a/common/src/main/resources/gtceu-common.mixins.json +++ b/common/src/main/resources/gtceu-common.mixins.json @@ -8,8 +8,8 @@ "BlockModelMixin", "LevelRendererMixin", "ModelBakeryMixin", - "MinecraftMixin", "MultiPlayerGameModeMixin", + "PackRepositoryMixin", "rei.FluidEntryRendererMixin" ], "mixins": [ diff --git a/settings.gradle b/settings.gradle index 419b184649..20faa4d963 100644 --- a/settings.gradle +++ b/settings.gradle @@ -59,7 +59,7 @@ dependencyResolutionManagement { def vineFlowerVersion = "1.+" def macheteVersion = "1.+" def ldLibVersion = "1.0.21.a" - def mixinextrasVersion = "0.2.0" + def mixinextrasVersion = "0.2.0-rc.2" fabric { def parchment = version("parchment", parchmentVersion) @@ -127,9 +127,6 @@ dependencyResolutionManagement { library("mixinextras", "io.github.llamalad7", "mixinextras-fabric").versionRef(mixinextras) library("mixinextras-common", "io.github.llamalad7", "mixinextras-common").versionRef(mixinextras) - def configuration = version("configuration", configurationVersion) - library("configuration", "dev.toma.configuration", "configuration-fabric-1.20.1").versionRef(configuration) - def worldStripper = version("worldStripper", worldStripperFabricFile) library("worldStripper", "curse.maven", "worldStripper-250603").versionRef(worldStripper)