Search in sources :

Example 1 with PlayerBuff

use of mcjty.rftools.PlayerBuff in project RFTools by McJty.

the class PotionEffectModule method processEntities.

private void processEntities(World world, BlockPos pos, int radius, int miny, int maxy, EnvironmentalControllerTileEntity controllerTileEntity) {
    double maxsqdist = radius * radius;
    List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos.getX() - radius, pos.getY() - radius, pos.getZ() - radius, pos.getX() + radius, pos.getY() + radius, pos.getZ() + radius));
    for (EntityLivingBase entity : entities) {
        double py = entity.posY;
        if (py >= miny && py <= maxy) {
            double px = entity.posX;
            double pz = entity.posZ;
            double sqdist = (px - pos.getX()) * (px - pos.getX()) + (pz - pos.getZ()) * (pz - pos.getZ());
            if (sqdist < maxsqdist) {
                if (controllerTileEntity.isEntityAffected(entity)) {
                    if (!(entity instanceof EntityPlayer) || allowedForPlayers()) {
                        entity.addPotionEffect(new PotionEffect(potion, MAXTICKS * 3, amplifier, true, false));
                        PlayerBuff buff = getBuff();
                        if (buff != null) {
                            if (entity instanceof EntityPlayer) {
                                BuffProperties.addBuffToPlayer((EntityPlayer) entity, buff, MAXTICKS);
                            }
                        }
                    }
                } else if (entity instanceof EntityPlayer) {
                    PlayerBuff buff = getBuff();
                    if (buff != null) {
                        BuffProperties.addBuffToPlayer((EntityPlayer) entity, buff, MAXTICKS);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PlayerBuff(mcjty.rftools.PlayerBuff) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with PlayerBuff

use of mcjty.rftools.PlayerBuff in project RFTools by McJty.

the class BuffProperties method saveNBTData.

public void saveNBTData(NBTTagCompound compound) {
    compound.setBoolean("onElevator", onElevator);
    compound.setInteger("buffTicks", buffTimeout);
    compound.setBoolean("allowFlying", allowFlying);
    compound.setBoolean("oldAllowFlying", oldAllowFlying);
    int[] buffArray = new int[buffs.size()];
    int[] timeoutArray = new int[buffs.size()];
    int idx = 0;
    for (Map.Entry<PlayerBuff, Integer> entry : buffs.entrySet()) {
        PlayerBuff buff = entry.getKey();
        buffArray[idx] = buff.ordinal();
        timeoutArray[idx] = entry.getValue();
        idx++;
    }
    compound.setIntArray("buffs", buffArray);
    compound.setIntArray("buffTimeouts", timeoutArray);
}
Also used : PlayerBuff(mcjty.rftools.PlayerBuff) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PlayerBuff

use of mcjty.rftools.PlayerBuff in project RFTools by McJty.

the class BuffProperties method performBuffs.

private void performBuffs(EntityPlayerMP player) {
    // Perform all buffs that we can perform here (not potion effects and also not
    // passive effects like feather falling.
    boolean enableFlight = false;
    if (onElevator) {
        enableFlight = true;
        player.capabilities.isFlying = true;
    } else {
        for (PlayerBuff buff : buffs.keySet()) {
            if (buff == PlayerBuff.BUFF_FLIGHT) {
                enableFlight = true;
                break;
            }
        }
    }
    boolean oldAllow = player.capabilities.allowFlying;
    if (enableFlight) {
        if (!allowFlying) {
            // We were not already allowing flying.
            oldAllowFlying = player.capabilities.allowFlying;
            allowFlying = true;
        }
        player.capabilities.allowFlying = true;
    } else {
        if (allowFlying) {
            // We were flying before.
            player.capabilities.allowFlying = oldAllowFlying;
            if (player.capabilities.isCreativeMode) {
                player.capabilities.allowFlying = true;
            }
            allowFlying = false;
        }
    }
    if (player.capabilities.allowFlying != oldAllow) {
        if (!player.capabilities.allowFlying) {
            player.capabilities.isFlying = false;
        }
    }
    player.sendPlayerAbilities();
}
Also used : PlayerBuff(mcjty.rftools.PlayerBuff)

Example 4 with PlayerBuff

use of mcjty.rftools.PlayerBuff in project RFTools by McJty.

the class PotionEffectModule method processPlayers.

private void processPlayers(World world, BlockPos pos, int radius, int miny, int maxy, EnvironmentalControllerTileEntity controllerTileEntity) {
    double maxsqdist = radius * radius;
    List<EntityPlayer> players = new ArrayList<>(world.playerEntities);
    for (EntityPlayer player : players) {
        double py = player.posY;
        if (py >= miny && py <= maxy) {
            double px = player.posX;
            double pz = player.posZ;
            double sqdist = (px - pos.getX()) * (px - pos.getX()) + (pz - pos.getZ()) * (pz - pos.getZ());
            if (sqdist < maxsqdist) {
                if (controllerTileEntity.isPlayerAffected(player)) {
                    player.addPotionEffect(new PotionEffect(potion, MAXTICKS * 3, amplifier, true, false));
                    PlayerBuff buff = getBuff();
                    if (buff != null) {
                        BuffProperties.addBuffToPlayer(player, buff, MAXTICKS);
                    }
                }
            }
        }
    }
}
Also used : PlayerBuff(mcjty.rftools.PlayerBuff) PotionEffect(net.minecraft.potion.PotionEffect) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

PlayerBuff (mcjty.rftools.PlayerBuff)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 PotionEffect (net.minecraft.potion.PotionEffect)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1