Search in sources :

Example 36 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretBaseContainer method detectAndSendChanges.

@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    DebugHandler.getInstance().setListeners(this.listeners);
    for (IContainerListener listener : this.listeners) {
        if (listener instanceof EntityPlayerMP) {
            NetworkingHandler.INSTANCE.sendTo(new MessageTurretBase(this.tileEntity), (EntityPlayerMP) listener);
        }
    }
}
Also used : IContainerListener(net.minecraft.inventory.IContainerListener) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MessageTurretBase(omtteam.openmodularturrets.network.messages.MessageTurretBase)

Example 37 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project OpenModularTurrets by OpenModularTurretsTeam.

the class RelativisticTurretTileEntity method update.

@SuppressWarnings("ConstantConditions")
@Override
public void update() {
    setSide();
    this.base = getBaseFromWorld();
    if (this.getWorld().isRemote) {
        if (rotationAnimation >= 360F) {
            rotationAnimation = 0F;
        }
        rotationAnimation = rotationAnimation + 0.03F;
        return;
    }
    ticks++;
    // BASE IS OKAY
    if (base == null || base.getTier() < this.turretTier) {
        this.getWorld().destroyBlock(this.pos, true);
    } else {
        concealmentChecks();
        TurretHeadUtil.updateSolarPanelAddon(base);
        //turret tick rate;
        if (target == null && targetingTicks < ConfigHandler.getTurretTargetSearchTicks()) {
            targetingTicks++;
            return;
        }
        targetingTicks = 0;
        int power_required = Math.round(this.getTurretPowerUsage() * (1 - TurretHeadUtil.getEfficiencyUpgrades(base)) * (1 + TurretHeadUtil.getScattershotUpgrades(base)));
        // power check
        if ((base.getEnergyLevel(EnumFacing.DOWN) < power_required) || (!base.isActive())) {
            return;
        }
        // is there a target, and Has it died in the previous tick?
        if (target == null || target.isDead || this.getWorld().getEntityByID(target.getEntityId()) == null || ((EntityLivingBase) target).getHealth() <= 0.0F) {
            target = getTargetWithoutEffect();
        }
        // did we even get a target previously?
        if (target == null) {
            return;
        }
        this.rotationXZ = TurretHeadUtil.getAimYaw(target, this.pos) + 3.2F;
        this.rotationXY = TurretHeadUtil.getAimPitch(target, this.pos);
        // has cooldown passed?
        if (ticks < (this.getTurretFireRate() * (1 - TurretHeadUtil.getFireRateUpgrades(base)))) {
            return;
        }
        // Can the turret still see the target? (It's moving)
        if (target != null) {
            if (!TurretHeadUtil.canTurretSeeTarget(this, (EntityLivingBase) target)) {
                target = null;
                return;
            }
        }
        if (target != null && target instanceof EntityPlayerMP) {
            EntityPlayerMP entity = (EntityPlayerMP) target;
            if (isPlayerTrusted(entity, base)) {
                target = null;
                return;
            }
        }
        if (target != null) {
            if (chebyshevDistance(target, base)) {
                target = null;
                return;
            }
        }
        // Consume energy
        base.setEnergyStored(base.getEnergyLevel(EnumFacing.DOWN) - power_required);
        ((EntityLivingBase) target).addPotionEffect(new PotionEffect(Potion.getPotionById(2), 200, 5, false, false));
        ((EntityLivingBase) target).addPotionEffect(new PotionEffect(Potion.getPotionById(18), 200, 5, false, false));
        target = null;
    }
    this.getWorld().playSound(null, this.getPos(), this.getLaunchSoundEffect(), SoundCategory.BLOCKS, 0.6F, 1.0F);
    ticks = 0;
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 38 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getTarget.

@SuppressWarnings("ConstantConditions")
public static Entity getTarget(TurretBase base, World worldObj, BlockPos pos, int turretRange, TurretHead turret) {
    Entity target = null;
    if (!worldObj.isRemote && base != null && base.getOwner() != null) {
        AxisAlignedBB axis = new AxisAlignedBB(pos.getX() - turretRange - 1, pos.getY() - turretRange - 1, pos.getZ() - turretRange - 1, pos.getX() + turretRange + 1, pos.getY() + turretRange + 1, pos.getZ() + turretRange + 1);
        List<EntityLivingBase> targets = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis);
        for (EntityLivingBase target1 : targets) {
            if (target1 != null && EntityList.getEntityString(target1) != null) {
                if (ConfigHandler.validMobBlacklist.contains(EntityList.getEntityString(target1)))
                    continue;
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAnimal && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAmbientCreature && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksMobs() && ConfigHandler.globalCanTargetMobs) {
                if (target1.isCreatureType(EnumCreatureType.MONSTER, false) && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksPlayers() && ConfigHandler.globalCanTargetPlayers) {
                if (target1 instanceof EntityPlayerMP && !target1.isDead) {
                    EntityPlayerMP entity = (EntityPlayerMP) target1;
                    if (!isPlayerOwner(entity, base) && !isPlayerTrusted(entity, base) && !entity.capabilities.isCreativeMode) {
                        target = target1;
                    }
                }
            }
            if (target != null && turret != null) {
                if (base.isMultiTargeting() && isTargetAlreadyTargeted(base, target)) {
                    continue;
                }
                EntityLivingBase targetELB = (EntityLivingBase) target;
                if (canTurretSeeTarget(turret, targetELB) && targetELB.getHealth() > 0.0F) {
                    return target;
                }
            }
        }
    }
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityAmbientCreature(net.minecraft.entity.passive.EntityAmbientCreature)

Example 39 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project minecolonies by Minecolonies.

the class Colony method sendPermissionsPackets.

/**
     * Sends packages to update the permissions.
     *
     * @param oldSubscribers    the existing subscribers.
     * @param hasNewSubscribers the new subscribers.
     */
private void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
    if (permissions.isDirty() || hasNewSubscribers) {
        subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
            final Rank rank = getPermissions().getRank(player);
            MineColonies.getNetwork().sendTo(new PermissionsMessage.View(this, rank), player);
        });
    }
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AchievementUtils(com.minecolonies.coremod.util.AchievementUtils) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) Achievement(net.minecraft.stats.Achievement) com.minecolonies.coremod.network.messages(com.minecolonies.coremod.network.messages) NBTTagString(net.minecraft.nbt.NBTTagString) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Rank(com.minecolonies.api.colony.permissions.Rank) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) NBTTagList(net.minecraft.nbt.NBTTagList) ModAchievements(com.minecolonies.coremod.achievements.ModAchievements) Block(net.minecraft.block.Block) ServerUtils(com.minecolonies.coremod.util.ServerUtils) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) com.minecolonies.api.util(com.minecolonies.api.util) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StatList(net.minecraft.stats.StatList) World(net.minecraft.world.World) StatBase(net.minecraft.stats.StatBase) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Collectors(java.util.stream.Collectors) com.minecolonies.coremod.colony.buildings(com.minecolonies.coremod.colony.buildings) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) ColonyPermissionEventHandler(com.minecolonies.coremod.permissions.ColonyPermissionEventHandler) NBT(net.minecraftforge.common.util.Constants.NBT) MineColonies(com.minecolonies.coremod.MineColonies) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NBTUtil(net.minecraft.nbt.NBTUtil) Configurations(com.minecolonies.api.configuration.Configurations) Rank(com.minecolonies.api.colony.permissions.Rank)

Example 40 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project minecolonies by Minecolonies.

the class Colony method updateSubscribers.

/**
     * Update Subscribers with Colony, Citizen, and AbstractBuilding Views.
     */
private void updateSubscribers() {
    // If the world or server is null, don't try to update the subscribers this tick.
    if (world == null || world.getMinecraftServer() == null) {
        return;
    }
    //  Recompute subscribers every frame (for now)
    //  Subscribers = Owners + Players within (double working town hall range)
    @NotNull final Set<EntityPlayerMP> oldSubscribers = subscribers;
    subscribers = new HashSet<>();
    // Add owners
    world.getMinecraftServer().getPlayerList().getPlayers().stream().filter(permissions::isSubscriber).forEachOrdered(subscribers::add);
    if (subscribers.isEmpty()) {
        if (ticksPassed >= TICKS_HOUR) {
            ticksPassed = 0;
            lastContactInHours++;
        }
        ticksPassed++;
    } else {
        ticksPassed = 0;
    }
    //  Add nearby players
    for (final EntityPlayer o : world.playerEntities) {
        if (o instanceof EntityPlayerMP) {
            @NotNull final EntityPlayerMP player = (EntityPlayerMP) o;
            final double distance = player.getDistanceSq(center);
            if (distance < MAX_SQ_DIST_SUBSCRIBER_UPDATE || (oldSubscribers.contains(player) && distance < MAX_SQ_DIST_OLD_SUBSCRIBER_UPDATE)) {
                // Players become subscribers if they come within 16 blocks of the edge of the colony
                // Players remain subscribers while they remain within double the colony's radius
                subscribers.add(player);
            }
        }
    }
    if (!subscribers.isEmpty()) {
        //  Determine if any new subscribers were added this pass
        final boolean hasNewSubscribers = ColonyUtils.hasNewSubscribers(oldSubscribers, subscribers);
        //  Send each type of update packet as appropriate:
        //      - To Subscribers if the data changes
        //      - To New Subscribers even if it hasn't changed
        //ColonyView
        sendColonyViewPackets(oldSubscribers, hasNewSubscribers);
        //Permissions
        sendPermissionsPackets(oldSubscribers, hasNewSubscribers);
        //WorkOrders
        sendWorkOrderPackets(oldSubscribers, hasNewSubscribers);
        //Citizens
        sendCitizenPackets(oldSubscribers, hasNewSubscribers);
        //Buildings
        sendBuildingPackets(oldSubscribers, hasNewSubscribers);
        //Fields
        if (!isBuildingsDirty) {
            sendFieldPackets(hasNewSubscribers);
        }
        //schematics
        if (Structures.isDirty()) {
            sendSchematicsPackets(hasNewSubscribers);
            Structures.clearDirty();
        }
    }
    isFieldsDirty = false;
    isDirty = false;
    isCitizensDirty = false;
    isBuildingsDirty = false;
    permissions.clearDirty();
    buildings.values().forEach(AbstractBuilding::clearDirty);
    citizens.values().forEach(CitizenData::clearDirty);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NotNull(org.jetbrains.annotations.NotNull)

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