Search in sources :

Example 51 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project VoodooCraft by Mod-DevCafeTeam.

the class CapabilityHandler method onClonePlayer.

@SuppressWarnings("all")
@SubscribeEvent
public static void onClonePlayer(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    //Copy capability on player death to new player
    if (event.isWasDeath() && (event.getEntityPlayer() instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
        for (Capability<? extends ICapability> cap : VCCapabilities.getCapabilities()) {
            ICapability oldicap = event.getOriginal().getCapability(cap, null);
            ICapability icap = player.getCapability(cap, null);
            if (oldicap == null || icap == null)
                continue;
            icap.deserializeNBT(oldicap.serializeNBT());
            icap.dataChanged(player);
        }
    }
}
Also used : ICapability(mdc.voodoocraft.capability.ICapability) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 52 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project ConvenientAdditions by Necr0.

the class ExtendedExplosion method newExplosion.

public static Explosion newExplosion(ExtendedExplosion e) {
    if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(e.getWorld(), e))
        return e;
    e.doExplosionA();
    e.doExplosionB(false);
    if (!e.isSmoking) {
        e.clearAffectedBlockPositions();
    }
    for (EntityPlayer entityplayer : e.getWorld().playerEntities) {
        if (entityplayer instanceof EntityPlayerMP && entityplayer.getDistanceSq(e.explosionX, e.explosionY, e.explosionZ) < 4096.0D) {
            ModNetworking.INSTANCE.sendTo(new PacketExtendedExplosion(e.explosionX, e.explosionY, e.explosionZ, e.explosionSize, e.getAffectedBlockPositions(), (Vec3d) e.getPlayerKnockbackMap().get(entityplayer)), (EntityPlayerMP) entityplayer);
        }
    }
    return e;
}
Also used : PacketExtendedExplosion(convenientadditions.api.network.PacketExtendedExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Vec3d(net.minecraft.util.math.Vec3d)

Example 53 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project ImmersiveEngineering by BluSunrize.

the class EntitySkylineHook method onUpdate.

@Override
public void onUpdate() {
    EntityPlayer player = null;
    //		if(this.getControllingPassenger() instanceof EntityPlayer)
    //			player = ((EntityPlayer)this.getControllingPassenger());
    List<Entity> list = this.getPassengers();
    if (!list.isEmpty() && list.get(0) instanceof EntityPlayer)
        player = (EntityPlayer) list.get(0);
    if (this.ticksExisted == 1 && !worldObj.isRemote) {
        IELogger.debug("init tick at " + System.currentTimeMillis());
        if (player instanceof EntityPlayerMP)
            ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
    }
    super.onUpdate();
    //			return;
    if (subPoints != null && targetPoint < subPoints.length - 1) {
        double dist = subPoints[targetPoint].distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("dist: " + dist);
        if (dist <= 0) {
            this.posX = subPoints[targetPoint].xCoord;
            this.posY = subPoints[targetPoint].yCoord;
            this.posZ = subPoints[targetPoint].zCoord;
            targetPoint++;
            if (player instanceof EntityPlayerMP)
                ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
            IELogger.debug("next vertex: " + targetPoint);
            return;
        }
        float speed = 2f;
        if (player != null && player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
            speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
        Vec3d moveVec = SkylineHelper.getSubMovementVector(new Vec3d(posX, posY, posZ), subPoints[targetPoint], speed);
        //*speed;
        motionX = moveVec.xCoord;
        //*speed;
        motionY = moveVec.yCoord;
        //*speed;
        motionZ = moveVec.zCoord;
    }
    if (target != null && targetPoint == subPoints.length - 1) {
        TileEntity end = this.worldObj.getTileEntity(target);
        IImmersiveConnectable iicEnd = ApiUtils.toIIC(end, worldObj);
        if (iicEnd == null) {
            this.setDead();
            return;
        }
        Vec3d vEnd = new Vec3d(target.getX(), target.getY(), target.getZ());
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
        double gDist = vEnd.distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("distance to goal: " + gDist);
        if (gDist <= .3) {
            reachedTarget(end);
            return;
        } else if (gDist > 5) {
            setDead();
            return;
        }
    }
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
    for (this.rotationPitch = (float) (Math.atan2((double) f1, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) ;
    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) this.prevRotationPitch += 360.0F;
    while (this.rotationYaw - this.prevRotationYaw < -180.0F) this.prevRotationYaw -= 360.0F;
    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) this.prevRotationYaw += 360.0F;
    this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    if (this.isInWater()) {
        for (int j = 0; j < 4; ++j) {
            float f3 = 0.25F;
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double) f3, this.posY - this.motionY * (double) f3, this.posZ - this.motionZ * (double) f3, this.motionX, this.motionY, this.motionZ);
        }
    }
    if (player != null) {
        double dx = this.posX - this.prevPosX;
        double dy = this.posY - this.prevPosY;
        double dz = this.posZ - this.prevPosZ;
        int distTrvl = Math.round(MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz) * 100.0F);
        if (distTrvl > 0)
            player.addStat(IEAchievements.statDistanceSkyhook, distTrvl);
        if (!worldObj.isRemote && SkylineHelper.isInBlock(player, worldObj)) {
        //				setDead();
        //				player.setPosition(posX-3*dx, posY-3*dy+getMountedYOffset(),posZ-3*dz);
        }
    //TODO
    //			if(player instanceof EntityPlayerMP)
    //				if(((EntityPlayerMP)player).getStatFile().func_150870_b(IEAchievements.statDistanceSkyhook)>100000)
    //					player.triggerAchievement(IEAchievements.skyhookPro);
    }
    this.setPosition(this.posX, this.posY, this.posZ);
}
Also used : MessageSkyhookSync(blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync) TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Vec3d(net.minecraft.util.math.Vec3d)

Example 54 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project RecurrentComplex by Ivorforce.

the class CommandPaste method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "generate", "select");
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
    RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
    NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
    if (worldData == null)
        throw ServerTranslations.commandException("commands.strucPaste.noClipboard");
    WorldServer world = (WorldServer) sender.getEntityWorld();
    BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    String seed = parameters.get("seed").first().optional().orElse(null);
    boolean generate = parameters.has("generate");
    boolean select = parameters.has("select");
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldData;
    // TODO Generate with generation info?
    OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, generate).withSeed(seed).prepare(world), sender);
    if (select) {
        StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // Can never not place so don't handle
        //noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 55 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project RecurrentComplex by Ivorforce.

the class CommandExportStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
    String structureID = parameters.get().first().optional().orElse(null);
    GenericStructure genericStructureInfo = getNewGenericStructure(commandSender, parameters.rc("from"));
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    genericStructureInfo.worldDataCompound = IvWorldData.capture(commandSender.getEntityWorld(), selectionOwner.getSelection(), true).createTagCompound();
    PacketEditStructureHandler.openEditStructure(genericStructureInfo, structureID, player);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

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