Skip to content

Commit

Permalink
升级至1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloePrime committed May 13, 2024
1 parent 6b0d36b commit df80198
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ static HitFeedbackAction addEmitter(Supplier<? extends ParticleOptions> 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);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +19,7 @@

import static mod.chloeprime.hitfeedback.common.HitFeedbackTypes.*;

public class HitFeedbackType extends RegistryEntry<HitFeedbackType> {
public class HitFeedbackType {
private final @Nullable TagKey<EntityType<?>> tag;
private final @Nullable Supplier<SoundEvent> sound;
private final Set<Options> options;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HitFeedbackType> REGISTRY = Registries.get(MOD_ID)
Registrar<HitFeedbackType> REGISTRY = RegistrarManager.get(MOD_ID)
.<HitFeedbackType>builder(HitFeedbackMod.loc("types"))
.build();

@SuppressWarnings("unchecked")
DeferredRegister<HitFeedbackType> DFR = DeferredRegister.create(MOD_ID, (ResourceKey<Registry<HitFeedbackType>>) REGISTRY.key());

Expand All @@ -32,19 +34,19 @@ public interface HitFeedbackTypes {

RegistrySupplier<HitFeedbackType> 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<HitFeedbackType> 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<HitFeedbackType> SLIME_SWORD = DFR.register("slime_sword", () -> new HitFeedbackType(null));

RegistrySupplier<HitFeedbackType> 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<HitFeedbackType> METAL_FAILURE = DFR.register("metal_failure", () -> new HitFeedbackType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
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<SoundEvent> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registry.SOUND_EVENT_REGISTRY);
DeferredRegister<SoundEvent> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registries.SOUND_EVENT);
RegistrySupplier<SoundEvent> FLESH_PUNCH_HIT = register("feedback.flesh.punch");
RegistrySupplier<SoundEvent> FLESH_SWORD_HIT = register("feedback.flesh.sword");
RegistrySupplier<SoundEvent> FLESH_GUNSHOT = register("feedback.flesh.gunshot");
RegistrySupplier<SoundEvent> METAL = register("feedback.metal");
RegistrySupplier<SoundEvent> METAL_FAILURE = register("feedback.metal.failure");

private static RegistrySupplier<SoundEvent> register(String id) {
return DFR.register(id, () -> new SoundEvent(HitFeedbackMod.loc(id)));
return DFR.register(id, () -> SoundEvent.createVariableRangeEvent(HitFeedbackMod.loc(id)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParticleType<?>> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registry.PARTICLE_TYPE_REGISTRY);
DeferredRegister<ParticleType<?>> DFR = DeferredRegister.create(HitFeedbackMod.MOD_ID, Registries.PARTICLE_TYPE);
RegistrySupplier<SimpleParticleType> BLOOD = DFR.register("blood", SimpleParticleType::new);
RegistrySupplier<SimpleParticleType> SPARK = DFR.register("spark", SimpleParticleType::new);
}
4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"

0 comments on commit df80198

Please sign in to comment.