-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove most of the model injection code (#165)
* new raw ore textures i got made, feel free to reorder/remove as you please * fix-a-mixin (removed most of the ModelBakeryMixin code, and moved it to the respective renderer classes as suppliers) also fixed create fluid tank rendering on forge * revert to the old raw ore block for dull, this one is too dark --------- Co-authored-by: KilaBash <[email protected]>
- Loading branch information
Showing
26 changed files
with
99 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 14 additions & 90 deletions
104
common/src/main/java/com/gregtechceu/gtceu/core/mixins/ModelBakeryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ResourceLocation, UnbakedModel> unbakedCache; | ||
|
||
@Shadow @Final private Map<ResourceLocation, UnbakedModel> topLevelModels; | ||
|
||
@Shadow @Final private ResourceManager resourceManager; | ||
|
||
@Shadow @Final private static Set<net.minecraft.client.resources.model.Material> UNREFERENCED_TEXTURES; | ||
|
||
/** | ||
* register additional models as what forge does | ||
*/ | ||
@Redirect(method = "<init>", 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 = "<init>", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Sets;newLinkedHashSet()Ljava/util/LinkedHashSet;", ordinal = 0)) | ||
private LinkedHashSet<Pair<String, String>> 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<? extends MaterialBlock> 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(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/gtceu/models/item/material_sets/diamond/raw_ore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/material_sets/diamond/raw_ore" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/gtceu/models/item/material_sets/fine/raw_ore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/material_sets/fine/raw_ore" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/gtceu/models/item/material_sets/lignite/raw_ore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/material_sets/lignite/raw_ore" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/gtceu/models/item/material_sets/shiny/raw_ore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/material_sets/shiny/raw_ore" | ||
} | ||
} |
Binary file modified
BIN
-936 Bytes
(22%)
...main/resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.17 KB
.../resources/assets/gtceu/textures/block/material_sets/dull/raw_ore_block_old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.82 KB
...n/resources/assets/gtceu/textures/block/material_sets/lignite/raw_ore_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.84 KB
...ain/resources/assets/gtceu/textures/block/material_sets/rough/raw_ore_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.17 KB
...ain/resources/assets/gtceu/textures/block/material_sets/shiny/raw_ore_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.7 KB
...src/main/resources/assets/gtceu/textures/item/material_sets/diamond/raw_ore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.58 KB
(400%)
...on/src/main/resources/assets/gtceu/textures/item/material_sets/dull/raw_ore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.17 KB
...on/src/main/resources/assets/gtceu/textures/item/material_sets/fine/raw_ore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.77 KB
...n/src/main/resources/assets/gtceu/textures/item/material_sets/shiny/raw_ore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.