mirror of
https://github.com/TeamMidnightDust/SwordBlocking.git
synced 2025-12-15 22:45:09 +01:00
Update to 1.20.5, and update loom to 1.6.
This commit is contained in:
@@ -12,24 +12,26 @@ import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class SwordBlockingClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
SwordBlockingConfig.init("swordblocking", SwordBlockingConfig.class);
|
||||
|
||||
for (Item item : Registries.ITEM) {
|
||||
if (item instanceof SwordItem || item instanceof AxeItem) {
|
||||
ModelPredicateProviderRegistry.register(item, new Identifier("blocking"),
|
||||
(stack, world, entity, seed) ->
|
||||
entity != null && isWeaponBlocking(entity) ? 1.0F : 0.0F);
|
||||
}
|
||||
if (!(item instanceof SwordItem || item instanceof AxeItem))
|
||||
continue;
|
||||
ModelPredicateProviderRegistry.register(item, new Identifier("blocking"),
|
||||
(stack, world, entity, seed) -> entity != null && isWeaponBlocking(entity) ? 1.0F : 0.0F);
|
||||
}
|
||||
|
||||
FabricLoader.getInstance().getModContainer("swordblocking").ifPresent(modContainer -> {
|
||||
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("swordblocking", "blocking_predicates"), modContainer, ResourcePackActivationType.ALWAYS_ENABLED);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isWeaponBlocking(LivingEntity entity) {
|
||||
return (entity.isUsingItem() && canWeaponBlock(entity));
|
||||
}
|
||||
|
||||
public static boolean canWeaponBlock(LivingEntity entity) {
|
||||
return (SwordBlockingConfig.enabled && (entity.getMainHandStack().getItem() instanceof SwordItem || entity.getMainHandStack().getItem() instanceof AxeItem) &&
|
||||
entity.getOffHandStack().getItem() instanceof ShieldItem) ||
|
||||
|
||||
@@ -15,13 +15,13 @@ public abstract class MixinBipedEntityModel<T extends LivingEntity> {
|
||||
|
||||
@Shadow protected abstract void positionLeftArm(T entity);
|
||||
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;animateArms(Lnet/minecraft/entity/LivingEntity;F)V",
|
||||
shift = At.Shift.BEFORE),method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V")
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;animateArms(Lnet/minecraft/entity/LivingEntity;F)V", shift = At.Shift.BEFORE), method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V")
|
||||
private void swordblocking$setBlockingAngles(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
|
||||
if (SwordBlockingClient.isWeaponBlocking(livingEntity)) {
|
||||
if (livingEntity.getOffHandStack().getItem() instanceof ShieldItem)
|
||||
this.positionRightArm(livingEntity);
|
||||
else this.positionLeftArm(livingEntity);
|
||||
}
|
||||
if (!SwordBlockingClient.isWeaponBlocking(livingEntity))
|
||||
return;
|
||||
if (livingEntity.getOffHandStack().getItem() instanceof ShieldItem)
|
||||
this.positionRightArm(livingEntity);
|
||||
else
|
||||
this.positionLeftArm(livingEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class MixinHeldItemRenderer {
|
||||
@Inject(at = @At("HEAD"), cancellable = true, method = "renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V")
|
||||
public void swordblocking$hideShield(LivingEntity entity, ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
|
||||
if (SwordBlockingConfig.alwaysHideShield && SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem) ci.cancel();
|
||||
else if (SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem && SwordBlockingClient.canWeaponBlock(entity)) ci.cancel();
|
||||
if ((SwordBlockingConfig.alwaysHideShield && SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem) || (SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem && SwordBlockingClient.canWeaponBlock(entity)))
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ public abstract class MixinInGameHud {
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getOffHandStack()Lnet/minecraft/item/ItemStack;"), method = "renderHotbar")
|
||||
public ItemStack swordblocking$hideOffHandSlot(PlayerEntity player) {
|
||||
ItemStack realStack = player.getOffHandStack();
|
||||
if (SwordBlockingConfig.enabled && SwordBlockingConfig.hideOffhandSlot && realStack.getItem() instanceof ShieldItem) return ItemStack.EMPTY;
|
||||
else return realStack;
|
||||
return (SwordBlockingConfig.enabled && SwordBlockingConfig.hideOffhandSlot && realStack.getItem() instanceof ShieldItem) ? ItemStack.EMPTY : realStack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,15 @@ public abstract class MixinPlayerEntityRenderer {
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static void swordblocking$getArmPose(AbstractClientPlayerEntity abstractClientPlayerEntity, Hand hand, CallbackInfoReturnable<BipedEntityModel.ArmPose> cir) {
|
||||
if (!SwordBlockingConfig.enabled) return;
|
||||
|
||||
ItemStack handStack = abstractClientPlayerEntity.getStackInHand(hand);
|
||||
ItemStack offStack = abstractClientPlayerEntity.getStackInHand(hand.equals(Hand.MAIN_HAND) ? Hand.OFF_HAND : Hand.MAIN_HAND);
|
||||
if (!SwordBlockingConfig.alwaysHideShield && (handStack.getItem() instanceof ShieldItem) && !SwordBlockingClient.canWeaponBlock(abstractClientPlayerEntity)) return;
|
||||
if (!SwordBlockingConfig.alwaysHideShield && (handStack.getItem() instanceof ShieldItem) && !SwordBlockingClient.canWeaponBlock(abstractClientPlayerEntity))
|
||||
return;
|
||||
|
||||
if (offStack.getItem() instanceof ShieldItem && abstractClientPlayerEntity.isUsingItem()) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.BLOCK);
|
||||
}
|
||||
else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield) {
|
||||
} else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user