package com.thebrokenrail.reliccraft.mixin; import com.thebrokenrail.reliccraft.RelicCraft; import com.thebrokenrail.reliccraft.entity.RelicEntity; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @SuppressWarnings("unused") @Environment(EnvType.CLIENT) @Mixin(ClientPlayNetworkHandler.class) public class MixinClientPlayNetworkHandler { @Shadow private ClientWorld world; @Inject(method = "onEntitySpawn", at = @At(value = "TAIL")) public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo info) { EntityType entityType = packet.getEntityTypeId(); Entity entity = null; if (entityType == RelicCraft.RELIC_ENTITY) { entity = new RelicEntity(world, packet.getX(), packet.getY(), packet.getZ()); } if (entity != null) { double x = packet.getX(); double y = packet.getY(); double z = packet.getZ(); entity.updateTrackedPosition(x, y, z); entity.pitch = (float) (packet.getPitch() * 360) / 250F; entity.yaw = (float) (packet.getYaw() * 360) / 250F; entity.setEntityId(packet.getId()); entity.setUuid(packet.getUuid()); world.addEntity(packet.getId(), entity); } } }