bm,health,repel-scrolls

This commit is contained in:
Jenny 2025-03-28 12:50:42 +01:00
parent 53d86302b6
commit 8651bd6a41
Signed by: Jenny
GPG Key ID: 4A98012FB1C39311
6 changed files with 132 additions and 2 deletions

View File

@ -0,0 +1,33 @@
package com.jenny.magic.items;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BoneMealItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class BonemealScroll extends SingleActionScroll {
public BonemealScroll(Properties pProperties) {
super(pProperties);
}
@Override
void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) {
if (!level.isClientSide) {
boolean flag = false;
for (int x = -5; x <= 5; x++) {
for (int z = -5; z <= 5; z++) {
if (BoneMealItem.applyBonemeal(new ItemStack(Items.BONE_MEAL), level, player.blockPosition().offset(x, 0, z), player)) {
flag = true;
BoneMealItem.applyBonemeal(new ItemStack(Items.BONE_MEAL), level, player.blockPosition().offset(x, 0, z), player);
}
}
}
if (flag) {
itemStack.shrink(1);
}
}
}
}

View File

@ -0,0 +1,28 @@
package com.jenny.magic.items;
import com.jenny.magic.networking.networking;
import com.jenny.magic.networking.packets.EffectS2C;
import com.jenny.magic.particles.effects;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class HealthScroll extends SingleActionScroll {
public HealthScroll(Properties pProperties) {
super(pProperties);
}
@Override
void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) {
if (!level.isClientSide) {
if (player.getMaxHealth() != player.getHealth()) {
player.heal(5);
itemStack.shrink(1);
networking.sendToPlayer(new EffectS2C(effects.EFFECT.SCROLL_HEALTH, player.position().add(0, player.getEyeHeight(), 0)), (ServerPlayer) player);
}
}
}
}

View File

@ -0,0 +1,34 @@
package com.jenny.magic.items;
import com.jenny.magic.networking.networking;
import com.jenny.magic.networking.packets.EffectS2C;
import com.jenny.magic.particles.effects;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class RepelScroll extends SingleActionScroll {
public RepelScroll(Properties pProperties) {
super(pProperties);
}
@Override
void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) {
if (!level.isClientSide) {
boolean flag = false;
for (Entity e : level.getEntitiesOfClass(LivingEntity.class, player.getBoundingBox().inflate(5, 2, 5))) {
e.addDeltaMovement(e.position().subtract(player.position()).normalize().scale(5 * e.position().subtract(player.position()).length()).multiply(1, 0, 1));
flag = true;
networking.sendToPlayer(new EffectS2C(effects.EFFECT.SCROLL_REPEL, e.position().add(0, e.getEyeHeight(), 0)), (ServerPlayer) player);
}
if (flag) {
itemStack.shrink(1);
}
}
}
}

View File

@ -0,0 +1,31 @@
package com.jenny.magic.items;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
abstract class SingleActionScroll extends BaseItem {
public SingleActionScroll(Properties pProperties) {
super(pProperties);
}
@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) {
use(pPlayer.position(), pPlayer, pPlayer.getItemInHand(pUsedHand), pLevel);
return InteractionResultHolder.success(pPlayer.getItemInHand(pUsedHand));
}
@Override
public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {
use(pContext.getClickedPos().getCenter().add(0, 0.5, 0), pContext.getPlayer(), pContext.getItemInHand(), pContext.getLevel());
return InteractionResult.SUCCESS;
}
abstract void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level);
}

View File

@ -17,11 +17,12 @@ public class items {
public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new TeleportScrollPersistent(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new TeleportScrollConsumable(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM = ITEMS.register("scroll_teleport_random", () -> new TeleportScrollRandom(new Item.Properties().stacksTo(1)));
//public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM_BIOME = ITEMS.register("scroll_teleport_random_biome", () -> new TeleportScrollRandomBiome(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> SCROLL_TELEPORT_BIOME_PLAINS = ITEMS.register("scroll_teleport_biome_plains", () -> new TeleportScrollBiome(new Item.Properties().stacksTo(16), Biomes.PLAINS, ChatFormatting.GREEN));
public static final RegistryObject<Item> SCROLL_HEALTH = ITEMS.register("scroll_health", () -> new HealthScroll(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> SCROLL_REPEL = ITEMS.register("scroll_repel", () -> new RepelScroll(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> SCROLL_BONEMEAL = ITEMS.register("scroll_bonemeal", () -> new BonemealScroll(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> DRAGON_HEART = ITEMS.register("dragon_heart", () -> new QualityItem(new Item.Properties()));
public static void register(IEventBus bus) {
ITEMS.register(bus);
}

View File

@ -75,6 +75,9 @@ public class effects {
SCROLL_TELEPORT_ORIGIN,
SCROLL_TELEPORT_TARGET,
SCROLL_HEALTH,
SCROLL_REPEL,
SCROLL_WITHER,
SCROLL_BONEMEAL,
WAND_VACUUM
}
}