WandBoost onGround() check + Attraction Wand

This commit is contained in:
Jenny 2025-04-21 19:09:01 +02:00
parent 9593712e42
commit 90ef92b453
Signed by: Jenny
GPG Key ID: 4A98012FB1C39311
6 changed files with 70 additions and 9 deletions

View File

@ -3,10 +3,7 @@ package com.jenny.magic.items;
import com.jenny.magic.entities.entities; import com.jenny.magic.entities.entities;
import com.jenny.magic.items.amulets.*; import com.jenny.magic.items.amulets.*;
import com.jenny.magic.items.scrolls.*; import com.jenny.magic.items.scrolls.*;
import com.jenny.magic.items.wands.ProjectileWand; import com.jenny.magic.items.wands.*;
import com.jenny.magic.items.wands.WandBoost;
import com.jenny.magic.items.wands.WandPush;
import com.jenny.magic.items.wands.WandVacuum;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
@ -26,6 +23,7 @@ public class items {
public static final RegistryObject<Item> WAND_VACUUM = ITEMS.register("wand_vacuum", () -> new WandVacuum(new Item.Properties())); public static final RegistryObject<Item> WAND_VACUUM = ITEMS.register("wand_vacuum", () -> new WandVacuum(new Item.Properties()));
public static final RegistryObject<Item> WAND_BOOST = ITEMS.register("wand_boost", () -> new WandBoost(new Item.Properties())); public static final RegistryObject<Item> WAND_BOOST = ITEMS.register("wand_boost", () -> new WandBoost(new Item.Properties()));
public static final RegistryObject<Item> WAND_PUSH = ITEMS.register("wand_push", () -> new WandPush(new Item.Properties())); public static final RegistryObject<Item> WAND_PUSH = ITEMS.register("wand_push", () -> new WandPush(new Item.Properties()));
public static final RegistryObject<Item> WAND_ATTRACTION = ITEMS.register("wand_attraction", () -> new WandAttraction(new Item.Properties()));
// SCROLLS // SCROLLS
public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new ScrollTeleportPersistent(new Item.Properties().stacksTo(1))); public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new ScrollTeleportPersistent(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new ScrollTeleportConsumable(new Item.Properties().stacksTo(16))); public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new ScrollTeleportConsumable(new Item.Properties().stacksTo(16)));

View File

@ -4,7 +4,7 @@ import com.jenny.magic.config.ConfigServer;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
@ -21,9 +21,9 @@ public abstract class BaseWand extends Item {
super(properties.durability(100)); super(properties.durability(100));
} }
public static boolean tryUse(ItemStack itemStack, Player player) { public static boolean tryUse(ItemStack itemStack, LivingEntity livingEntity) {
if (!ConfigServer.C_PREVENT_BREAKING.get() || itemStack.getMaxDamage() - itemStack.getDamageValue() > 1) { if (!ConfigServer.C_PREVENT_BREAKING.get() || itemStack.getMaxDamage() - itemStack.getDamageValue() > 1) {
itemStack.hurtAndBreak(1, player, (player2) -> player2.broadcastBreakEvent(player2.getUsedItemHand())); itemStack.hurtAndBreak(1, livingEntity, (player2) -> player2.broadcastBreakEvent(player2.getUsedItemHand()));
return true; return true;
} }
return false; return false;

View File

@ -0,0 +1,8 @@
package com.jenny.magic.items.wands;
public class WandAttraction extends BaseWand {
public WandAttraction(Properties properties) {
super(properties);
}
}

View File

@ -28,7 +28,7 @@ public class WandBoost extends BaseWand {
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, Player pPlayer, @NotNull InteractionHand pHand) { public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, Player pPlayer, @NotNull InteractionHand pHand) {
ItemStack itemStack = pPlayer.getItemInHand(pHand); ItemStack itemStack = pPlayer.getItemInHand(pHand);
if (tryUse(itemStack, pPlayer)) { if (pPlayer.onGround() && tryUse(itemStack, pPlayer)) {
pPlayer.startUsingItem(pHand); pPlayer.startUsingItem(pHand);
return InteractionResultHolder.consume(itemStack); return InteractionResultHolder.consume(itemStack);
} }

View File

@ -0,0 +1,54 @@
package com.jenny.magic.mixins;
import com.jenny.magic.items.items;
import com.jenny.magic.items.wands.BaseWand;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(net.minecraft.world.entity.ai.goal.TemptGoal.class)
public abstract class TemptGoal {
@Shadow
@Final
protected PathfinderMob mob;
@Unique
private static @Nullable ItemStack getStack(@NotNull LivingEntity livingEntity) {
if (livingEntity.getItemInHand(InteractionHand.MAIN_HAND).getItem().asItem().equals(items.WAND_ATTRACTION.get())) {
return livingEntity.getItemInHand(InteractionHand.MAIN_HAND);
} else {
if (items.WAND_ATTRACTION.get().equals(livingEntity.getItemInHand(InteractionHand.OFF_HAND).getItem().asItem())) {
return livingEntity.getItemInHand(InteractionHand.OFF_HAND);
}
}
return null;
}
/**
* @author xJenny69
* @reason Attraction Wand
*/
@Inject(method = "shouldFollow", at = @At("RETURN"), cancellable = true)
private void shouldFollow(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
ItemStack itemStack = getStack(livingEntity);
if (itemStack != null) {
boolean usable = true;
if (livingEntity.level().getRandom().nextInt(30) == 0 && livingEntity.distanceTo(mob) < 10f) {
usable = BaseWand.tryUse(itemStack, livingEntity);
}
if (usable) {
cir.setReturnValue(true);
}
}
}
}

View File

@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"refmap": "magic.refmap.json", "refmap": "magic.refmap.json",
"mixins": [ "mixins": [
"PiglinAi" "PiglinAi",
"TemptGoal"
], ],
"client": [], "client": [],
"injectors": { "injectors": {