package com.thebrokenrail.sorcerycraft.mixin; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.entity.SpellEntity; 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") @Mixin(ClientPlayNetworkHandler.class) public class MixinClientPlayNetworkHandler { @Shadow private ClientWorld world; @Inject(method = "onEntitySpawn", at = @At(value = "TAIL")) public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo callbackInfo) { EntityType entityType = packet.getEntityTypeId(); Entity entity = null; if (entityType == SorceryCraft.SPELL_ENTITY) { entity = new SpellEntity(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); } } }