添加副手物品渲染取消机制
This commit is contained in:
parent
d5b7559ebb
commit
5853382fe3
2 changed files with 30 additions and 34 deletions
|
@ -11,7 +11,9 @@ import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.HumanoidArm;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -58,6 +60,20 @@ public class ClientEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRenderHand(RenderHandEvent event) {
|
||||||
|
Player player = Minecraft.getInstance().player;
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
InteractionHand hand = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
||||||
|
|
||||||
|
if (event.getHand() == hand) {
|
||||||
|
if (player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void handleWeaponCrossHair(LivingEntity entity) {
|
private static void handleWeaponCrossHair(LivingEntity entity) {
|
||||||
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||||
float fps = Minecraft.getInstance().getFps();
|
float fps = Minecraft.getInstance().getFps();
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
package net.mcreator.target.mixins;
|
package net.mcreator.target.mixins;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.mcreator.target.item.gun.GunItem;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
|
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
|
||||||
import net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.HumanoidArm;
|
import net.minecraft.world.entity.HumanoidArm;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
@ -18,34 +14,18 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
/**
|
|
||||||
* Author: MrCrayfish
|
|
||||||
*/
|
|
||||||
@Mixin(ItemInHandLayer.class)
|
@Mixin(ItemInHandLayer.class)
|
||||||
public class ItemInHandLayerMixin
|
public class ItemInHandLayerMixin {
|
||||||
{
|
|
||||||
@SuppressWarnings({"ConstantConditions"})
|
@SuppressWarnings({"ConstantConditions"})
|
||||||
@Inject(method = "renderArmWithItem", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "renderArmWithItem(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemDisplayContext;Lnet/minecraft/world/entity/HumanoidArm;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V",
|
||||||
private void renderArmWithItemHead(LivingEntity entity, ItemStack stack, ItemDisplayContext display, HumanoidArm arm, PoseStack poseStack, MultiBufferSource source, int light, CallbackInfo ci)
|
at = @At(value = "HEAD"), cancellable = true)
|
||||||
{
|
private void renderArmWithItemHead(LivingEntity entity, ItemStack stack, ItemDisplayContext display, HumanoidArm arm, PoseStack poseStack, MultiBufferSource source, int light, CallbackInfo ci) {
|
||||||
if(entity.getType() == EntityType.PLAYER)
|
if (entity.getType() == EntityType.PLAYER) {
|
||||||
{
|
if (arm == HumanoidArm.LEFT) {
|
||||||
InteractionHand hand = Minecraft.getInstance().options.mainHand().get() == arm ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
|
ItemStack mainHand = entity.getMainHandItem();
|
||||||
if(hand == InteractionHand.OFF_HAND)
|
if (!mainHand.is(TargetModTags.Items.GUN)) return;
|
||||||
{
|
|
||||||
if(stack.getItem() instanceof GunItem)
|
|
||||||
{
|
|
||||||
ci.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entity.getMainHandItem().getItem() instanceof GunItem) {
|
|
||||||
ci.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(stack.getItem() instanceof GunItem)
|
|
||||||
{
|
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue