mirror of
https://github.com/TeamMidnightDust/SwordBlocking.git
synced 2025-12-15 14:35:10 +01:00
Improved way of rendering the blocking animation
- Now no longer depends on the integrated resourcepack - Improved compatibility with resourcepacks and mods (closes #17) - Big thanks to @lowercasebtw for contributing this part of the code - Fixed #13
This commit is contained in:
@@ -9,7 +9,7 @@ org.gradle.parallel=true
|
||||
loader_version=0.15.11
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.3.2
|
||||
mod_version = 2.0.0
|
||||
maven_group = eu.midnightdust
|
||||
archives_base_name = swordblocking
|
||||
release_type=release
|
||||
|
||||
@@ -2,33 +2,15 @@ package eu.midnightdust.swordblocking;
|
||||
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.item.ModelPredicateProviderRegistry;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.AxeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import net.minecraft.item.SwordItem;
|
||||
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))
|
||||
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) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.midnightdust.swordblocking.mixin;
|
||||
|
||||
import eu.midnightdust.swordblocking.SwordBlockingClient;
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||
@@ -9,6 +10,9 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -21,4 +25,16 @@ public abstract class MixinHeldItemRenderer {
|
||||
if ((SwordBlockingConfig.alwaysHideShield && SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem) || (SwordBlockingConfig.hideShield && stack.getItem() instanceof ShieldItem && SwordBlockingClient.canWeaponBlock(entity)))
|
||||
ci.cancel();
|
||||
}
|
||||
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;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", shift = At.Shift.BEFORE, ordinal = 1))
|
||||
public void swordblocking$blockingPosition(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
|
||||
if (!SwordBlockingClient.isWeaponBlocking(player) || item.getItem() instanceof ShieldItem)
|
||||
return;
|
||||
boolean bl = hand == Hand.MAIN_HAND;
|
||||
Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
|
||||
int k = arm == Arm.RIGHT ? 1 : -1;
|
||||
matrices.translate(k * -0.14142136F, 0.08F, 0.14142136F);
|
||||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
|
||||
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(k * 13.365F));
|
||||
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(k * 78.05F));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public abstract class MixinPlayerEntityRenderer {
|
||||
@Inject(at = @At(value = "RETURN"), method = "getArmPose", cancellable = true)
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static void swordblocking$getArmPose(AbstractClientPlayerEntity abstractClientPlayerEntity, Hand hand, CallbackInfoReturnable<BipedEntityModel.ArmPose> cir) {
|
||||
private static void swordblocking$getArmPose(AbstractClientPlayerEntity player, 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))
|
||||
ItemStack handStack = player.getStackInHand(hand);
|
||||
ItemStack offStack = player.getStackInHand(hand.equals(Hand.MAIN_HAND) ? Hand.OFF_HAND : Hand.MAIN_HAND);
|
||||
if (!SwordBlockingConfig.alwaysHideShield && (handStack.getItem() instanceof ShieldItem) && !SwordBlockingClient.canWeaponBlock(player))
|
||||
return;
|
||||
|
||||
if (offStack.getItem() instanceof ShieldItem && abstractClientPlayerEntity.isUsingItem()) {
|
||||
if (offStack.getItem() instanceof ShieldItem && SwordBlockingClient.isWeaponBlocking(player)) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.BLOCK);
|
||||
} else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield) {
|
||||
} else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield && (cir.getReturnValue() == BipedEntityModel.ArmPose.ITEM || cir.getReturnValue() == BipedEntityModel.ArmPose.BLOCK)) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"description": "Adds sword blocking to new versions, you just need a shield in your offhand!",
|
||||
"authors": [
|
||||
"Motschen",
|
||||
"TeamMidnightDust"
|
||||
"TeamMidnightDust",
|
||||
"lowercasebtw"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://www.midnightdust.eu/",
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/diamond_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/diamond_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/golden_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/golden_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"credit": "https://github.com/FoundationGames/Parry/blob/master/src/main/resources/assets/minecraft/models/item/handheld_parry.json",
|
||||
"parent": "item/handheld",
|
||||
"display": {
|
||||
"firstperson_righthand": {
|
||||
"rotation": [ 171, 13, 165 ],
|
||||
"translation": [ -2.8, -0.2, -5 ],
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [ 171, 13, 75 ],
|
||||
"translation": [ -2.8, -0.2, -5 ],
|
||||
"scale": [ 1, 1, 1 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/iron_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/iron_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/netherite_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/netherite_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/stone_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/stone_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/wooden_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_axe"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_sword"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/wooden_sword_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_sword"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 12,
|
||||
"_comment_": "'supported_formats' only works for 1.20.2+",
|
||||
"supported_formats": {
|
||||
"min_inclusive": 12,
|
||||
"max_inclusive": 100
|
||||
},
|
||||
"description": "§2Provides the required predicates for Sword Blocking"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.4 KiB |
Reference in New Issue
Block a user