Skip to content

Commit

Permalink
more tags
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoLezury committed Jul 16, 2024
1 parent 23b99dc commit 7be2187
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 1.21 2024-07-16T14:37:17.2183249 Tags for minecraft:item mod id assorted_armaments
// 1.21 2024-07-16T16:07:37.0090101 Tags for minecraft:item mod id assorted_armaments
d500bd43e88c70df0ec4054b266d05b7df7e221e data/assorted_armaments/tags/item/can_block.json
f24a559480a18b444e7f297e1003e8167bc0f39a data/assorted_armaments/tags/item/claymores.json
d500bd43e88c70df0ec4054b266d05b7df7e221e data/assorted_armaments/tags/item/efficient_sweep.json
d500bd43e88c70df0ec4054b266d05b7df7e221e data/assorted_armaments/tags/item/two_handed.json
d500bd43e88c70df0ec4054b266d05b7df7e221e data/minecraft/tags/item/swords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#assorted_armaments:claymores"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#assorted_armaments:claymores"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#assorted_armaments:claymores"
]
}
10 changes: 5 additions & 5 deletions src/main/java/team/leomc/assortedarmaments/AACommonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
public class AACommonConfig {
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();

private static final ModConfigSpec.DoubleValue CLAYMORE_BLOCK_WALK_SPEED_MODIFIER = BUILDER
.comment("Player's walk speed when blocking using a claymore = (1 - claymoreBlockWalkSpeedModifier) * originalSpeed")
.defineInRange("claymoreBlockWalkSpeedModifier", 0.25, 0, 1);
private static final ModConfigSpec.DoubleValue WEAPON_BLOCK_WALK_SPEED_MODIFIER = BUILDER
.comment("Player's walk speed when blocking with a weapon = (1 - weaponBlockWalkSpeedModifier) * originalSpeed")
.defineInRange("weaponBlockWalkSpeedModifier", 0.25, 0, 1);

public static final ModConfigSpec SPEC = BUILDER.build();

public static double claymoreBlockWalkSpeedModifier;
public static double weaponBlockWalkSpeedModifier;

@SubscribeEvent
private static void onLoad(final ModConfigEvent event) {
claymoreBlockWalkSpeedModifier = CLAYMORE_BLOCK_WALK_SPEED_MODIFIER.get();
weaponBlockWalkSpeedModifier = WEAPON_BLOCK_WALK_SPEED_MODIFIER.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
AAItems.GOLDEN_CLAYMORE.get(),
AAItems.NETHERITE_CLAYMORE.get()
);
tag(ItemTags.SWORDS).addTags(AAItemTags.CLAYMORES);
tag(AAItemTags.TWO_HANDED).addTag(AAItemTags.CLAYMORES);
tag(AAItemTags.CAN_BLOCK).addTag(AAItemTags.CLAYMORES);
tag(AAItemTags.EFFICIENT_SWEEP).addTag(AAItemTags.CLAYMORES);
tag(ItemTags.SWORDS).addTag(AAItemTags.CLAYMORES);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package team.leomc.assortedarmaments.event;

import com.mojang.logging.LogUtils;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;
import team.leomc.assortedarmaments.AACommonConfig;
import team.leomc.assortedarmaments.AssortedArmaments;
import team.leomc.assortedarmaments.item.ClaymoreItem;
import team.leomc.assortedarmaments.tags.AAItemTags;

@EventBusSubscriber(modid = AssortedArmaments.ID)
public class AACommonEvents {
@SubscribeEvent
private static void onShieldBlock(LivingShieldBlockEvent event) {
if (event.getEntity().isUsingItem() && event.getEntity().getUseItem().is(AAItemTags.CLAYMORES)) {
if (event.getEntity().isUsingItem() && event.getEntity().getUseItem().is(AAItemTags.CAN_BLOCK)) {
double damage = 0;
AttributeInstance damageInstance = event.getEntity().getAttribute(Attributes.ATTACK_DAMAGE);
if (damageInstance != null) {
Expand All @@ -26,19 +26,22 @@ private static void onShieldBlock(LivingShieldBlockEvent event) {
}
}

public static AttributeModifier getBlockSpeedModifier() {
return new AttributeModifier(AssortedArmaments.id("block_speed"), -AACommonConfig.weaponBlockWalkSpeedModifier, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL);
}

@SubscribeEvent
private static void onPostEntityTick(EntityTickEvent.Post event) {
if (event.getEntity() instanceof LivingEntity living && !living.level().isClientSide) {
AttributeInstance speedInstance = living.getAttribute(Attributes.MOVEMENT_SPEED);
if (speedInstance != null) {
if (living.isUsingItem() && living.getUseItem().is(AAItemTags.CLAYMORES)) {
if (!speedInstance.hasModifier(ClaymoreItem.getBlockSpeedModifier().id())) {
speedInstance.addPermanentModifier(ClaymoreItem.getBlockSpeedModifier());
LogUtils.getLogger().warn("Claymore amount: {}", ClaymoreItem.getBlockSpeedModifier().amount());
if (living.isUsingItem() && living.getUseItem().is(AAItemTags.CAN_BLOCK)) {
if (!speedInstance.hasModifier(getBlockSpeedModifier().id())) {
speedInstance.addPermanentModifier(getBlockSpeedModifier());
}
} else {
if (speedInstance.hasModifier(ClaymoreItem.getBlockSpeedModifier().id())) {
speedInstance.removeModifier(ClaymoreItem.getBlockSpeedModifier().id());
if (speedInstance.hasModifier(getBlockSpeedModifier().id())) {
speedInstance.removeModifier(getBlockSpeedModifier().id());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.common.ItemAbility;
import team.leomc.assortedarmaments.AACommonConfig;
import team.leomc.assortedarmaments.AssortedArmaments;

import java.util.List;
Expand All @@ -34,10 +33,6 @@ public static ItemAttributeModifiers createAttributes(Tier tier, float attackDam
.build();
}

public static AttributeModifier getBlockSpeedModifier() {
return new AttributeModifier(AssortedArmaments.id("claymore_block_speed"), -AACommonConfig.claymoreBlockWalkSpeedModifier, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL);
}

@Override
public UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.BLOCK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public abstract class ItemInHandLayerMixin {
@Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true)
private void renderArmWithItem(LivingEntity livingEntity, ItemStack itemStack, ItemDisplayContext displayContext, HumanoidArm arm, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) {
if (livingEntity.getMainHandItem().is(AAItemTags.CLAYMORES) && arm != livingEntity.getMainArm()) {
if (livingEntity.getMainHandItem().is(AAItemTags.TWO_HANDED) && arm != livingEntity.getMainArm()) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public abstract class ItemInHandRendererMixin {
@Inject(method = "evaluateWhichHandsToRender", at = @At("RETURN"), cancellable = true)
private static void evaluateWhichHandsToRender(LocalPlayer player, CallbackInfoReturnable<ItemInHandRenderer.HandRenderSelection> cir) {
if (player.getMainHandItem().is(AAItemTags.CLAYMORES) && cir.getReturnValue().renderMainHand) {
if (player.getMainHandItem().is(AAItemTags.TWO_HANDED) && cir.getReturnValue().renderMainHand) {
cir.setReturnValue(ItemInHandRenderer.HandRenderSelection.RENDER_MAIN_HAND_ONLY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
public abstract class ItemStackMixin {
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
private void use(Level level, Player player, InteractionHand usedHand, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir) {
if (player.getMainHandItem().is(AAItemTags.CLAYMORES) && usedHand == InteractionHand.OFF_HAND) {
if (player.getMainHandItem().is(AAItemTags.TWO_HANDED) && usedHand == InteractionHand.OFF_HAND) {
cir.setReturnValue(InteractionResultHolder.pass(player.getOffhandItem()));
}
}

@Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
private void useOn(UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
if (context.getPlayer() != null && context.getPlayer().getMainHandItem().is(AAItemTags.CLAYMORES) && context.getHand() == InteractionHand.OFF_HAND) {
if (context.getPlayer() != null && context.getPlayer().getMainHandItem().is(AAItemTags.TWO_HANDED) && context.getHand() == InteractionHand.OFF_HAND) {
cir.setReturnValue(InteractionResult.PASS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class LocalPlayerMixin {

@Inject(method = "aiStep", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;sprintTriggerTime:I", ordinal = 3, shift = At.Shift.BEFORE))
private void modifyClaymoreWalkSpeed(CallbackInfo ci) {
if (isUsingItem() && ((Player) (Object) this).getUseItem().is(AAItemTags.CLAYMORES)) {
if (isUsingItem() && ((Player) (Object) this).getUseItem().is(AAItemTags.CAN_BLOCK)) {
input.forwardImpulse *= 5;
input.leftImpulse *= 5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -31,8 +32,8 @@ private void captureOriginalDamage(Entity target, CallbackInfo ci, float f, Item

@ModifyArg(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getEnchantedDamage(Lnet/minecraft/world/entity/Entity;FLnet/minecraft/world/damagesource/DamageSource;)F", ordinal = 1), index = 1)
private float modifySweepDamage(float damage) {
if (getWeaponItem().is(AAItemTags.CLAYMORES)) {
return aa$originalAttackDamage;
if (getWeaponItem().is(AAItemTags.EFFICIENT_SWEEP)) {
return (float) (aa$originalAttackDamage * (1 + ((Player) (Object) this).getAttributeValue(Attributes.SWEEPING_DAMAGE_RATIO) * 0.1));
}
return damage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import team.leomc.assortedarmaments.AssortedArmaments;

public class AAItemTags {
public static final TagKey<Item> TWO_HANDED = create("two_handed");
public static final TagKey<Item> CAN_BLOCK = create("can_block");
public static final TagKey<Item> EFFICIENT_SWEEP = create("efficient_sweep");
public static final TagKey<Item> CLAYMORES = create("claymores");

private static TagKey<Item> create(String id) {
Expand Down

0 comments on commit 7be2187

Please sign in to comment.