From 836934d46dc74e48f56de263269d0624c530d11d Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 2 Apr 2025 11:57:49 +0200 Subject: [PATCH] tmp --- src/main/java/com/jenny/magic/Magic.java | 2 + .../com/jenny/magic/config/ConfigServer.java | 5 +- .../java/com/jenny/magic/items/BaseWand.java | 31 +++++++---- .../com/jenny/magic/items/BonemealScroll.java | 7 ++- .../com/jenny/magic/items/HealthScroll.java | 4 +- .../com/jenny/magic/items/RepelScroll.java | 2 +- .../com/jenny/magic/items/TeleportScroll.java | 2 +- .../com/jenny/magic/items/WandVacuum.java | 2 +- .../jenny/magic/networking/networking.java | 12 ++++ .../magic/networking/packets/EffectS2C.java | 2 +- .../jenny/magic/particles/BasicParticle.java | 43 +++++++++++++++ .../com/jenny/magic/particles/Particle.java | 52 ++++++++++++++++++ .../com/jenny/magic/particles/effects.java | 22 ++++++++ .../com/jenny/magic/particles/particles.java | 31 +++++++++++ .../magic/particles/particle_health.json | 5 ++ .../textures/particle/particle_health.png | Bin 0 -> 196 bytes .../particle/particle_health.png.mcmeta | 6 ++ 17 files changed, 210 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/jenny/magic/particles/BasicParticle.java create mode 100644 src/main/java/com/jenny/magic/particles/Particle.java create mode 100644 src/main/java/com/jenny/magic/particles/particles.java create mode 100644 src/main/resources/assets/magic/particles/particle_health.json create mode 100644 src/main/resources/assets/magic/textures/particle/particle_health.png create mode 100644 src/main/resources/assets/magic/textures/particle/particle_health.png.mcmeta diff --git a/src/main/java/com/jenny/magic/Magic.java b/src/main/java/com/jenny/magic/Magic.java index c550ef9..2b3469c 100644 --- a/src/main/java/com/jenny/magic/Magic.java +++ b/src/main/java/com/jenny/magic/Magic.java @@ -8,6 +8,7 @@ import com.jenny.magic.enchantments.enchantments; import com.jenny.magic.entities.entities; import com.jenny.magic.items.items; import com.jenny.magic.networking.networking; +import com.jenny.magic.particles.particles; import com.mojang.logging.LogUtils; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; @@ -37,6 +38,7 @@ public class Magic { blockEntities.register(modEventBus); enchantments.register(modEventBus); creativeTab.register(modEventBus); + particles.register(modEventBus); } @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) diff --git a/src/main/java/com/jenny/magic/config/ConfigServer.java b/src/main/java/com/jenny/magic/config/ConfigServer.java index af24f2f..40276d8 100644 --- a/src/main/java/com/jenny/magic/config/ConfigServer.java +++ b/src/main/java/com/jenny/magic/config/ConfigServer.java @@ -11,7 +11,7 @@ import static com.jenny.magic.Magic.MODID; @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ConfigServer { public static final ForgeConfigSpec SPEC; - public static final ForgeConfigSpec.ConfigValue C_TELEPORT_SCROLL_RANGE, C_TELEPORT_SCROLL_RANGE_RANDOM; + public static final ForgeConfigSpec.ConfigValue C_TELEPORT_SCROLL_RANGE, C_TELEPORT_SCROLL_RANGE_RANDOM, C_BROADCAST_RANGE; public static final ForgeConfigSpec.ConfigValue> C_DISABLED_LIST; private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); @@ -25,6 +25,9 @@ public class ConfigServer { C_DISABLED_LIST = BUILDER.comment("add any items (without mod ID) from this mod to this list to disable their recipes") .define("disabled_items", defaultListDisabled()); + C_BROADCAST_RANGE = + BUILDER.comment("up to which distance to send particle effects to players") + .defineInRange("scroll_teleport_random_range", 128, 1, 60000000); SPEC = BUILDER.build(); } diff --git a/src/main/java/com/jenny/magic/items/BaseWand.java b/src/main/java/com/jenny/magic/items/BaseWand.java index af4d5ed..5086fae 100644 --- a/src/main/java/com/jenny/magic/items/BaseWand.java +++ b/src/main/java/com/jenny/magic/items/BaseWand.java @@ -1,8 +1,6 @@ package com.jenny.magic.items; import com.jenny.magic.entities.BaseWandProjectile; -import com.jenny.magic.mana.ManaClient; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; @@ -12,7 +10,10 @@ import org.jetbrains.annotations.NotNull; public abstract class BaseWand extends QualityItem { public BaseWand(Properties properties) { - super(properties.stacksTo(1)); + super(properties.stacksTo(1).durability(100)); + } + + private static void onItemDestroyed(Player player) { } @Override @@ -21,15 +22,25 @@ public abstract class BaseWand extends QualityItem { BaseWandProjectile projectile = newProjectile(pLevel); projectile.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 2.0F); pLevel.addFreshEntity(projectile); - - if (!pLevel.isClientSide) { - manaUpdate((ServerPlayer) pPlayer); - } else { - ManaClient.lastUse = System.currentTimeMillis(); - } - + setDamage(itemstack, getDamage(itemstack) + damageItem(itemstack, 1, pPlayer, (player) -> onItemDestroyed(player))); return InteractionResultHolder.success(itemstack); } + ; + + @Override + public boolean isValidRepairItem(@NotNull ItemStack pStack, @NotNull ItemStack pRepairCandidate) { + if (pRepairCandidate.getItem().getDescriptionId().equals(items.DRAGON_HEART.get().getDescriptionId())) { + while (pRepairCandidate.getCount() >= 1 && pStack.isDamaged()) { + pRepairCandidate.shrink(1); + pStack.setDamageValue(pStack.getDamageValue() - 20); + System.out.println("test"); + } + return true; + } else { + return false; + } + } + abstract BaseWandProjectile newProjectile(Level level); } diff --git a/src/main/java/com/jenny/magic/items/BonemealScroll.java b/src/main/java/com/jenny/magic/items/BonemealScroll.java index 583dafc..abd197a 100644 --- a/src/main/java/com/jenny/magic/items/BonemealScroll.java +++ b/src/main/java/com/jenny/magic/items/BonemealScroll.java @@ -1,5 +1,9 @@ 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.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.ItemStack; @@ -14,7 +18,7 @@ public class BonemealScroll extends SingleActionScroll { } @Override - void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) { + void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, @NotNull Level level) { if (!level.isClientSide) { boolean flag = false; for (int x = -5; x <= 5; x++) { @@ -26,6 +30,7 @@ public class BonemealScroll extends SingleActionScroll { } } if (flag) { + networking.sendToClose(new EffectS2C(effects.EFFECT.SCROLL_BONEMEAL, player.position().add(0, player.getEyeHeight(), 0)), (ServerLevel) level); itemStack.shrink(1); } } diff --git a/src/main/java/com/jenny/magic/items/HealthScroll.java b/src/main/java/com/jenny/magic/items/HealthScroll.java index 5a48322..d78322f 100644 --- a/src/main/java/com/jenny/magic/items/HealthScroll.java +++ b/src/main/java/com/jenny/magic/items/HealthScroll.java @@ -3,7 +3,7 @@ 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.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -21,7 +21,7 @@ public class HealthScroll extends SingleActionScroll { 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); + networking.sendToClose(new EffectS2C(effects.EFFECT.SCROLL_HEALTH, player.position().add(0, player.getEyeHeight(), 0)), (ServerLevel) level); } } } diff --git a/src/main/java/com/jenny/magic/items/RepelScroll.java b/src/main/java/com/jenny/magic/items/RepelScroll.java index 4209bf2..9f3cb68 100644 --- a/src/main/java/com/jenny/magic/items/RepelScroll.java +++ b/src/main/java/com/jenny/magic/items/RepelScroll.java @@ -18,7 +18,7 @@ public class RepelScroll extends SingleActionScroll { } @Override - void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) { + void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, @NotNull Level level) { if (!level.isClientSide) { boolean flag = false; for (Entity e : level.getEntitiesOfClass(LivingEntity.class, player.getBoundingBox().inflate(5, 2, 5))) { diff --git a/src/main/java/com/jenny/magic/items/TeleportScroll.java b/src/main/java/com/jenny/magic/items/TeleportScroll.java index 8184a70..fbdcd44 100644 --- a/src/main/java/com/jenny/magic/items/TeleportScroll.java +++ b/src/main/java/com/jenny/magic/items/TeleportScroll.java @@ -43,7 +43,7 @@ public class TeleportScroll extends BaseItem { return InteractionResult.SUCCESS; } - public static String dim(Level level) { + public static @NotNull String dim(@NotNull Level level) { return level.dimension().location().toString(); } diff --git a/src/main/java/com/jenny/magic/items/WandVacuum.java b/src/main/java/com/jenny/magic/items/WandVacuum.java index e1c854a..1471372 100644 --- a/src/main/java/com/jenny/magic/items/WandVacuum.java +++ b/src/main/java/com/jenny/magic/items/WandVacuum.java @@ -33,7 +33,7 @@ public class WandVacuum extends BaseItem { return InteractionResult.SUCCESS; } - protected void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) { + protected void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, @NotNull Level level) { if (!level.isClientSide) { AABB aabb = new AABB(player.position().subtract(20, 20, 20), player.position().add(20, 20, 20)); for (ItemEntity e : level.getEntitiesOfClass(ItemEntity.class, aabb)) { diff --git a/src/main/java/com/jenny/magic/networking/networking.java b/src/main/java/com/jenny/magic/networking/networking.java index 323b582..36eba87 100644 --- a/src/main/java/com/jenny/magic/networking/networking.java +++ b/src/main/java/com/jenny/magic/networking/networking.java @@ -1,14 +1,18 @@ package com.jenny.magic.networking; +import com.jenny.magic.config.ConfigServer; import com.jenny.magic.networking.packets.EffectS2C; import com.jenny.magic.networking.packets.ManaAmountS2C; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.network.NetworkDirection; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.simple.SimpleChannel; +import java.util.function.Predicate; + import static com.jenny.magic.Magic.MODID; public class networking { @@ -48,4 +52,12 @@ public class networking { public static void sendToPlayer(MSG message, ServerPlayer player) { INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), message); } + + public static void sendToClose(EffectS2C message, ServerLevel level) { + for (ServerPlayer p : level.getPlayers(Predicate.not(ServerPlayer::hasDisconnected)).stream().toList()) { + if (p.position().subtract(message.vector1).length() <= ConfigServer.C_BROADCAST_RANGE.get()) { + INSTANCE.send(PacketDistributor.PLAYER.with(() -> p), message); + } + } + } } diff --git a/src/main/java/com/jenny/magic/networking/packets/EffectS2C.java b/src/main/java/com/jenny/magic/networking/packets/EffectS2C.java index 586abb9..a9fe554 100644 --- a/src/main/java/com/jenny/magic/networking/packets/EffectS2C.java +++ b/src/main/java/com/jenny/magic/networking/packets/EffectS2C.java @@ -9,7 +9,7 @@ import java.util.function.Supplier; public class EffectS2C { private final effects.EFFECT effectID; - private final Vec3 vector1; + public final Vec3 vector1; public EffectS2C(effects.EFFECT effectID, Vec3 origin) { this.effectID = effectID; diff --git a/src/main/java/com/jenny/magic/particles/BasicParticle.java b/src/main/java/com/jenny/magic/particles/BasicParticle.java new file mode 100644 index 0000000..7bde615 --- /dev/null +++ b/src/main/java/com/jenny/magic/particles/BasicParticle.java @@ -0,0 +1,43 @@ +package com.jenny.magic.particles; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.NotNull; + +@OnlyIn(Dist.CLIENT) +public class BasicParticle extends SimpleAnimatedParticle { + BasicParticle(ClientLevel pLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed, SpriteSet pSprites) { + super(pLevel, pX, pY, pZ, pSprites, 0.0125F); + this.xd = pXSpeed; + this.yd = pYSpeed; + this.zd = pZSpeed; + this.quadSize *= 0.75F; + this.lifetime = 60 + this.random.nextInt(12); + this.setFadeColor(15916745); + this.setSpriteFromAge(pSprites); + } + + public void move(double pX, double pY, double pZ) { + this.setBoundingBox(this.getBoundingBox().move(pX, pY, pZ)); + this.setLocationFromBoundingbox(); + } + + @OnlyIn(Dist.CLIENT) + public static class Provider implements ParticleProvider { + private final SpriteSet sprites; + + public Provider(SpriteSet pSprites) { + this.sprites = pSprites; + } + + public Particle createParticle(@NotNull SimpleParticleType pType, @NotNull ClientLevel pLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed) { + return new BasicParticle(pLevel, pX, pY, pZ, pXSpeed, pYSpeed, pZSpeed, this.sprites); + } + } +} diff --git a/src/main/java/com/jenny/magic/particles/Particle.java b/src/main/java/com/jenny/magic/particles/Particle.java new file mode 100644 index 0000000..033c2ef --- /dev/null +++ b/src/main/java/com/jenny/magic/particles/Particle.java @@ -0,0 +1,52 @@ +package com.jenny.magic.particles; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.NotNull; + +public class Particle extends TextureSheetParticle { + private final float quadSizeStart; + + protected Particle(ClientLevel level, double xCoord, double yCoord, double zCoord, + SpriteSet spriteSet, double xd, double yd, double zd) { + super(level, xCoord, yCoord, zCoord, xd, yd, zd); + this.friction = 0.8F; + this.xd = xd; + this.yd = yd; + this.zd = zd; + this.quadSizeStart = this.quadSize; + this.lifetime = 40; + this.setSpriteFromAge(spriteSet); + + this.rCol = 1f; + this.gCol = 1f; + this.bCol = 1f; + } + + @Override + @NotNull + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; + } + + @OnlyIn(Dist.CLIENT) + public static class Provider implements ParticleProvider { + private final SpriteSet sprites; + + public Provider(SpriteSet spriteSet) { + this.sprites = spriteSet; + } + + public net.minecraft.client.particle.Particle createParticle(@NotNull SimpleParticleType particleType, @NotNull ClientLevel level, + double x, double y, double z, + double dx, double dy, double dz) { + return new Particle(level, x, y, z, this.sprites, dx, dy, dz); + } + } +} diff --git a/src/main/java/com/jenny/magic/particles/effects.java b/src/main/java/com/jenny/magic/particles/effects.java index d734831..744f98a 100644 --- a/src/main/java/com/jenny/magic/particles/effects.java +++ b/src/main/java/com/jenny/magic/particles/effects.java @@ -14,6 +14,8 @@ public class effects { case WAND_VACUUM -> wandVacuum(origin); case SCROLL_TELEPORT_ORIGIN -> teleportOrigin(origin); case SCROLL_TELEPORT_TARGET -> teleportTarget(origin); + case SCROLL_BONEMEAL -> bonemeal(origin); + case SCROLL_HEALTH -> health(origin); } } @@ -42,6 +44,22 @@ public class effects { } } + private static void bonemeal(Vec3 v) { + Vec3 pos; + for (int i = 0; i < 50; i++) { + pos = randPosBetween2D(2, 4).add(v); + level().addParticle(ParticleTypes.COMPOSTER, pos.x, pos.y, pos.z, 0, 0, 0); + } + } + + private static void health(Vec3 v) { + Vec3 pos; + for (int i = 0; i < 50; i++) { + pos = randPosBetween2D(2, 4).add(v); + level().addParticle(particles.PARTICLE_HEALTH.get(), pos.x, pos.y, pos.z, 0, 0, 0); + } + } + public static Vec3 randPos(float maxDist) { return new Vec3( rng().nextFloat() * 2 - 1, @@ -56,6 +74,10 @@ public class effects { rng().nextFloat() * 2 - 1).normalize().scale(maxDist); } + public static Vec3 randPosBetween2D(float minDist, float maxDist) { + return randPos2D(1).scale((minDist + rng().nextFloat() * (maxDist - minDist))); + } + public static Vec3 randPosRandDist(float maxDist) { return new Vec3( rng().nextFloat() * 2 - 1, diff --git a/src/main/java/com/jenny/magic/particles/particles.java b/src/main/java/com/jenny/magic/particles/particles.java new file mode 100644 index 0000000..9aec92c --- /dev/null +++ b/src/main/java/com/jenny/magic/particles/particles.java @@ -0,0 +1,31 @@ +package com.jenny.magic.particles; + +import net.minecraft.client.Minecraft; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraftforge.client.event.RegisterParticleProvidersEvent; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +import static com.jenny.magic.Magic.MODID; + +@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class particles { + public static final DeferredRegister> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, MODID); + + public static final RegistryObject PARTICLE_HEALTH = + PARTICLES.register("particle_health", () -> new SimpleParticleType(true)); + + public static void register(IEventBus bus) { + PARTICLES.register(bus); + } + + @SubscribeEvent + public static void registerParticleFactories(final RegisterParticleProvidersEvent event) { + Minecraft.getInstance().particleEngine.register(PARTICLE_HEALTH.get(), BasicParticle.Provider::new); + } +} diff --git a/src/main/resources/assets/magic/particles/particle_health.json b/src/main/resources/assets/magic/particles/particle_health.json new file mode 100644 index 0000000..c4ece4a --- /dev/null +++ b/src/main/resources/assets/magic/particles/particle_health.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "magic:particle_health" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/magic/textures/particle/particle_health.png b/src/main/resources/assets/magic/textures/particle/particle_health.png new file mode 100644 index 0000000000000000000000000000000000000000..4c46dfbd2177184552dc5fa8b43e75ada286f186 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^96)Tr!3HD`lHV+gZgTKC_*@Vp(D^y%^*=22WQ%mvv4FO#s!1Nq7JN literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/magic/textures/particle/particle_health.png.mcmeta b/src/main/resources/assets/magic/textures/particle/particle_health.png.mcmeta new file mode 100644 index 0000000..6dd9383 --- /dev/null +++ b/src/main/resources/assets/magic/textures/particle/particle_health.png.mcmeta @@ -0,0 +1,6 @@ +{ + "animation": { + "frametime": 5, + "interpolate": false + } +} \ No newline at end of file