-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
60a345d
commit 0a91c9d
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/net/frozenblock/trailiertales/mixin/client/PlayerItemInHandLayerMixin.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,79 @@ | ||
package net.frozenblock.trailiertales.mixin.client; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.math.Axis; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.model.ArmedModel; | ||
import net.minecraft.client.model.EntityModel; | ||
import net.minecraft.client.model.HeadedModel; | ||
import net.minecraft.client.model.geom.ModelPart; | ||
import net.minecraft.client.renderer.ItemInHandRenderer; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.entity.RenderLayerParent; | ||
import net.minecraft.client.renderer.entity.layers.CustomHeadLayer; | ||
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; | ||
import net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.HumanoidArm; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemDisplayContext; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import org.jetbrains.annotations.NotNull; | ||
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; | ||
|
||
@Mixin(PlayerItemInHandLayer.class) | ||
public abstract class PlayerItemInHandLayerMixin<T extends Player, M extends EntityModel<T> & ArmedModel & HeadedModel> extends ItemInHandLayer<T, M> { | ||
|
||
@Shadow | ||
@Final | ||
private ItemInHandRenderer itemInHandRenderer; | ||
|
||
public PlayerItemInHandLayerMixin(RenderLayerParent<T, M> renderer, ItemInHandRenderer itemInHandRenderer) { | ||
super(renderer, itemInHandRenderer); | ||
} | ||
|
||
@Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true) | ||
void trailierTales$overrideWithNewBrushAnim( | ||
LivingEntity livingEntity, ItemStack itemStack, ItemDisplayContext displayContext, HumanoidArm arm, PoseStack poseStack, MultiBufferSource buffer, int packedLight, | ||
CallbackInfo info | ||
) { | ||
if (itemStack.is(Items.BRUSH) && livingEntity.getUseItem() == itemStack && livingEntity.swingTime == 0) { | ||
info.cancel(); | ||
this.trailierTales$renderArmWithBrush(livingEntity, itemStack, arm, poseStack, buffer, packedLight); | ||
} | ||
} | ||
|
||
@Unique | ||
private void trailierTales$renderArmWithBrush(LivingEntity entity, ItemStack stack, HumanoidArm arm, @NotNull PoseStack poseStack, MultiBufferSource buffer, int combinedLight) { | ||
poseStack.pushPose(); | ||
float remainingTicks = entity.getUseItemRemainingTicks() % 10F; | ||
float partialTick = Minecraft.getInstance().getDeltaFrameTime(); | ||
float g = remainingTicks - partialTick + 1F; | ||
float h = 1.0F - g / 10.0F; | ||
float n = -15.0F + 75.0F * Mth.cos(h * 2.0F * (float) Math.PI); | ||
if (arm != HumanoidArm.RIGHT) { | ||
poseStack.translate(0.1, 0.83, 0.35); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(-80.0F)); | ||
poseStack.mulPose(Axis.YP.rotationDegrees(-90.0F)); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(n)); | ||
poseStack.translate(-0.3, 0.22, 0.35); | ||
} else { | ||
poseStack.translate(-0.25, 0.22, 0.35); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(-80.0F)); | ||
poseStack.mulPose(Axis.YP.rotationDegrees(90.0F)); | ||
poseStack.mulPose(Axis.ZP.rotationDegrees(0.0F)); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(n)); | ||
} | ||
this.itemInHandRenderer.renderItem(entity, stack, ItemDisplayContext.HEAD, false, poseStack, buffer, combinedLight); | ||
poseStack.popPose(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/resources/assets/minecraft/models/item/brush.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,23 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "minecraft:item/brush" | ||
}, | ||
"display": { | ||
"firstperson_lefthand": { | ||
"rotation": [ 55, -85, 0 ], | ||
"translation": [ 8.0, 0.5, -5.5 ], | ||
"scale": [ 1.0, 1.0, 1.0 ] | ||
}, | ||
"thirdperson_righthand": { | ||
"rotation": [ 0, 0, 45 ], | ||
"translation": [ 0, 4, 0 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [ 0, 0, -45 ], | ||
"translation": [ 0, 4, 0 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
} | ||
} | ||
} |
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