Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Remove :concern: trinkets mixins
Browse files Browse the repository at this point in the history
- Equipping multiple of the same Trinkets is now allowed
- Fully custom FeatureRenderer
  • Loading branch information
florensie committed Apr 8, 2021
1 parent 763adb4 commit 199f2a8
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 157 deletions.
43 changes: 43 additions & 0 deletions src/main/java/artifacts/client/render/ArtifactFeatureRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package artifacts.client.render;

import artifacts.item.trinket.TrinketArtifactItem;
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketSlots;
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;

import java.util.List;

/**
* Custom trinkets feature renderer, {@link dev.emi.trinkets.TrinketFeatureRenderer} is missing parameters
*/
public class ArtifactFeatureRenderer extends FeatureRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {
private final FeatureRendererContext<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> context;

public ArtifactFeatureRenderer(
FeatureRendererContext<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> context) {
super(context);
this.context = context;
}

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
TrinketComponent comp = TrinketsApi.getTrinketComponent(player);
List<String> names = TrinketSlots.getAllSlotNames();

for (int i = 0; i < comp.getInventory().size(); i++) {
matrices.push();
ItemStack stack = comp.getInventory().getStack(i);
if (stack.getItem() instanceof TrinketArtifactItem) {
((TrinketArtifactItem) stack.getItem()).render(names.get(i), matrices, vertexConsumers, light, context.getModel(), player, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch);
}
matrices.pop();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package artifacts.mixin.mixins.client.render;

import artifacts.Artifacts;
import artifacts.client.render.ArtifactFeatureRenderer;
import artifacts.item.trinket.glove.GloveItem;
import dev.emi.trinkets.api.SlotGroups;
import dev.emi.trinkets.api.Slots;
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -20,7 +24,16 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerEntityRenderer.class)
public class PlayerEntityRendererMixin {
public abstract class PlayerEntityRendererMixin extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {

public PlayerEntityRendererMixin(EntityRenderDispatcher dispatcher, PlayerEntityModel<AbstractClientPlayerEntity> model, float shadowRadius) {
super(dispatcher, model, shadowRadius);
}

@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/client/render/entity/EntityRenderDispatcher;Z)V")
public void init(EntityRenderDispatcher dispatcher, boolean b, CallbackInfo info) {
this.addFeature(new ArtifactFeatureRenderer(this));
}

@Inject(method = "renderLeftArm", at = @At("TAIL"))
private void renderLeftGlove(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, CallbackInfo info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(TitleScreen.class)
public class TitleScreenMixin {
public abstract class TitleScreenMixin {

@Shadow
@Mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private static LivingEntity getUserFromStackHolder(LivingEntity user, BlockState
@Inject(method = "handleIsEffectiveOnIgnoresVanilla", at = @At(value = "TAIL"), cancellable = true)
private static void invokeNonToolsHandlers(BlockState state, ItemStack stack, LivingEntity user, boolean vanillaResult, CallbackInfoReturnable<Boolean> info) {
if (!info.getReturnValueZ()) {
// TODO: does cancelling at return still run other injectors?
info.setReturnValue(ToolHandlers.NON_TOOLS_HANDLER.invoker()
.isEffectiveOn(null, state, stack, user).isAccepted());
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/resources/artifacts.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
"item.whoopeecushion.EntityMixin",
"statuseffect.LivingEntityMixin",
"statuseffect.StatusEffectInstanceMixin",
"trinkets.PlayerEntityMixin",
"trinkets.PlayerTrinketComponentMixin",
"trinkets.TrinketFeatureRendererMixin",
"trinkets.TrinketSlotMixin",
"util.DefaultedRegistryMixin"
],
"client": [
Expand Down

0 comments on commit 199f2a8

Please sign in to comment.