generated from FabricMC/fabric-example-mod
-
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.
fix loot, render book as model in hand now
- Loading branch information
Showing
14 changed files
with
214 additions
and
19 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
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/reoseah/magisterium/mixin/client/BuiltinItemModelRendererMixin.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,49 @@ | ||
package io.github.reoseah.magisterium.mixin.client; | ||
|
||
import io.github.reoseah.magisterium.item.SpellBookItem; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.entity.model.BookModel; | ||
import net.minecraft.client.render.entity.model.EntityModelLayers; | ||
import net.minecraft.client.render.item.BuiltinModelItemRenderer; | ||
import net.minecraft.client.render.item.ItemRenderer; | ||
import net.minecraft.client.render.model.json.ModelTransformationMode; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(BuiltinModelItemRenderer.class) | ||
public class BuiltinItemModelRendererMixin { | ||
@Unique | ||
private static final Identifier TEXTURE = Identifier.of("magisterium", "textures/entity/spell_book.png"); | ||
|
||
@Unique | ||
private BookModel bookModel; | ||
|
||
@Inject(at = @At("HEAD"), method = "reload") | ||
public void reload(ResourceManager manager, CallbackInfo ci) { | ||
this.bookModel = new BookModel(MinecraftClient.getInstance().getEntityModelLoader().getModelPart(EntityModelLayers.BOOK)); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "render", cancellable = true) | ||
public void render(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) { | ||
Item item = stack.getItem(); | ||
if (item == SpellBookItem.INSTANCE) { | ||
matrices.push(); | ||
matrices.scale(1, -1, -1); | ||
VertexConsumer vertexConsumer = ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, this.bookModel.getLayer(TEXTURE), false, false); | ||
this.bookModel.setPageAngles(0, 0.1F, 0.9F, 1.2F); | ||
this.bookModel.render(matrices, vertexConsumer, light, overlay, 0xFFFFFF); | ||
matrices.pop(); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/io/github/reoseah/magisterium/mixin/client/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,85 @@ | ||
package io.github.reoseah.magisterium.mixin.client; | ||
|
||
import io.github.reoseah.magisterium.item.SpellBookItem; | ||
import net.minecraft.client.render.*; | ||
import net.minecraft.client.render.item.BuiltinModelItemRenderer; | ||
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.ModelIdentifier; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
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.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Objects; | ||
|
||
@Mixin(ItemRenderer.class) | ||
public abstract class ItemRendererMixin { | ||
@Unique | ||
private static final ModelIdentifier SPELL_BOOK = ModelIdentifier.ofInventoryVariant(Identifier.of("magisterium", "spell_book")); | ||
@Unique | ||
private static final Identifier SPELL_BOOK_IN_HAND = Identifier.of("magisterium", "item/spell_book_in_hand"); | ||
|
||
@Shadow | ||
private @Final ItemModels models; | ||
@Shadow | ||
private @Final BuiltinModelItemRenderer builtinModelItemRenderer; | ||
|
||
@Shadow | ||
protected abstract void renderBakedItemModel(BakedModel model, ItemStack stack, int light, int overlay, MatrixStack matrices, VertexConsumer vertices); | ||
|
||
@Inject(at = @At("HEAD"), method = "getModel", cancellable = true) | ||
public void setHemonomiconModel(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> ci) { | ||
Item item = stack.getItem(); | ||
if (item == SpellBookItem.INSTANCE) { | ||
BakedModel model = this.models.getModelManager().getModel(SPELL_BOOK_IN_HAND); | ||
ClientWorld clientWorld = world instanceof ClientWorld ? (ClientWorld) world : null; | ||
model = model.getOverrides().apply(model, stack, clientWorld, entity, seed); | ||
ci.setReturnValue(model == null ? this.models.getModelManager().getMissingModel() : model); | ||
} | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "renderItem", cancellable = true) | ||
public void renderHemonomicon(ItemStack stack, ModelTransformationMode mode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { | ||
if (!stack.isEmpty() && stack.getItem() == SpellBookItem.INSTANCE) { | ||
matrices.push(); | ||
boolean gui = mode == ModelTransformationMode.GUI; | ||
boolean notInHand = gui || mode == ModelTransformationMode.GROUND || mode == ModelTransformationMode.FIXED; | ||
if (notInHand) { | ||
model = this.models.getModelManager().getModel(SPELL_BOOK); | ||
} | ||
model.getTransformation().getTransformation(mode).apply(leftHanded, matrices); | ||
matrices.translate(-0.5D, -0.5D, -0.5D); | ||
if (model.isBuiltin() || !notInHand) { | ||
this.builtinModelItemRenderer.render(stack, mode, matrices, vertexConsumers, light, overlay); | ||
} else { | ||
RenderLayer itemLayer = RenderLayers.getItemLayer(stack, true); | ||
RenderLayer layer; | ||
if (gui && Objects.equals(itemLayer, TexturedRenderLayers.getEntityTranslucentCull())) { | ||
layer = TexturedRenderLayers.getEntityTranslucentCull(); | ||
} else { | ||
layer = itemLayer; | ||
} | ||
|
||
VertexConsumer vertexConsumer = ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, layer, true, stack.hasGlint()); | ||
this.renderBakedItemModel(model, stack, light, overlay, matrices, vertexConsumer); | ||
} | ||
matrices.pop(); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
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
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
44 changes: 44 additions & 0 deletions
44
src/main/resources/assets/magisterium/models/item/spell_book_in_hand.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,44 @@ | ||
{ | ||
"parent": "builtin/entity", | ||
"gui_light": "front", | ||
"textures": { | ||
"particle": "magisterium:item/spell_book" | ||
}, | ||
"display": { | ||
"thirdperson_righthand": { | ||
"rotation": [0, -120, 0], | ||
"translation": [-12, 12, 3], | ||
"scale": [1, 1, 1] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [0, 60, 0], | ||
"translation": [3, 12, 12], | ||
"scale": [1, 1, 1] | ||
}, | ||
"firstperson_righthand": { | ||
"rotation": [0, -90, 25], | ||
"translation": [-3, 12, 1], | ||
"scale": [1, 1, 1] | ||
}, | ||
"firstperson_lefthand": { | ||
"rotation": [0, 90, -25], | ||
"translation": [13, 12, 1], | ||
"scale": [1, 1, 1] | ||
}, | ||
"gui": { | ||
"rotation": [15, -25, -5], | ||
"translation": [2, 3, 0], | ||
"scale": [0.65, 0.65, 0.65] | ||
}, | ||
"fixed": { | ||
"rotation": [0, 180, 0], | ||
"translation": [-2, 4, -5], | ||
"scale": [0.5, 0.5, 0.5] | ||
}, | ||
"ground": { | ||
"rotation": [0, 0, 0], | ||
"translation": [4, 4, 2], | ||
"scale": [0.25, 0.25, 0.25] | ||
} | ||
} | ||
} |
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