diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/client/HitFeedbackAction.java b/common/src/main/java/mod/chloeprime/hitfeedback/client/HitFeedbackAction.java index 3e9ff70..7ceacfa 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/client/HitFeedbackAction.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/client/HitFeedbackAction.java @@ -21,8 +21,8 @@ static HitFeedbackAction addEmitter(Supplier particle return (packet, context) -> { var pos = packet.position; var vel = packet.velocity; - var entity = packet.getEntity(context.getPlayer().getLevel()); - var emitter = constructor.create(particle.get(), builder, entity, ((ClientLevel) entity.getLevel()), pos.x, pos.y, pos.z, vel.x, vel.y, vel.z); + var entity = packet.getEntity(context.getPlayer().level()); + var emitter = constructor.create(particle.get(), builder, entity, ((ClientLevel) entity.level()), pos.x, pos.y, pos.z, vel.x, vel.y, vel.z); ((ParticleEngineAccessor) MinecraftHolder.MC.particleEngine).getTrackingEmitters().add(emitter); }; } diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/EntityPieceParticle.java b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/EntityPieceParticle.java index 853fc24..b0aa668 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/EntityPieceParticle.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/EntityPieceParticle.java @@ -80,8 +80,7 @@ public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) RenderSystem.setShaderTexture(0, texture); builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE); super.render(buffer, renderInfo, partialTicks); - builder.end(); - BufferUploader.end(builder); + BufferUploader.drawWithShader(builder.end()); } @Override diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SimpleTexturedParticle.java b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SimpleTexturedParticle.java index b574dfb..ad934b0 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SimpleTexturedParticle.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SimpleTexturedParticle.java @@ -4,7 +4,6 @@ import net.minecraft.client.particle.ParticleRenderType; import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.particle.TextureSheetParticle; -import net.minecraft.util.Mth; import org.jetbrains.annotations.NotNull; public class SimpleTexturedParticle extends TextureSheetParticle { @@ -14,8 +13,8 @@ public SimpleTexturedParticle(SpriteSet sprite, ClientLevel clientLevel, double this.gravity = 1; setSpriteFromAge(sprite); - var oldVelocity = 1 / Mth.fastInvSqrt(xd * xd + yd * yd + zd * zd); - var newVelocity = 1 / Mth.fastInvSqrt(xv * xv + yv * yv + zv * zv); + var oldVelocity = Math.sqrt(xd * xd + yd * yd + zd * zd); + var newVelocity = Math.sqrt(xv * xv + yv * yv + zv * zv); var velScale = newVelocity / oldVelocity; this.xd *= velScale; this.yd *= velScale; diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SwordFeedbackEmitter.java b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SwordFeedbackEmitter.java index 50b510c..48ce17f 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SwordFeedbackEmitter.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/client/particles/SwordFeedbackEmitter.java @@ -2,6 +2,7 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; @@ -23,7 +24,7 @@ public SwordFeedbackEmitter(ParticleOptions particle, Builder builder, Entity bo } var direction = hitDirections.compute(boundEntity, (k, v) -> !Objects.requireNonNullElse(v, random.nextBoolean())); var relX = UP.cross(relMotion).normalize(); - var angle = random.nextDouble(-Math.PI / 12, Math.PI / 12) + (direction ? Math.PI : 0); + var angle = Mth.lerp(random.nextDouble(), -Math.PI / 12, Math.PI / 12) + (direction ? Math.PI : 0); var offsetDirection = relX.scale(Math.cos(angle)).add(UP.scale(Math.sin(angle))); var offsetAmount = 0.5; this.relPos = this.relPos.add(offsetDirection.scale(offsetAmount)); diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/common/CommonEventHandler.java b/common/src/main/java/mod/chloeprime/hitfeedback/common/CommonEventHandler.java index e1fb624..714225b 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/common/CommonEventHandler.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/common/CommonEventHandler.java @@ -16,7 +16,7 @@ public class CommonEventHandler { public static void onEndAttack(DamageSource source, LivingEntity victim, float amount) { - if (victim.getLevel().isClientSide()) { + if (victim.level().isClientSide()) { return; } var attacker = source.getEntity(); @@ -33,7 +33,7 @@ public static void onEndAttack(DamageSource source, LivingEntity victim, float a var feedback = HitFeedbackType.match(source, victim, amount > 0); if (!feedback.isServerOnly()) { var packet = new S2CHitFeedback(victim, feedback, position, normal); - ((ServerLevel) victim.level).getChunkSource().broadcast(victim, ModNetwork.CHANNEL.toPacket(NetworkManager.Side.S2C, packet)); + ((ServerLevel) victim.level()).getChunkSource().broadcast(victim, ModNetwork.CHANNEL.toPacket(NetworkManager.Side.S2C, packet)); } feedback.getHitSound().ifPresent(sound -> { var pitch = 1 + (victim.getRandom().nextFloat() - victim.getRandom().nextFloat()) * 0.2f; diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackType.java b/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackType.java index 0267075..d885650 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackType.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackType.java @@ -1,10 +1,8 @@ package mod.chloeprime.hitfeedback.common; -import dev.architectury.core.RegistryEntry; import net.minecraft.sounds.SoundEvent; import net.minecraft.tags.TagKey; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.IndirectEntityDamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; @@ -21,7 +19,7 @@ import static mod.chloeprime.hitfeedback.common.HitFeedbackTypes.*; -public class HitFeedbackType extends RegistryEntry { +public class HitFeedbackType { private final @Nullable TagKey> tag; private final @Nullable Supplier sound; private final Set options; @@ -59,7 +57,7 @@ public static HitFeedbackType match(DamageSource source, LivingEntity victim, bo private static HitFeedbackType matchDefault(DamageSource source, LivingEntity victim, boolean valid) { var attacker = source.getEntity(); - var isGunshot = source instanceof IndirectEntityDamageSource; + var isGunshot = source.isIndirect(); var isHoldingSword = !isGunshot && isHoldingSword(attacker); if (!valid) { return isHoldingSword ? METAL_FAILURE.get() : PUNCH.get(); diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackTypes.java b/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackTypes.java index 306a657..a72fe6f 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackTypes.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/common/HitFeedbackTypes.java @@ -2,19 +2,21 @@ import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.Registrar; -import dev.architectury.registry.registries.Registries; +import dev.architectury.registry.registries.RegistrarManager; import dev.architectury.registry.registries.RegistrySupplier; import mod.chloeprime.hitfeedback.HitFeedbackMod; import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import static mod.chloeprime.hitfeedback.HitFeedbackMod.MOD_ID; public interface HitFeedbackTypes { - Registrar REGISTRY = Registries.get(MOD_ID) + Registrar REGISTRY = RegistrarManager.get(MOD_ID) .builder(HitFeedbackMod.loc("types")) .build(); + @SuppressWarnings("unchecked") DeferredRegister DFR = DeferredRegister.create(MOD_ID, (ResourceKey>) REGISTRY.key()); @@ -32,19 +34,19 @@ public interface HitFeedbackTypes { RegistrySupplier BONE = DFR.register("bone", () -> new HitFeedbackType( null, - TagKey.create(Registry.ENTITY_TYPE_REGISTRY, HitFeedbackMod.loc("type/bone")) + TagKey.create(Registries.ENTITY_TYPE, HitFeedbackMod.loc("type/bone")) )); RegistrySupplier METAL = DFR.register("metal", () -> new HitFeedbackType( null, - TagKey.create(Registry.ENTITY_TYPE_REGISTRY, HitFeedbackMod.loc("type/metal")) + TagKey.create(Registries.ENTITY_TYPE, HitFeedbackMod.loc("type/metal")) )); RegistrySupplier SLIME_SWORD = DFR.register("slime_sword", () -> new HitFeedbackType(null)); RegistrySupplier SLIME_GUNSHOT = DFR.register("slime_gunshot", () -> new HitFeedbackType( null, - TagKey.create(Registry.ENTITY_TYPE_REGISTRY, HitFeedbackMod.loc("type/slime")) + TagKey.create(Registries.ENTITY_TYPE, HitFeedbackMod.loc("type/slime")) )); RegistrySupplier METAL_FAILURE = DFR.register("metal_failure", () -> new HitFeedbackType( diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/common/ModSoundEvents.java b/common/src/main/java/mod/chloeprime/hitfeedback/common/ModSoundEvents.java index 09c6a6f..430abd2 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/common/ModSoundEvents.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/common/ModSoundEvents.java @@ -3,13 +3,13 @@ import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; import mod.chloeprime.hitfeedback.HitFeedbackMod; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; import net.minecraft.sounds.SoundEvent; import org.jetbrains.annotations.ApiStatus; @ApiStatus.NonExtendable public interface ModSoundEvents { - DeferredRegister DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registry.SOUND_EVENT_REGISTRY); + DeferredRegister DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registries.SOUND_EVENT); RegistrySupplier FLESH_PUNCH_HIT = register("feedback.flesh.punch"); RegistrySupplier FLESH_SWORD_HIT = register("feedback.flesh.sword"); RegistrySupplier FLESH_GUNSHOT = register("feedback.flesh.gunshot"); @@ -17,6 +17,6 @@ public interface ModSoundEvents { RegistrySupplier METAL_FAILURE = register("feedback.metal.failure"); private static RegistrySupplier register(String id) { - return DFR.register(id, () -> new SoundEvent(HitFeedbackMod.loc(id))); + return DFR.register(id, () -> SoundEvent.createVariableRangeEvent(HitFeedbackMod.loc(id))); } } diff --git a/common/src/main/java/mod/chloeprime/hitfeedback/common/particle/ModParticleTypes.java b/common/src/main/java/mod/chloeprime/hitfeedback/common/particle/ModParticleTypes.java index f1b8dff..b01246f 100644 --- a/common/src/main/java/mod/chloeprime/hitfeedback/common/particle/ModParticleTypes.java +++ b/common/src/main/java/mod/chloeprime/hitfeedback/common/particle/ModParticleTypes.java @@ -3,11 +3,11 @@ import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; import mod.chloeprime.hitfeedback.HitFeedbackMod; -import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.Registries; public interface ModParticleTypes { - DeferredRegister> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registry.PARTICLE_TYPE_REGISTRY); + DeferredRegister> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registries.PARTICLE_TYPE); RegistrySupplier BLOOD = DFR.register("blood", SimpleParticleType::new); RegistrySupplier SPARK = DFR.register("spark", SimpleParticleType::new); } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index ebdca42..58f03a8 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -22,7 +22,7 @@ ], "depends": { "fabricloader": ">=0.15.11", - "minecraft": ">=1.18.2", - "architectury": ">=4.0.0" + "minecraft": ">=1.20.1", + "architectury": ">=9.0.0" } } diff --git a/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/ForgeCommonEventHandler.java b/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/ForgeCommonEventHandler.java index f8148be..9396014 100644 --- a/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/ForgeCommonEventHandler.java +++ b/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/ForgeCommonEventHandler.java @@ -10,6 +10,6 @@ public class ForgeCommonEventHandler { @SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true) public static void onEndAttack(LivingDamageEvent event) { - CommonEventHandler.onEndAttack(event.getSource(), event.getEntityLiving(), event.getAmount()); + CommonEventHandler.onEndAttack(event.getSource(), event.getEntity(), event.getAmount()); } } \ No newline at end of file diff --git a/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/PlatformMethodsImpl.java b/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/PlatformMethodsImpl.java index 0e2a1fb..b2d277b 100644 --- a/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/PlatformMethodsImpl.java +++ b/forge/src/main/java/mod/chloeprime/hitfeedback/common/forge/PlatformMethodsImpl.java @@ -2,7 +2,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.common.ForgeMod; /** * @see mod.chloeprime.hitfeedback.common.PlatformMethods @@ -11,8 +10,8 @@ public class PlatformMethodsImpl { public static double getAttackReach(Entity entity) { if (entity instanceof Player player) { - return player.getAttackRange(); + return player.getEntityReach(); } - return ForgeMod.ATTACK_RANGE.get().getDefaultValue(); + return 32; } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index dbfb675..38a7660 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -6,7 +6,7 @@ # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion="[47,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. license="MIT" @@ -49,7 +49,7 @@ description="Add blood and gore as hit feedback." # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="[40,)" #mandatory + versionRange="[47,)" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER @@ -59,13 +59,13 @@ description="Add blood and gore as hit feedback." modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version - versionRange="[1.18.2,1.19)" + versionRange="[1.20.1,1.20.2)" ordering="NONE" side="BOTH" [[dependencies.hit_feedback]] modId="architectury" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version - versionRange="[4,)" + versionRange="[9,)" ordering="NONE" side="BOTH"