diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java b/common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java index 5e850e8e58..5a150652f0 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java @@ -1084,17 +1084,6 @@ private void verifyInfo(MaterialProperties p, boolean averageRGB) { } } - // Verify FluidTexture - if (p.hasProperty(PropertyKey.FLUID)) { - var fluid = p.getProperty(PropertyKey.FLUID); - if (fluid.getStillTexture() == null) { - fluid.setStillTexture(MaterialIconType.fluid.getBlockTexturePath(iconSet, true)); - } - if (fluid.getFlowTexture() == null) { - fluid.setFlowTexture(fluid.getStillTexture()); - } - } - } } } diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/item/MaterialPipeBlockItem.java b/common/src/main/java/com/gregtechceu/gtceu/api/item/MaterialPipeBlockItem.java index e8028070e2..ee5f964aae 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/item/MaterialPipeBlockItem.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/item/MaterialPipeBlockItem.java @@ -7,6 +7,7 @@ import net.fabricmc.api.Environment; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.client.color.item.ItemColor; +import net.minecraft.network.chat.Component; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; @@ -49,4 +50,13 @@ public IRenderer getRenderer(ItemStack stack) { return getBlock().getRenderer(getBlock().defaultBlockState()); } + @Override + public Component getDescription() { + return this.getBlock().getName(); + } + + @Override + public Component getName(ItemStack stack) { + return getDescription(); + } } 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 de4acd2616..9b670b735c 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 @@ -28,11 +28,7 @@ public static MaterialBlockRenderer getOrCreate(MaterialIconType type, MaterialI } protected MaterialBlockRenderer(MaterialIconType type, MaterialIconSet iconSet) { - super(GTCEu.id("block/tinted_cube_all"), Map.of("all", type.getBlockTexturePath(iconSet, true))); - } - - public void setBlockTexture(ResourceLocation newBlockTexture) { - setTextureOverride(Map.of("all", newBlockTexture)); + super(GTCEu.id("block/tinted_cube_all"), () -> Map.of("all", type.getBlockTexturePath(iconSet, true))); } @Override 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 8726da261a..b744787149 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 @@ -39,22 +39,19 @@ */ public class OreBlockRenderer extends BlockStateRenderer { private final Supplier stone; + private Supplier overlaySupplier; private ResourceLocation overlay; private final boolean emissive; - public OreBlockRenderer(Supplier stone, ResourceLocation overlay, boolean emissive) { + public OreBlockRenderer(Supplier stone, Supplier overlaySupplier, boolean emissive) { this.stone = stone; - this.overlay = overlay; + this.overlaySupplier = overlaySupplier; this.emissive = emissive; if (LDLib.isClient()) { registerEvent(); } } - public void setOverlayTexture(ResourceLocation newOverlay) { - this.overlay = newOverlay; - } - @Override public BlockInfo getBlockInfo() { return new BlockInfo(stone.get()); @@ -95,6 +92,9 @@ public List renderModel(BlockAndTintGetter level, BlockPos pos, Block public void onPrepareTextureAtlas(ResourceLocation atlasName, Consumer register) { super.onPrepareTextureAtlas(atlasName, register); if (atlasName.equals(TextureAtlas.LOCATION_BLOCKS)) { + if (overlaySupplier != null) { + overlay = overlaySupplier.get(); + } register.accept(overlay); } } diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/TextureOverrideRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/TextureOverrideRenderer.java index fe613a49a8..ea16cad42b 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/TextureOverrideRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/TextureOverrideRenderer.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.Map; import java.util.function.Consumer; +import java.util.function.Supplier; /** * @author KilaBash @@ -30,6 +31,8 @@ public class TextureOverrideRenderer extends CTMModelRenderer { @Nonnull protected Map override; + @Nullable + protected Supplier> overrideSupplier; public TextureOverrideRenderer(ResourceLocation model, @Nonnull Map override) { super(model); @@ -39,6 +42,15 @@ public TextureOverrideRenderer(ResourceLocation model, @Nonnull Map> overrideSupplier) { + super(model); + this.override = Collections.emptyMap(); + this.overrideSupplier = overrideSupplier; + if (LDLib.isClient()) { + registerEvent(); + } + } + public TextureOverrideRenderer(ResourceLocation model) { super(model); this.override = Collections.emptyMap(); @@ -83,6 +95,7 @@ public BakedModel getRotatedModel(Direction frontFacing) { public void onPrepareTextureAtlas(ResourceLocation atlasName, Consumer register) { super.onPrepareTextureAtlas(atlasName, register); if (atlasName.equals(TextureAtlas.LOCATION_BLOCKS)) { // prepare for override. + if (overrideSupplier != null) override = overrideSupplier.get(); for (Object value : override.values()) { register.accept(new ResourceLocation(value.toString())); } 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 288fd79bec..c12b5381a8 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 @@ -2,12 +2,10 @@ import com.google.common.collect.Table; import com.google.common.collect.Tables; -import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconSet; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconType; import com.lowdragmc.lowdraglib.client.model.ModelFactory; import com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer; -import lombok.Setter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.block.model.BlockModel; @@ -16,9 +14,9 @@ import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; -import java.io.FileNotFoundException; import java.util.HashMap; import java.util.function.Consumer; +import java.util.function.Supplier; /** * @author KilaBash @@ -28,16 +26,14 @@ public class TagPrefixItemRenderer extends IModelRenderer { private static final Table MODELS = Tables.newCustomTable(new HashMap<>(), HashMap::new); + @Nullable private ResourceLocation modelLocation; + @Nullable + private Supplier modelLocationSupplier; private TagPrefixItemRenderer(MaterialIconType type, MaterialIconSet iconSet) { - super(type.getItemModelPath(iconSet, true)); - this.modelLocation = type.getItemModelPath(iconSet, true); - } - - public void setModelLocation(ResourceLocation newModelLocation) { - this.modelLocation = newModelLocation; - this.itemModel = null; + super(null); + this.modelLocationSupplier = () -> type.getItemModelPath(iconSet, true); } public static TagPrefixItemRenderer getOrCreate(MaterialIconType type, MaterialIconSet iconSet) { @@ -85,6 +81,9 @@ public BakedModel getRotatedModel(Direction frontFacing) { @Override @Environment(EnvType.CLIENT) public void onAdditionalModel(Consumer registry) { - // no-op, handled in ModelBakeryMixin.java + if (modelLocationSupplier != null) { + modelLocation = modelLocationSupplier.get(); + } + registry.accept(modelLocation); } } 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 2b1c6e4749..40fc4f2fa8 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 @@ -160,7 +160,7 @@ public static void generateMaterialBlocks() { var entry = REGISTRATE.block("%s%s_ore".formatted(oreTag != TagPrefix.ore ? FormattingUtil.toLowerCaseUnder(oreTag.name) + "_" : "", material.getName()), oreType.material(), properties -> new MaterialBlock(properties, oreTag, material, Platform.isClient() ? new OreBlockRenderer(oreType.stoneType(), - Objects.requireNonNull(oreTag.materialIconType()).getBlockTexturePath(material.getMaterialIconSet(), true), + () -> Objects.requireNonNull(oreTag.materialIconType()).getBlockTexturePath(material.getMaterialIconSet(), true), oreProperty.isEmissive()) : null)) .initialProperties(() -> oreType.stoneType().get().getBlock()) .properties(properties -> { diff --git a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/ModelBakeryMixin.java b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/ModelBakeryMixin.java index ceb9c4f549..1a90610b9a 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/ModelBakeryMixin.java +++ b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/ModelBakeryMixin.java @@ -1,117 +1,41 @@ package com.gregtechceu.gtceu.core.mixins; -import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.api.block.MaterialBlock; +import com.google.common.collect.Sets; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconSet; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconType; import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidProperty; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; -import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.registry.GTRegistries; -import com.gregtechceu.gtceu.client.renderer.block.MaterialBlockRenderer; -import com.gregtechceu.gtceu.client.renderer.block.OreBlockRenderer; -import com.gregtechceu.gtceu.client.renderer.item.TagPrefixItemRenderer; -import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.core.MixinHelpers; -import com.tterrag.registrate.util.entry.BlockEntry; -import net.minecraft.client.renderer.texture.TextureAtlas; +import com.mojang.datafixers.util.Pair; import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.util.profiling.ProfilerFiller; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import java.util.Map; -import java.util.Set; +import java.util.LinkedHashSet; @Mixin(value = ModelBakery.class, priority = 999) public abstract class ModelBakeryMixin { - @Shadow - public abstract UnbakedModel getModel(ResourceLocation modelLocation); - - @Shadow @Final - private Map unbakedCache; - - @Shadow @Final private Map topLevelModels; - - @Shadow @Final private ResourceManager resourceManager; - - @Shadow @Final private static Set UNREFERENCED_TEXTURES; - - /** - * register additional models as what forge does - */ - @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", ordinal = 4)) - private void gtceu$injectModelBakery(ProfilerFiller profiler, String name) { // Have to use a redirect here cuz it's to constructor and mixin doesn't like that much + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Sets;newLinkedHashSet()Ljava/util/LinkedHashSet;", ordinal = 0)) + private LinkedHashSet> gtceu$injectModelBakery() { // Have to use a redirect here cuz it's to constructor and mixin doesn't like that much for (Material material : GTRegistries.MATERIALS.values()) { MaterialIconSet iconSet = material.getMaterialIconSet(); - - { - if (material.hasProperty(PropertyKey.ORE) && !material.hasProperty(PropertyKey.GEM)) { - MaterialBlockRenderer.getOrCreate(MaterialIconType.rawOreBlock, iconSet).setBlockTexture(gtceu$generateBlockTexture(iconSet, MaterialIconType.rawOreBlock)); - } - if (material.hasProperty(PropertyKey.INGOT) || material.hasProperty(PropertyKey.GEM) || material.hasFlag(MaterialFlags.FORCE_GENERATE_BLOCK)) { - MaterialBlockRenderer.getOrCreate(MaterialIconType.block, iconSet).setBlockTexture(gtceu$generateBlockTexture(iconSet, MaterialIconType.block)); - } - if (material.hasProperty(PropertyKey.DUST) && material.hasFlag(MaterialFlags.GENERATE_FRAME)) { - MaterialBlockRenderer.getOrCreate(MaterialIconType.frameGt, iconSet).setBlockTexture(gtceu$generateBlockTexture(iconSet, MaterialIconType.frameGt)); + if (material.hasProperty(PropertyKey.FLUID)) { + FluidProperty fluid = material.getProperty(PropertyKey.FLUID); + if (fluid.getStillTexture() == null) { + ResourceLocation foundTexture = MaterialIconType.fluid.getBlockTexturePath(iconSet, false); + fluid.setStillTexture(foundTexture); } - if (material.hasProperty(PropertyKey.FLUID)) { - FluidProperty prop = material.getProperty(PropertyKey.FLUID); - prop.setStillTexture(gtceu$generateBlockTexture(iconSet, MaterialIconType.fluid)); - prop.setFlowTexture(prop.getStillTexture()); - MaterialBlockRenderer.getOrCreate(MaterialIconType.fluid, iconSet).setBlockTexture(prop.getStillTexture()); - MixinHelpers.addFluidTexture(material, prop); - } - } - - prefixLoop: - for (TagPrefix tagPrefix : TagPrefix.values()) { - MaterialIconType type = tagPrefix.materialIconType(); - - if (material.hasProperty(PropertyKey.ORE)) { - BlockEntry blockEntry = GTBlocks.MATERIAL_BLOCKS.get(tagPrefix, material); - if (blockEntry != null && blockEntry.isPresent()) { - MaterialBlock block = blockEntry.get(); - if (block.getRenderer(block.defaultBlockState()) instanceof OreBlockRenderer oreRenderer) { - oreRenderer.setOverlayTexture(gtceu$generateBlockTexture(iconSet, type)); - } - continue prefixLoop; - } - } - - if (tagPrefix.doGenerateItem(material)) { - ResourceLocation model = GTCEu.id(String.format("item/material_sets/%s/%s", iconSet.name, type.name())); - ResourceLocation foundModel = type.getItemModelPath(iconSet, false); - - UnbakedModel unbakedmodel = this.getModel(foundModel); - this.unbakedCache.put(model, unbakedmodel); - this.topLevelModels.put(model, unbakedmodel); - TagPrefixItemRenderer.getOrCreate(type, iconSet).setModelLocation(model); + if (fluid.getFlowTexture() == null) { + fluid.setFlowTexture(fluid.getStillTexture()); } + MixinHelpers.addFluidTexture(material, fluid); } } - profiler.popPush(name); - } - - @Unique - private ResourceLocation gtceu$generateBlockTexture(MaterialIconSet iconSet, MaterialIconType type) { - ResourceLocation texture = GTCEu.id(String.format("block/material_sets/%s/%s", iconSet.name, type.name())); - ResourceLocation foundTexture = type.getBlockTexturePath(iconSet, false); - - ResourceLocation path = GTCEu.id(String.format("textures/block/material_sets/%s/%s.png", iconSet.name, type.name())); - foundTexture = this.resourceManager.getResource(path).isPresent() ? texture : foundTexture; - - UNREFERENCED_TEXTURES.add(new net.minecraft.client.resources.model.Material(TextureAtlas.LOCATION_BLOCKS, foundTexture)); - return foundTexture; + return Sets.newLinkedHashSet(); } } diff --git a/common/src/main/resources/assets/gtceu/models/item/material_sets/diamond/raw_ore.json b/common/src/main/resources/assets/gtceu/models/item/material_sets/diamond/raw_ore.json new file mode 100644 index 0000000000..0caea56adf --- /dev/null +++ b/common/src/main/resources/assets/gtceu/models/item/material_sets/diamond/raw_ore.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gtceu:item/material_sets/diamond/raw_ore" + } +} diff --git a/common/src/main/resources/assets/gtceu/models/item/material_sets/fine/raw_ore.json b/common/src/main/resources/assets/gtceu/models/item/material_sets/fine/raw_ore.json new file mode 100644 index 0000000000..7b7a3d6534 --- /dev/null +++ b/common/src/main/resources/assets/gtceu/models/item/material_sets/fine/raw_ore.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gtceu:item/material_sets/fine/raw_ore" + } +} diff --git a/common/src/main/resources/assets/gtceu/models/item/material_sets/lignite/raw_ore.json b/common/src/main/resources/assets/gtceu/models/item/material_sets/lignite/raw_ore.json new file mode 100644 index 0000000000..2a4468ee66 --- /dev/null +++ b/common/src/main/resources/assets/gtceu/models/item/material_sets/lignite/raw_ore.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gtceu:item/material_sets/lignite/raw_ore" + } +} diff --git a/common/src/main/resources/assets/gtceu/models/item/material_sets/shiny/raw_ore.json b/common/src/main/resources/assets/gtceu/models/item/material_sets/shiny/raw_ore.json new file mode 100644 index 0000000000..8d839b779e --- /dev/null +++ b/common/src/main/resources/assets/gtceu/models/item/material_sets/shiny/raw_ore.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gtceu:item/material_sets/shiny/raw_ore" + } +} diff --git a/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block.png b/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block.png index 532dff9408..033f74f879 100644 Binary files a/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block.png and b/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block_old.png b/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block_old.png new file mode 100644 index 0000000000..e92c8d2373 Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block_old.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/block/material_sets/lignite/raw_ore_block.png b/common/src/main/resources/assets/gtceu/textures/block/material_sets/lignite/raw_ore_block.png new file mode 100644 index 0000000000..5a427e871a Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/block/material_sets/lignite/raw_ore_block.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/block/material_sets/rough/raw_ore_block.png b/common/src/main/resources/assets/gtceu/textures/block/material_sets/rough/raw_ore_block.png new file mode 100644 index 0000000000..5bf2c43d13 Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/block/material_sets/rough/raw_ore_block.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/block/material_sets/shiny/raw_ore_block.png b/common/src/main/resources/assets/gtceu/textures/block/material_sets/shiny/raw_ore_block.png new file mode 100644 index 0000000000..ac69fc39a1 Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/block/material_sets/shiny/raw_ore_block.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/item/material_sets/diamond/raw_ore.png b/common/src/main/resources/assets/gtceu/textures/item/material_sets/diamond/raw_ore.png new file mode 100644 index 0000000000..77c85dd669 Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/item/material_sets/diamond/raw_ore.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/item/material_sets/dull/raw_ore.png b/common/src/main/resources/assets/gtceu/textures/item/material_sets/dull/raw_ore.png index a8ae434456..b9c01319ee 100644 Binary files a/common/src/main/resources/assets/gtceu/textures/item/material_sets/dull/raw_ore.png and b/common/src/main/resources/assets/gtceu/textures/item/material_sets/dull/raw_ore.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/item/material_sets/fine/raw_ore.png b/common/src/main/resources/assets/gtceu/textures/item/material_sets/fine/raw_ore.png new file mode 100644 index 0000000000..a8ae434456 Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/item/material_sets/fine/raw_ore.png differ diff --git a/common/src/main/resources/assets/gtceu/textures/item/material_sets/shiny/raw_ore.png b/common/src/main/resources/assets/gtceu/textures/item/material_sets/shiny/raw_ore.png new file mode 100644 index 0000000000..36c28d47fd Binary files /dev/null and b/common/src/main/resources/assets/gtceu/textures/item/material_sets/shiny/raw_ore.png differ diff --git a/fabric/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/fabric/GTFluidBuilder.java b/fabric/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/fabric/GTFluidBuilder.java index 18d48080cf..6d985ac1fd 100644 --- a/fabric/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/fabric/GTFluidBuilder.java +++ b/fabric/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/fabric/GTFluidBuilder.java @@ -294,8 +294,8 @@ protected T createEntry() { protected void registerDefaultRenderer(T flowing) { FluidRenderHandlerRegistry.INSTANCE.register(getSource(), flowing, new SimpleFluidRenderHandler(stillTexture, flowingTexture, color)); ClientSpriteRegistryCallback.event(InventoryMenu.BLOCK_ATLAS).register((atlas, registry) -> { - registry.register(stillTexture); - registry.register(flowingTexture); + if (stillTexture != null) registry.register(stillTexture); + if (flowingTexture != null) registry.register(flowingTexture); }); } diff --git a/fabric/src/main/java/com/gregtechceu/gtceu/core/fabric/MixinHelpersImpl.java b/fabric/src/main/java/com/gregtechceu/gtceu/core/fabric/MixinHelpersImpl.java index bb05f2855f..b371d4020d 100644 --- a/fabric/src/main/java/com/gregtechceu/gtceu/core/fabric/MixinHelpersImpl.java +++ b/fabric/src/main/java/com/gregtechceu/gtceu/core/fabric/MixinHelpersImpl.java @@ -5,6 +5,8 @@ import com.gregtechceu.gtceu.common.data.GTFluids; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler; +import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; +import net.minecraft.world.inventory.InventoryMenu; public class MixinHelpersImpl { @@ -13,6 +15,10 @@ public static void addFluidTexture(Material material, FluidProperty prop) { var fluids = GTFluids.MATERIAL_FLUID_FLOWING.get(prop); if (fluids != null) { FluidRenderHandlerRegistry.INSTANCE.register(fluids.get().getFirst(), fluids.get().getSecond(), new SimpleFluidRenderHandler(prop.getStillTexture(), prop.getFlowTexture(), material.getMaterialRGB())); + ClientSpriteRegistryCallback.event(InventoryMenu.BLOCK_ATLAS).register((atlas, registry) -> { + registry.register(prop.getStillTexture()); + registry.register(prop.getFlowTexture()); + }); } } } diff --git a/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTClientFluidTypeExtensions.java b/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTClientFluidTypeExtensions.java index 9d9480346c..77687435e5 100644 --- a/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTClientFluidTypeExtensions.java +++ b/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTClientFluidTypeExtensions.java @@ -5,17 +5,12 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; -import java.util.HashMap; -import java.util.Map; - public class GTClientFluidTypeExtensions implements IClientFluidTypeExtensions { - public static final Map FLUID_TYPES = new HashMap<>(); - public GTClientFluidTypeExtensions(ResourceLocation still, ResourceLocation stillTexture, ResourceLocation flowingTexture, int tintColor) { + public GTClientFluidTypeExtensions(ResourceLocation stillTexture, ResourceLocation flowingTexture, int tintColor) { this.stillTexture = stillTexture; this.flowingTexture = flowingTexture; this.tintColor = tintColor; - FLUID_TYPES.put(still, this); } @Getter @Setter diff --git a/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTFluidBuilder.java b/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTFluidBuilder.java index 2130e32127..16479081e7 100644 --- a/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTFluidBuilder.java +++ b/forge/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/forge/GTFluidBuilder.java @@ -67,7 +67,7 @@ public class GTFluidBuilder extends AbstractBuil @FunctionalInterface public interface FluidTypeFactory { - FluidType create(String langKey, Material material, ResourceLocation stillId, FluidType.Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture, int color); + FluidType create(String langKey, Material material, FluidType.Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture, int color); } private final String sourceName, bucketName; @@ -104,7 +104,7 @@ public GTFluidBuilder(AbstractRegistrate owner, P parent, Material material, this.stillTexture = stillTexture; this.flowingTexture = flowingTexture; this.fluidFactory = fluidFactory; - this.fluidType = NonNullSupplier.lazy(() -> typeFactory.create(langKey, material, new ResourceLocation(owner.getModid(), name), makeTypeProperties(), this.stillTexture, this.flowingTexture, this.color)); + this.fluidType = NonNullSupplier.lazy(() -> typeFactory.create(langKey, material, makeTypeProperties(), this.stillTexture, this.flowingTexture, this.color)); this.registerType = true; defaultBucket(); @@ -338,11 +338,11 @@ protected RegistryEntry createEntryWrapper(RegistryObject delegate) { return new FluidEntry<>(getOwner(), delegate); } - public static FluidType defaultFluidType(String langKey, Material material, ResourceLocation still, FluidType.Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture, int color) { + public static FluidType defaultFluidType(String langKey, Material material, FluidType.Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture, int color) { return new FluidType(properties) { @Override public void initializeClient(Consumer consumer) { - consumer.accept(new GTClientFluidTypeExtensions(still, stillTexture, flowingTexture, color)); + consumer.accept(new GTClientFluidTypeExtensions(stillTexture, flowingTexture, color)); } @Override diff --git a/forge/src/main/java/com/gregtechceu/gtceu/core/forge/MixinHelpersImpl.java b/forge/src/main/java/com/gregtechceu/gtceu/core/forge/MixinHelpersImpl.java index 183f3dd1bf..b3776b4eb8 100644 --- a/forge/src/main/java/com/gregtechceu/gtceu/core/forge/MixinHelpersImpl.java +++ b/forge/src/main/java/com/gregtechceu/gtceu/core/forge/MixinHelpersImpl.java @@ -3,17 +3,17 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidProperty; import com.gregtechceu.gtceu.api.registry.registrate.forge.GTClientFluidTypeExtensions; -import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; public class MixinHelpersImpl { public static void addFluidTexture(Material material, FluidProperty prop) { - if (prop == null || !prop.hasFluidSupplier()) return; - GTClientFluidTypeExtensions extensions = GTClientFluidTypeExtensions.FLUID_TYPES.get(ForgeRegistries.FLUIDS.getKey(prop.getFluid())); - if (extensions != null) { - extensions.setFlowingTexture(prop.getFlowTexture()); - extensions.setStillTexture(prop.getStillTexture()); - extensions.setTintColor(material.getMaterialRGB()); + if (prop == null || !prop.hasFluidSupplier() || prop.getFluid() == null) return; + IClientFluidTypeExtensions extensions = IClientFluidTypeExtensions.of(prop.getFluid()); + if (extensions instanceof GTClientFluidTypeExtensions gtExtensions) { + gtExtensions.setFlowingTexture(prop.getFlowTexture()); + gtExtensions.setStillTexture(prop.getStillTexture()); + gtExtensions.setTintColor(material.getMaterialARGB()); } } }