fix: camera and outdated cache

This commit is contained in:
Octol1ttle 2024-05-06 23:23:32 +05:00
parent 8dd209899f
commit d70b2b5974
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
4 changed files with 23 additions and 18 deletions

View file

@ -117,7 +117,7 @@ public class KnockdownsClientEvents {
|| client.player.getEyePos().distanceTo(eyePosition) > 64.0
|| client.world
.raycast(new RaycastContext(
client.player.getEyePos(),
client.getEntityRenderDispatcher().camera.getPos(),
eyePosition,
RaycastContext.ShapeType.VISUAL,
RaycastContext.FluidHandling.SOURCE_ONLY,

View file

@ -4,6 +4,7 @@ import dev.architectury.networking.NetworkManager;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Vec3d;
import ru.octol1ttle.knockdowns.common.api.RemotePlayer;
@ -37,6 +38,13 @@ public class RemotePlayerS2CPacket extends KnockdownsPacket {
@Override
public void apply(Supplier<NetworkManager.PacketContext> contextSupplier) {
NetworkManager.PacketContext context = contextSupplier.get();
context.queue(() -> KnockdownsClientEvents.remotePlayers.put(targetUuid, Optional.of(new RemotePlayer(this.eyePosition, this.knockedDown))));
context.queue(() -> {
//noinspection DataFlowIssue
if (MinecraftClient.getInstance().player.getUuid().equals(targetUuid)) {
KnockdownsClientEvents.remotePlayers.clear();
} else {
KnockdownsClientEvents.remotePlayers.put(targetUuid, Optional.of(new RemotePlayer(this.eyePosition, this.knockedDown)));
}
});
}
}

View file

@ -1,8 +1,21 @@
package ru.octol1ttle.knockdowns.forge;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = "knockdowns", bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class KnockdownsClientForge {
@SubscribeEvent
public void onInitializeClient(FMLClientSetupEvent event) {
KnockdownsClient.init();
}
@SubscribeEvent
public static void onHudRender(RenderGuiEvent.Pre event) {
ru.octol1ttle.knockdowns.common.events.KnockdownsClientEvents.onHudRender(event.getGuiGraphics());
}

View file

@ -1,14 +1,9 @@
package ru.octol1ttle.knockdowns.forge;
import dev.architectury.platform.forge.EventBuses;
import net.minecraftforge.client.event.RenderGuiEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
@SuppressWarnings("unused")
@ -18,18 +13,7 @@ public class KnockdownsForge {
// Submit our event bus to let architectury register our content on the right time
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
EventBuses.registerModEventBus(KnockdownsCommon.MOD_ID, modEventBus);
modEventBus.addListener(this::onInitializeClient);
MinecraftForge.EVENT_BUS.register(this);
KnockdownsCommon.init();
}
public void onInitializeClient(FMLClientSetupEvent event) {
KnockdownsClient.init();
}
@SubscribeEvent
public void onHudRender(RenderGuiEvent.Pre event) {
KnockdownsClientForge.onHudRender(event);
}
}