mirror of
https://github.com/TeamMidnightDust/SwordBlocking.git
synced 2025-12-15 22:45:09 +01:00
SwordBlocking 1.2.0 - 1.19.3, Config, Axe blocking,
- Added configuration screen based on MidnightLib - Made everything configurable - Add option to hide offhand slot when it contains a shield - Fix 3rd-person blocking
This commit is contained in:
@@ -1,31 +1,39 @@
|
||||
package eu.midnightdust.swordblocking;
|
||||
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||
import net.minecraft.client.item.UnclampedModelPredicateProvider;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
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.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SwordBlockingClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
for (Item item : Registry.ITEM) {
|
||||
if (item instanceof SwordItem) {
|
||||
FabricModelPredicateProviderRegistry.register(item, new Identifier("blocking"), new UnclampedModelPredicateProvider() {
|
||||
@Override
|
||||
public float unclampedCall(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity, int seed) {
|
||||
return entity != null && entity.getOffHandStack().getItem().equals(Items.SHIELD) && entity.isUsingItem() ? 1.0F : 0.0F;
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
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) ||
|
||||
((entity.getOffHandStack().getItem() instanceof SwordItem || entity.getOffHandStack().getItem() instanceof AxeItem) &&
|
||||
entity.getMainHandStack().getItem() instanceof ShieldItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package eu.midnightdust.swordblocking.config;
|
||||
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
|
||||
public class SwordBlockingConfig extends MidnightConfig {
|
||||
@Entry public static boolean enabled = true;
|
||||
@Entry public static boolean hideShield = true;
|
||||
@Entry public static boolean alwaysHideShield = true;
|
||||
@Entry public static boolean hideOffhandSlot = false;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.midnightdust.swordblocking.mixin;
|
||||
|
||||
import eu.midnightdust.swordblocking.SwordBlockingClient;
|
||||
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(BipedEntityModel.class)
|
||||
public abstract class MixinBipedEntityModel<T extends LivingEntity> {
|
||||
@Shadow protected abstract void positionRightArm(T entity);
|
||||
|
||||
@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")
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.midnightdust.swordblocking.mixin;
|
||||
|
||||
import eu.midnightdust.swordblocking.SwordBlockingClient;
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(HeldItemRenderer.class)
|
||||
public abstract class MixinHeldItemRenderer {
|
||||
@Inject(at = @At("HEAD"), cancellable = true, method = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V")
|
||||
public void swordblocking$hideShield(LivingEntity entity, ItemStack stack, ModelTransformation.Mode 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package eu.midnightdust.swordblocking.mixin;
|
||||
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.midnightdust.swordblocking.mixin;
|
||||
|
||||
import eu.midnightdust.swordblocking.SwordBlockingClient;
|
||||
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
@@ -15,17 +17,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PlayerEntityRenderer.class)
|
||||
public abstract class MixinPlayerEntityRenderer {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "getArmPose", cancellable = true)
|
||||
@Inject(at = @At(value = "RETURN"), method = "getArmPose", cancellable = true)
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static void getArmPose(AbstractClientPlayerEntity abstractClientPlayerEntity, Hand hand, CallbackInfoReturnable<BipedEntityModel.ArmPose> cir) {
|
||||
ItemStack itemStack = abstractClientPlayerEntity.getStackInHand(hand);
|
||||
ItemStack itemStack2 = abstractClientPlayerEntity.getOffHandStack();
|
||||
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 (itemStack2.getItem() instanceof ShieldItem && abstractClientPlayerEntity.isUsingItem()) {
|
||||
if (offStack.getItem() instanceof ShieldItem && abstractClientPlayerEntity.isUsingItem()) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.BLOCK);
|
||||
}
|
||||
if (itemStack.getItem() instanceof ShieldItem) {
|
||||
else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield) {
|
||||
cir.setReturnValue(BipedEntityModel.ArmPose.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"parent": "builtin/entity",
|
||||
"gui_light": "front",
|
||||
"textures": {
|
||||
"particle": "block/dark_oak_planks"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [ 0, 90, 0 ],
|
||||
"translation": [ 10, 6, -4 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"thirdperson_lefthand": {
|
||||
"rotation": [ 0, 90, 0 ],
|
||||
"translation": [ 10, 6, 12 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"firstperson_righthand": {
|
||||
"rotation": [ 0, 180, 5 ],
|
||||
"translation": [ -10, 2, -10 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [ 0, 180, 5 ],
|
||||
"translation": [ 10, 0, -10 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"gui": {
|
||||
"rotation": [ 15, -25, -5 ],
|
||||
"translation": [ 2, 3, 0 ],
|
||||
"scale": [ 0.65, 0.65, 0.65 ]
|
||||
},
|
||||
"fixed": {
|
||||
"rotation": [ 0, 180, 0 ],
|
||||
"translation": [ -2, 4, -5],
|
||||
"scale":[ 0.5, 0.5, 0.5]
|
||||
},
|
||||
"ground": {
|
||||
"rotation": [ 0, 0, 0 ],
|
||||
"translation": [ 4, 4, 2],
|
||||
"scale":[ 0.25, 0.25, 0.25]
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "item/shield_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"parent": "builtin/entity",
|
||||
"gui_light": "front",
|
||||
"textures": {
|
||||
"particle": "block/dark_oak_planks"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [ 45, 135, 0 ],
|
||||
"translation": [ 3.51, 11, -2 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"thirdperson_lefthand": {
|
||||
"rotation": [ 45, 135, 0 ],
|
||||
"translation": [ 13.51, 3, 5 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"firstperson_righthand": {
|
||||
"rotation": [ 0, 180, -5 ],
|
||||
"translation": [ -15, 5, -11 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [ 0, 180, -5 ],
|
||||
"translation": [ 5, 5, -11 ],
|
||||
"scale": [ 0, 0, 0 ]
|
||||
},
|
||||
"gui": {
|
||||
"rotation": [ 15, -25, -5 ],
|
||||
"translation": [ 2, 3, 0 ],
|
||||
"scale": [ 0.65, 0.65, 0.65 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/main/resources/assets/swordblocking/lang/en_us.json
Normal file
8
src/main/resources/assets/swordblocking/lang/en_us.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"swordblocking.midnightconfig.title": "Sword Blocking Config",
|
||||
"swordblocking.midnightconfig.enabled": "Enabled",
|
||||
"swordblocking.midnightconfig.hideShield": "Hide Shield",
|
||||
"swordblocking.midnightconfig.alwaysHideShield": "Always Hide Shield",
|
||||
"swordblocking.midnightconfig.hideOffhandSlot": "Hide Offhand Slot",
|
||||
"swordblocking.midnightconfig.hideOffhandSlot.tooltip": "Hides the offhand slot when a shield is in the offhand."
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Sword Blocking",
|
||||
"description": "Adds sword blocking back to 1.16, you just need a shield in your offhand!",
|
||||
"description": "Adds sword blocking to new versions, you just need a shield in your offhand!",
|
||||
"authors": [
|
||||
"Motschen",
|
||||
"TeamMidnightDust"
|
||||
@@ -30,6 +30,7 @@
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabric": "*"
|
||||
"fabric": "*",
|
||||
"midnightlib": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/diamond_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/diamond_axe"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/golden_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/golden_axe"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/iron_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/iron_axe"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/netherite_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/netherite_axe"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/stone_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/stone_axe"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_axe"
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"blocking": 1
|
||||
},
|
||||
"model": "minecraft:item/wooden_axe_blocking"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld_blocking",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/wooden_axe"
|
||||
}
|
||||
}
|
||||
6
src/main/resources/resourcepacks/blocking_predicates/pack.mcmeta
Executable file
6
src/main/resources/resourcepacks/blocking_predicates/pack.mcmeta
Executable file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 12,
|
||||
"description": "§2Provides the required predicates for Sword Blocking"
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/resourcepacks/blocking_predicates/pack.png
Normal file
BIN
src/main/resources/resourcepacks/blocking_predicates/pack.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "eu.midnightdust.swordblocking.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"MixinPlayerEntityRenderer"
|
||||
"MixinPlayerEntityRenderer",
|
||||
"MixinBipedEntityModel",
|
||||
"MixinInGameHud",
|
||||
"MixinHeldItemRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user