Search in sources :

Example 16 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onPlayerTickEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerTickEvent(PlayerTickEvent event) {
    if (!event.player.worldObj.isRemote && event.player != null) {
        EntityPlayerMP p = (EntityPlayerMP) event.player;
        try {
            if (!(p.connection instanceof CustomNetHandlerPlayServer)) {
                p.connection = new CustomNetHandlerPlayServer(p.connection);
            } else {
                CustomNetHandlerPlayServer customNetHandler = (CustomNetHandlerPlayServer) p.connection;
                if (p.interactionManager.getBlockReachDistance() == CustomNetHandlerPlayServer.dummyBlockReachDist && customNetHandler.ticksSinceLastTry == 2) {
                    p.interactionManager.setBlockReachDistance(((CustomNetHandlerPlayServer) p.connection).lastGoodBlockReachDist);
                }
                customNetHandler.ticksSinceLastTry++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Double[] pos = lastPositions.get(p);
        if (pos == null) {
            pos = new Double[3];
            lastPositions.put(p, pos);
        }
        try {
            if (pos[0] != p.posX || pos[2] != p.posZ) {
                // Player has moved
                if (Math.abs(p.posX) > 27000000 || Math.abs(p.posZ) > 27000000) {
                    // Player is outside of world border, tp them back
                    p.attemptTeleport(pos[0], pos[1], pos[2]);
                    p.addChatMessage(new TextComponentString("You can't go beyond 27000000 blocks because airships are stored there!"));
                }
            }
        } catch (NullPointerException e) {
            ValkyrienWarfareMod.VWLogger.log(Level.WARNING, "Nullpointer EventsCommon.java:onPlayerTickEvent");
        }
        pos[0] = p.posX;
        pos[1] = p.posY;
        pos[2] = p.posZ;
    }
}
Also used : CustomNetHandlerPlayServer(ValkyrienWarfareBase.Interaction.CustomNetHandlerPlayServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 17 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project Witchworks by Um-Mitternacht.

the class BrewEvents method onWorldJoin.

@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
        if (optional.isPresent()) {
            PacketHandler.sendTo(entity, new PotionMessage(optional.get().getBrews().keySet(), entity.getUniqueID()));
        }
    }
}
Also used : IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PotionMessage(com.witchworks.common.core.net.PotionMessage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project Witchworks by Um-Mitternacht.

the class EnergyEvents method onWorldJoin.

@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
        Optional<IEnergy> optional = EnergyHandler.getEnergy(entity);
        if (optional.isPresent()) {
            PacketHandler.sendTo(entity, new EnergyMessage(optional.get(), entity.getUniqueID()));
        }
    }
}
Also used : EnergyMessage(com.witchworks.common.core.net.EnergyMessage) IEnergy(com.witchworks.common.core.capability.energy.IEnergy) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 19 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method getPlayersThatJustWatched.

private Set getPlayersThatJustWatched() {
    HashSet newPlayers = new HashSet();
    for (Object o : ((WorldServer) worldObj).getEntityTracker().getTrackingPlayers(wrapper)) {
        EntityPlayerMP player = (EntityPlayerMP) o;
        if (!watchingPlayers.contains(player)) {
            newPlayers.add(player);
            watchingPlayers.add(player);
        }
    }
    return newPlayers;
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) HashSet(java.util.HashSet)

Example 20 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method destroy.

public void destroy() {
    wrapper.setDead();
    ArrayList<EntityPlayerMP> watchersCopy = (ArrayList<EntityPlayerMP>) watchingPlayers.clone();
    for (EntityPlayerMP wachingPlayer : watchersCopy) {
        for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
            for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
                SPacketUnloadChunk unloadPacket = new SPacketUnloadChunk(x, z);
                ((EntityPlayerMP) wachingPlayer).connection.sendPacket(unloadPacket);
            }
        }
    // NOTICE: This method isnt being called to avoid the watchingPlayers.remove(player) call, which is a waste of CPU time
    // onPlayerUntracking(wachingPlayer);
    }
    watchingPlayers.clear();
    ValkyrienWarfareMod.chunkManager.removeRegistedChunksForShip(wrapper);
    ValkyrienWarfareMod.chunkManager.removeShipPosition(wrapper);
    ValkyrienWarfareMod.chunkManager.removeShipNameRegistry(wrapper);
    ValkyrienWarfareMod.physicsManager.onShipUnload(wrapper);
}
Also used : SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) ArrayList(java.util.ArrayList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)163 EntityPlayer (net.minecraft.entity.player.EntityPlayer)32 ItemStack (net.minecraft.item.ItemStack)23 TileEntity (net.minecraft.tileentity.TileEntity)18 Entity (net.minecraft.entity.Entity)17 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)14 BlockPos (net.minecraft.util.math.BlockPos)14 Block (net.minecraft.block.Block)11 IBlockState (net.minecraft.block.state.IBlockState)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 World (net.minecraft.world.World)8 WrongUsageException (net.minecraft.command.WrongUsageException)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5