server fix

This commit is contained in:
2026-03-23 11:25:49 +01:00
parent f2c6cccb0a
commit f5f2443650
7 changed files with 16 additions and 26 deletions

View File

@@ -6,7 +6,7 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10 yarn_mappings=1.20.1+build.10
loader_version=0.18.3 loader_version=0.18.3
# Mod Properties # Mod Properties
mod_version=26.3.22 mod_version=26.3.23
maven_group=dev.tggamesyt maven_group=dev.tggamesyt
archives_base_name=szar archives_base_name=szar
# Dependencies # Dependencies

View File

@@ -1,10 +1,10 @@
package dev.tggamesyt.szar.client; package dev.tggamesyt.szar.client;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundInstance; import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@@ -106,7 +106,7 @@ public class VideoManager {
ClientWorld world = client.world; ClientWorld world = client.world;
if (world == null) return; if (world == null) return;
ClientPlayerEntity player = (ClientPlayerEntity) world.getPlayerByUuid(playerUuid); PlayerEntity player = world.getPlayerByUuid(playerUuid);
if (player == null) return; if (player == null) return;
Identifier soundId = new Identifier(MOD_ID, "firtana"); Identifier soundId = new Identifier(MOD_ID, "firtana");

View File

@@ -123,7 +123,7 @@ public class FaszItem extends BlockItem {
if (e.getBoundingBox().contains(px, py, pz)) { if (e.getBoundingBox().contains(px, py, pz)) {
if (e instanceof LivingEntity living) { if (e instanceof LivingEntity living) {
// Always deal half a heart // Always deal half a heart
RegistryEntry<DamageType> radiationEntry = SERVER.getRegistryManager() RegistryEntry<DamageType> radiationEntry = living.getServer().getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE) .get(RegistryKeys.DAMAGE_TYPE)
.getEntry(FCK_DAMAGE) .getEntry(FCK_DAMAGE)
.orElseThrow(() -> new IllegalStateException("FCK DamageType not registered!")); .orElseThrow(() -> new IllegalStateException("FCK DamageType not registered!"));

View File

@@ -14,6 +14,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@@ -290,9 +291,13 @@ public class PlaneEntity extends Entity {
} }
private void playServerAnimation(PlaneAnimation anim) { private void playServerAnimation(PlaneAnimation anim) {
if (this.currentServerAnimation == anim) return; if (this.currentServerAnimation == anim) return;
if (this.getWorld().isClient) return;
MinecraftServer server = this.getWorld().getServer();
if (server == null) return;
this.currentServerAnimation = anim; this.currentServerAnimation = anim;
Szar.playPlaneAnimation(anim, this.getId()); Szar.playPlaneAnimation(anim, this.getId(), server);
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)

View File

@@ -29,18 +29,14 @@ public class RadiationStatusEffect extends StatusEffect {
@Override @Override
public void applyUpdateEffect(LivingEntity entity, int amplifier) { public void applyUpdateEffect(LivingEntity entity, int amplifier) {
int level = amplifier + 1; int level = amplifier + 1;
float damage = (float) getInterpolatedDamage(level); float damage = (float) getInterpolatedDamage(level);
RegistryEntry<DamageType> radiationEntry = SERVER.getRegistryManager() RegistryEntry<DamageType> radiationEntry = entity.getWorld().getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE) .get(RegistryKeys.DAMAGE_TYPE)
.getEntry(RADIATION_DAMAGE) .getEntry(RADIATION_DAMAGE)
.orElseThrow(() -> new IllegalStateException("Radiation DamageType not registered!")); .orElseThrow(() -> new IllegalStateException("Radiation DamageType not registered!"));
entity.damage( entity.damage(new DamageSource(radiationEntry), damage);
new DamageSource(radiationEntry),
damage
);
} }
/* ========================= */ /* ========================= */

View File

@@ -101,7 +101,6 @@ import static dev.tggamesyt.szar.ServerCosmetics.sync;
public class Szar implements ModInitializer { public class Szar implements ModInitializer {
public static final String MOD_ID = "szar"; public static final String MOD_ID = "szar";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID); public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
public static MinecraftServer SERVER;
public static int april = 4; public static int april = 4;
public static int fools = 1; public static int fools = 1;
public static final Identifier DRUNK_TYPE_PACKET = new Identifier(MOD_ID, "drunk_type"); public static final Identifier DRUNK_TYPE_PACKET = new Identifier(MOD_ID, "drunk_type");
@@ -570,7 +569,7 @@ public class Szar implements ModInitializer {
SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 0.5f, 1.8f); SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 0.5f, 1.8f);
if (isHeadshot) { if (isHeadshot) {
RegistryEntry<DamageType> bullet_damage = SERVER.getRegistryManager() RegistryEntry<DamageType> bullet_damage = server.getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE) .get(RegistryKeys.DAMAGE_TYPE)
.getEntry(BULLET_DAMAGE) .getEntry(BULLET_DAMAGE)
.orElseThrow(() -> new IllegalStateException("Bullet DamageType not registered!")); .orElseThrow(() -> new IllegalStateException("Bullet DamageType not registered!"));
@@ -643,13 +642,6 @@ public class Szar implements ModInitializer {
} }
} }
}); });
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
SERVER = server;
});
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
SERVER = null;
});
// register block // register block
Registry.register( Registry.register(
Registries.BLOCK, Registries.BLOCK,
@@ -2313,8 +2305,8 @@ public class Szar implements ModInitializer {
return Text.literal(filtered); return Text.literal(filtered);
} }
public static void playPlaneAnimation(PlaneAnimation animation, int entityId) { public static void playPlaneAnimation(PlaneAnimation animation, int entityId, MinecraftServer server) {
for (ServerWorld world : SERVER.getWorlds()) { for (ServerWorld world : server.getWorlds()) {
for (ServerPlayerEntity player : world.getPlayers()) { for (ServerPlayerEntity player : world.getPlayers()) {
PacketByteBuf buf = PacketByteBufs.create(); PacketByteBuf buf = PacketByteBufs.create();
buf.writeInt(entityId); // <-- important change buf.writeInt(entityId); // <-- important change

View File

@@ -17,16 +17,13 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static dev.tggamesyt.szar.Szar.RADIATION_DAMAGE;
import static dev.tggamesyt.szar.Szar.SERVER;
@Mixin(Item.class) @Mixin(Item.class)
public abstract class RadiatedItemMixin { public abstract class RadiatedItemMixin {
@Inject(method = "use", at = @At("RETURN")) @Inject(method = "use", at = @At("RETURN"))
private void onUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) { private void onUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
ItemStack stack = cir.getReturnValue().getValue(); ItemStack stack = cir.getReturnValue().getValue();
if (!world.isClient && stack.hasNbt() && stack.getNbt().getBoolean("Radiated")) { if (!world.isClient && stack.hasNbt() && stack.getNbt().getBoolean("Radiated")) {
RegistryEntry<DamageType> radiationEntry = Szar.SERVER.getRegistryManager() RegistryEntry<DamageType> radiationEntry = world.getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE) .get(RegistryKeys.DAMAGE_TYPE)
.getEntry(Szar.RADIATION_DAMAGE) .getEntry(Szar.RADIATION_DAMAGE)
.orElseThrow(); .orElseThrow();