fixed the mod not working on servers

closes #346
This commit is contained in:
Ell 2024-03-29 13:17:40 +01:00
parent 16582e6d25
commit 3ae1246ec6
2 changed files with 20 additions and 16 deletions

View file

@ -42,22 +42,26 @@ public class PacketClient implements CustomPacketPayload {
return PacketClient.ID;
}
@SuppressWarnings("Convert2Lambda")
public static void onMessage(PacketClient message, PlayPayloadContext ctx) {
ctx.workHandler().execute(() -> {
var mc = Minecraft.getInstance();
if (mc.level != null) {
switch (message.type) {
case 0: // dimension rail visualization
var goalDim = new ResourceLocation(message.data.getString("dim"));
var goalPos = BlockPos.of(message.data.getLong("pos"));
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
case 1:
var entity = mc.level.getEntity(message.data.getInt("id"));
mc.particleEngine.createTrackingEmitter(entity, ParticleTypes.TOTEM_OF_UNDYING, 30);
mc.level.playLocalSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.TOTEM_USE, entity.getSoundSource(), 1.0F, 1.0F, false);
if (entity == mc.player) {
mc.gameRenderer.displayItemActivation(new ItemStack(ModItems.DEATH_RING));
}
ctx.workHandler().execute(new Runnable() {
@Override
public void run() {
var mc = Minecraft.getInstance();
if (mc.level != null) {
switch (message.type) {
case 0: // dimension rail visualization
var goalDim = new ResourceLocation(message.data.getString("dim"));
var goalPos = BlockPos.of(message.data.getLong("pos"));
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
case 1:
var entity = mc.level.getEntity(message.data.getInt("id"));
mc.particleEngine.createTrackingEmitter(entity, ParticleTypes.TOTEM_OF_UNDYING, 30);
mc.level.playLocalSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.TOTEM_USE, entity.getSoundSource(), 1.0F, 1.0F, false);
if (entity == mc.player) {
mc.gameRenderer.displayItemActivation(new ItemStack(ModItems.DEATH_RING));
}
}
}
}
});

View file

@ -67,7 +67,7 @@ public class PacketParticles implements CustomPacketPayload {
public static void onMessage(PacketParticles message, PlayPayloadContext ctx) {
ctx.workHandler().execute(() -> {
Level level = Minecraft.getInstance().level;
var level = ctx.level().orElseThrow();
if (level != null)
message.type.action.accept(message, level);
});