-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
2 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
43 changes: 43 additions & 0 deletions
43
src/main/java/dev/jaegerwald/voidlings/item/Renderers.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dev.jaegerwald.voidlings.item; | ||
|
||
import dev.jaegerwald.voidlings.Voidlings; | ||
import net.minecraft.client.render.model.json.ModelTransformationMode; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.BiPredicate; | ||
import java.util.function.Consumer; | ||
|
||
public class Renderers { | ||
public static Map<Item, Map<BiPredicate<ItemStack, ModelTransformationMode>, ModelIdentifier>> RENDERERS = new HashMap<>(); | ||
public static final List<ModelIdentifier> FORCELOAD = new ArrayList<>(); | ||
|
||
public static void register() { | ||
RENDERERS.put(ModItems.SURGEONS_BLADE, Map.of((stack, modelTransformationMode) -> { | ||
return modelTransformationMode != ModelTransformationMode.GUI; // The condition to apply the model | ||
}, forceLoad("fried_lamina"))); | ||
} | ||
|
||
public static void apply(ItemStack stack, ModelTransformationMode mode, Consumer<ModelIdentifier> consumer) { | ||
Map<BiPredicate<ItemStack, ModelTransformationMode>, ModelIdentifier> renderer = Renderers.RENDERERS.get(stack.getItem()); | ||
if (renderer != null) renderer.forEach(((predicate, modelIdentifier) -> { | ||
if (predicate.test(stack, mode)) consumer.accept(modelIdentifier); | ||
})); | ||
} | ||
|
||
private static ModelIdentifier forceLoad(String path) { | ||
ModelIdentifier modelID = modelID(path); | ||
FORCELOAD.add(modelID); | ||
return modelID; | ||
} | ||
|
||
private static ModelIdentifier modelID(String path) { | ||
return ModelIdentifier.ofInventoryVariant(Identifier.of(Voidlings.MOD_ID, path)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/dev/jaegerwald/voidlings/mixin/ItemRendererMixin.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.jaegerwald.voidlings.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
import dev.jaegerwald.voidlings.item.Renderers; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.item.ItemModels; | ||
import net.minecraft.client.render.item.ItemRenderer; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.render.model.json.ModelTransformationMode; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.item.ItemStack; | ||
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.CallbackInfo; | ||
|
||
@Mixin(ItemRenderer.class) | ||
public class ItemRendererMixin { | ||
@Shadow | ||
@Final | ||
private ItemModels models; | ||
|
||
@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/BakedModel;getTransformation()Lnet/minecraft/client/render/model/json/ModelTransformation;")) | ||
private void interruptModelRendering(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci, @Local(argsOnly = true) LocalRef<BakedModel> modelRef) { | ||
Renderers.apply(stack, renderMode, (modelIdentifier) -> modelRef.set(models.getModelManager().getModel(modelIdentifier))); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/jaegerwald/voidlings/mixin/ModelLoaderMixin.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.jaegerwald.voidlings.mixin; | ||
|
||
import dev.jaegerwald.voidlings.item.Renderers; | ||
import net.minecraft.client.color.block.BlockColors; | ||
import net.minecraft.client.render.model.BlockStatesLoader; | ||
import net.minecraft.client.render.model.ModelLoader; | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.profiler.Profiler; | ||
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.CallbackInfo; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Mixin(ModelLoader.class) | ||
public abstract class ModelLoaderMixin { | ||
@Shadow protected abstract void loadItemModel(ModelIdentifier id); | ||
|
||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;loadItemModel(Lnet/minecraft/client/util/ModelIdentifier;)V", ordinal = 0)) | ||
private void loadForcedModels(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<BlockStatesLoader.SourceTrackedData>> blockStates, CallbackInfo ci) { | ||
Renderers.FORCELOAD.forEach(this::loadItemModel); | ||
} | ||
} |
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