This commit is contained in:
Jenny 2025-04-02 11:57:49 +02:00
parent 8651bd6a41
commit 836934d46d
Signed by: Jenny
GPG Key ID: 4A98012FB1C39311
17 changed files with 210 additions and 18 deletions

View File

@ -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)

View File

@ -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<Integer> C_TELEPORT_SCROLL_RANGE, C_TELEPORT_SCROLL_RANGE_RANDOM;
public static final ForgeConfigSpec.ConfigValue<Integer> C_TELEPORT_SCROLL_RANGE, C_TELEPORT_SCROLL_RANGE_RANDOM, C_BROADCAST_RANGE;
public static final ForgeConfigSpec.ConfigValue<List<String>> 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();
}

View File

@ -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,14 +22,24 @@ 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);
}
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);

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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))) {

View File

@ -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();
}

View File

@ -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)) {

View File

@ -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 <MSG> 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);
}
}
}
}

View File

@ -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;

View File

@ -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<SimpleParticleType> {
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);
}
}
}

View File

@ -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<SimpleParticleType> {
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);
}
}
}

View File

@ -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,

View File

@ -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<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, MODID);
public static final RegistryObject<SimpleParticleType> 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);
}
}

View File

@ -0,0 +1,5 @@
{
"textures": [
"magic:particle_health"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

View File

@ -0,0 +1,6 @@
{
"animation": {
"frametime": 5,
"interpolate": false
}
}