*screaming louder*

This commit is contained in:
yrsegal@gmail.com 2022-04-25 19:53:55 -04:00
parent b7507d2a50
commit 1cabc187e9
3 changed files with 15 additions and 5 deletions

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.misc; package at.petrak.hexcasting.common.misc;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -11,8 +11,8 @@ import java.util.WeakHashMap;
public final class PlayerPositionRecorder { public final class PlayerPositionRecorder {
private static final Map<Player, Vec3> LAST_POSITION_MAP = new WeakHashMap<>(); private static final Map<Player, Vec3> LAST_POSITION_MAP = new WeakHashMap<>();
public static void updatePosition(LivingEntity e) { public static void updateAllPlayers(ServerLevel world) {
if (e instanceof ServerPlayer player) { for (ServerPlayer player : world.players()) {
LAST_POSITION_MAP.put(player, player.position()); LAST_POSITION_MAP.put(player, player.position());
} }
} }

View file

@ -9,11 +9,13 @@ import at.petrak.hexcasting.common.command.PatternResLocArgument
import at.petrak.hexcasting.common.entities.HexEntities import at.petrak.hexcasting.common.entities.HexEntities
import at.petrak.hexcasting.common.lib.* import at.petrak.hexcasting.common.lib.*
import at.petrak.hexcasting.common.misc.Brainsweeping import at.petrak.hexcasting.common.misc.Brainsweeping
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
import at.petrak.hexcasting.common.recipe.HexRecipeSerializers import at.petrak.hexcasting.common.recipe.HexRecipeSerializers
import at.petrak.hexcasting.fabric.event.VillagerConversionCallback import at.petrak.hexcasting.fabric.event.VillagerConversionCallback
import at.petrak.hexcasting.fabric.network.FabricPacketHandler import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import net.fabricmc.api.ModInitializer import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.fabricmc.fabric.api.event.player.UseEntityCallback import net.fabricmc.fabric.api.event.player.UseEntityCallback
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry import net.fabricmc.fabric.api.registry.FlammableBlockRegistry
import net.minecraft.commands.synchronization.ArgumentTypes import net.minecraft.commands.synchronization.ArgumentTypes
@ -46,6 +48,8 @@ object FabricHexInitializer : ModInitializer {
UseEntityCallback.EVENT.register(Brainsweeping::tradeWithVillager) UseEntityCallback.EVENT.register(Brainsweeping::tradeWithVillager)
VillagerConversionCallback.EVENT.register(Brainsweeping::copyBrainsweepFromVillager) VillagerConversionCallback.EVENT.register(Brainsweeping::copyBrainsweepFromVillager)
ServerTickEvents.END_WORLD_TICK.register(PlayerPositionRecorder::updateAllPlayers)
CommandRegistrationCallback.EVENT.register { dp, _ -> HexCommands.register(dp) } CommandRegistrationCallback.EVENT.register { dp, _ -> HexCommands.register(dp) }
} }
@ -110,4 +114,4 @@ object FabricHexInitializer : ModInitializer {
private fun <T> bind(registry: Registry<in T>): BiConsumer<T, ResourceLocation> = private fun <T> bind(registry: Registry<in T>): BiConsumer<T, ResourceLocation> =
BiConsumer<T, ResourceLocation> { t, id -> Registry.register(registry, id, t) } BiConsumer<T, ResourceLocation> { t, id -> Registry.register(registry, id, t) }
} }

View file

@ -25,6 +25,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.commands.synchronization.ArgumentTypes; import net.minecraft.commands.synchronization.ArgumentTypes;
import net.minecraft.commands.synchronization.EmptyArgumentSerializer; import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.Mob;
@ -36,6 +37,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolActions; import net.minecraftforge.common.ToolActions;
import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingConversionEvent; import net.minecraftforge.event.entity.living.LivingConversionEvent;
import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent;
@ -147,7 +149,11 @@ public class ForgeHexInitializer {
evBus.addListener((LivingEvent.LivingUpdateEvent evt) -> { evBus.addListener((LivingEvent.LivingUpdateEvent evt) -> {
OpFlight.INSTANCE.tickDownFlight(evt.getEntityLiving()); OpFlight.INSTANCE.tickDownFlight(evt.getEntityLiving());
PlayerPositionRecorder.updatePosition(evt.getEntityLiving()); });
evBus.addListener((TickEvent.WorldTickEvent evt) -> {
if (evt.phase == TickEvent.Phase.END && evt.world instanceof ServerLevel world)
PlayerPositionRecorder.updateAllPlayers(world);
}); });
evBus.addListener((RegisterCommandsEvent evt) -> HexCommands.register(evt.getDispatcher())); evBus.addListener((RegisterCommandsEvent evt) -> HexCommands.register(evt.getDispatcher()));