Search in sources :

Example 71 with EntityPlayer

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

the class BrewEvents method onPlayerClone.

@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    final EntityPlayer oldPlayer = event.getOriginal();
    final EntityPlayer newPlayer = event.getEntityPlayer();
    if (event.isWasDeath() && oldPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null) && newPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null)) {
        final IBrewStorage oldCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
        final IBrewStorage newCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
        newCap.setBrews(oldCap.getBrews());
    }
}
Also used : IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 72 with EntityPlayer

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

the class EnergyEvents method onPlayerClone.

@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    final EntityPlayer oldPlayer = event.getOriginal();
    final EntityPlayer newPlayer = event.getEntityPlayer();
    if (event.isWasDeath() && oldPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null) && newPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null)) {
        final IEnergy oldCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
        final IEnergy newCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
        newCap.set(oldCap.get());
        newCap.setMax(oldCap.getMax());
        newCap.setRegen(oldCap.getRegen());
        newCap.setUses(oldCap.getUses());
    }
}
Also used : IEnergy(com.witchworks.common.core.capability.energy.IEnergy) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 73 with EntityPlayer

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

the class PhysicsObject method changeOwner.

/**
	 * Tries to change the owner of this PhysicsObject.
	 *
	 * @param newOwner
	 * @return
	 */
public EnumChangeOwnerResult changeOwner(EntityPlayer newOwner) {
    if (!ValkyrienWarfareMod.canChangeAirshipCounter(true, newOwner)) {
        return EnumChangeOwnerResult.ERROR_NEWOWNER_NOT_ENOUGH;
    }
    if (newOwner.entityUniqueID.toString().equals(creator)) {
        return EnumChangeOwnerResult.ALREADY_CLAIMED;
    }
    EntityPlayer player = null;
    try {
        player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(UUID.fromString(creator));
    } catch (NullPointerException e) {
        newOwner.addChatMessage(new TextComponentString("That airship doesn't have an owner, you get to have it :D"));
        newOwner.getCapability(ValkyrienWarfareMod.airshipCounter, null).onCreate();
        allowedUsers.clear();
        creator = newOwner.entityUniqueID.toString();
        return EnumChangeOwnerResult.SUCCESS;
    }
    if (player != null) {
        player.getCapability(ValkyrienWarfareMod.airshipCounter, null).onLose();
    } else {
        try {
            File f = new File(DimensionManager.getCurrentSaveRootDirectory(), "playerdata/" + creator + ".dat");
            NBTTagCompound tag = CompressedStreamTools.read(f);
            NBTTagCompound capsTag = tag.getCompoundTag("ForgeCaps");
            capsTag.setInteger("valkyrienwarfare:IAirshipCounter", capsTag.getInteger("valkyrienwarfare:IAirshipCounter") - 1);
            CompressedStreamTools.safeWrite(tag, f);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    newOwner.getCapability(ValkyrienWarfareMod.airshipCounter, null).onCreate();
    allowedUsers.clear();
    creator = newOwner.entityUniqueID.toString();
    return EnumChangeOwnerResult.SUCCESS;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) File(java.io.File) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 74 with EntityPlayer

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

the class PhysicsObject method onSetBlockState.

public void onSetBlockState(IBlockState oldState, IBlockState newState, BlockPos posAt) {
    //If the block here is not to be physicsed, just treat it like you'd treat AIR blocks.
    boolean oldStateOnBlackList = false, newStateOnBlackList = false;
    if (oldState != null && BlockPhysicsRegistration.blocksToNotPhysicise.contains(oldState.getBlock())) {
        oldState = Blocks.AIR.getDefaultState();
        oldStateOnBlackList = true;
    }
    if (newState != null && BlockPhysicsRegistration.blocksToNotPhysicise.contains(newState.getBlock())) {
        newState = Blocks.AIR.getDefaultState();
        newStateOnBlackList = true;
    }
    boolean isOldAir = oldState == null || oldState.getBlock().equals(Blocks.AIR);
    boolean isNewAir = newState == null || newState.getBlock().equals(Blocks.AIR);
    if (!ownedChunks.isChunkEnclosedInMaxSet(posAt.getX() >> 4, posAt.getZ() >> 4)) {
        return;
    }
    if (!ownedChunks.isChunkEnclosedInSet(posAt.getX() >> 4, posAt.getZ() >> 4)) {
        return;
    }
    blocksChanged = true;
    if (isNewAir) {
        blockPositions.remove(posAt);
        if (!worldObj.isRemote) {
            balloonManager.onBlockPositionRemoved(posAt);
        }
    }
    if ((isOldAir && !isNewAir)) {
        if (!worldObj.isRemote) {
            balloonManager.onBlockPositionAdded(posAt);
            blockPositions.add(posAt);
        } else {
            if (!blockPositions.contains(posAt)) {
                blockPositions.add(posAt);
            }
        }
        int chunkX = (posAt.getX() >> 4) - claimedChunks[0][0].xPosition;
        int chunkZ = (posAt.getZ() >> 4) - claimedChunks[0][0].zPosition;
        ownedChunks.chunkOccupiedInLocal[chunkX][chunkZ] = true;
    }
    if (blockPositions.isEmpty()) {
        try {
            if (!worldObj.isRemote) {
                if (creator != null) {
                    EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(UUID.fromString(creator));
                    if (player != null) {
                        player.getCapability(ValkyrienWarfareMod.airshipCounter, null).onLose();
                    } else {
                        try {
                            File f = new File(DimensionManager.getCurrentSaveRootDirectory(), "playerdata/" + creator + ".dat");
                            NBTTagCompound tag = CompressedStreamTools.read(f);
                            NBTTagCompound capsTag = tag.getCompoundTag("ForgeCaps");
                            capsTag.setInteger("valkyrienwarfare:IAirshipCounter", capsTag.getInteger("valkyrienwarfare:IAirshipCounter") - 1);
                            CompressedStreamTools.safeWrite(tag, f);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    ValkyrienWarfareMod.chunkManager.getManagerForWorld(worldObj).data.avalibleChunkKeys.add(ownedChunks.centerX);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        destroy();
    }
    if (!worldObj.isRemote) {
        if (physicsProcessor != null) {
            physicsProcessor.onSetBlockState(oldState, newState, posAt);
        }
    }
//		System.out.println(blockPositions.size() + ":" + wrapper.isDead);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 75 with EntityPlayer

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

the class EntityCollisionInjector method alterEntityMovement.

// Returns false if game should use default collision
public static boolean alterEntityMovement(Entity entity, double dx, double dy, double dz) {
    if (entity instanceof PhysicsWrapperEntity) {
        return true;
    }
    Vector velVec = new Vector(dx, dy, dz);
    double origDx = dx;
    double origDy = dy;
    double origDz = dz;
    boolean isLiving = entity instanceof EntityLivingBase;
    boolean isMoving = false;
    if (isLiving) {
        EntityLivingBase living = (EntityLivingBase) entity;
        isMoving = Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01;
    }
    Vec3d velocity = new Vec3d(dx, dy, dz);
    ArrayList<EntityPolygonCollider> fastCollisions = new ArrayList<EntityPolygonCollider>();
    EntityPolygon playerBeforeMove = new EntityPolygon(entity.getEntityBoundingBox(), entity);
    ArrayList<Polygon> colPolys = getCollidingPolygonsAndDoBlockCols(entity, velocity);
    PhysicsWrapperEntity worldBelow = null;
    EntityDraggable draggable = EntityDraggable.getDraggableFromEntity(entity);
    for (Polygon poly : colPolys) {
        if (poly instanceof ShipPolygon) {
            ShipPolygon shipPoly = (ShipPolygon) poly;
            EntityPolygonCollider fast = new EntityPolygonCollider(playerBeforeMove, shipPoly, shipPoly.normals, velVec);
            if (!fast.seperated) {
                fastCollisions.add(fast);
                worldBelow = shipPoly.shipFrom.wrapper;
            }
        }
    }
    //TODO: Make this more comprehensive
    draggable.worldBelowFeet = worldBelow;
    if (fastCollisions.isEmpty()) {
        return false;
    }
    int contX = 0;
    int contY = 0;
    int contZ = 0;
    Vector total = new Vector();
    for (EntityPolygonCollider col : fastCollisions) {
        Vector response = col.collisions[col.minDistanceIndex].getResponse();
        // TODO: Add more potential yResponses
        double stepSquared = entity.stepHeight * entity.stepHeight;
        boolean isStep = isLiving && entity.onGround;
        if (response.Y > 0 && BigBastardMath.canStandOnNormal(col.potentialSeperatingAxes[col.minDistanceIndex])) {
            response = new Vector(0, -col.collisions[col.minDistanceIndex].penetrationDistance / col.potentialSeperatingAxes[col.minDistanceIndex].Y, 0);
        }
        if (isStep) {
            EntityLivingBase living = (EntityLivingBase) entity;
            if (Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01) {
                for (int i = 3; i < 6; i++) {
                    Vector tempResponse = col.collisions[i].getResponse();
                    if (tempResponse.Y > 0 && BigBastardMath.canStandOnNormal(col.collisions[i].axis) && tempResponse.lengthSq() < stepSquared) {
                        response = tempResponse;
                    }
                }
            }
        }
        // total.add(response);
        if (Math.abs(response.X) > .01) {
            total.X += response.X;
            contX++;
        }
        if (Math.abs(response.Y) > .01) {
            total.Y += response.Y;
            contY++;
        }
        if (Math.abs(response.Z) > .01) {
            total.Z += response.Z;
            contZ++;
        }
    }
    if (contX != 0) {
        total.X /= contX;
    }
    if (contY != 0) {
        total.Y /= contY;
    }
    if (contZ != 0) {
        total.Z /= contZ;
    }
    dx += total.X;
    dy += total.Y;
    dz += total.Z;
    boolean alreadyOnGround = entity.onGround && (dy == origDy) && origDy < 0;
    Vector original = new Vector(origDx, origDy, origDz);
    Vector newMov = new Vector(dx - origDx, dy - origDy, dz - origDz);
    entity.isCollidedHorizontally = original.dot(newMov) < 0;
    entity.isCollidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround;
    entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
    if (entity instanceof EntityLivingBase) {
        EntityLivingBase base = (EntityLivingBase) entity;
        base.motionY = dy;
        if (base.isOnLadder()) {
            float f9 = 0.15F;
            base.motionX = MathHelper.clamp_double(base.motionX, -0.15000000596046448D, 0.15000000596046448D);
            base.motionZ = MathHelper.clamp_double(base.motionZ, -0.15000000596046448D, 0.15000000596046448D);
            base.fallDistance = 0.0F;
            if (base.motionY < -0.15D) {
                base.motionY = -0.15D;
            }
            boolean flag = base.isSneaking() && base instanceof EntityPlayer;
            if (flag && base.motionY < 0.0D) {
                base.motionY = 0.0D;
            }
        }
        entity.moveEntity(dx, base.motionY, dz);
    } else {
        entity.moveEntity(dx, dy, dz);
    }
    entity.isCollidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
    entity.isCollidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
    entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
    if (dx != origDx) {
        entity.motionX = dx;
    }
    if (dy != origDy) {
        if (!(entity.motionY > 0 && dy > 0)) {
            entity.motionY = 0;
        }
    }
    if (dz != origDz) {
        entity.motionZ = dz;
    }
    return true;
}
Also used : EntityDraggable(ValkyrienWarfareBase.Interaction.EntityDraggable) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector(ValkyrienWarfareBase.API.Vector)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)625 ItemStack (net.minecraft.item.ItemStack)169 EntityLivingBase (net.minecraft.entity.EntityLivingBase)104 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)81 Entity (net.minecraft.entity.Entity)77 World (net.minecraft.world.World)73 BlockPos (net.minecraft.util.math.BlockPos)61 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)49 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)44 TileEntity (net.minecraft.tileentity.TileEntity)43 PotionEffect (net.minecraft.potion.PotionEffect)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 EntityItem (net.minecraft.entity.item.EntityItem)37 Block (net.minecraft.block.Block)36 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)35 ArrayList (java.util.ArrayList)33 IBlockState (net.minecraft.block.state.IBlockState)33 List (java.util.List)28 TextComponentString (net.minecraft.util.text.TextComponentString)27 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)23