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);
}
}
}
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;
}
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;
}
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);
});
}
}
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);
}
Aggregations