Java Code Examples for net.minecraft.entity.item.EntityEnderCrystal#setBeamTarget()

The following examples show how to use net.minecraft.entity.item.EntityEnderCrystal#setBeamTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaTileEntityMagicEnergyAbsorber.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateConnectedCrystals() {
    this.connectedCrystalsIds.clear();
    final double maxDistance = 64 * 64;
    List<EntityEnderCrystal> enderCrystals = Arrays.stream(BiomeEndDecorator.getSpikesForWorld(getWorld()))
        .flatMap(endSpike -> getWorld().getEntitiesWithinAABB(EntityEnderCrystal.class, endSpike.getTopBoundingBox()).stream())
        .filter(crystal -> crystal.getDistanceSq(getPos()) < maxDistance)
        .collect(Collectors.toList());

    for (EntityEnderCrystal entityEnderCrystal : enderCrystals) {
        BlockPos beamTarget = entityEnderCrystal.getBeamTarget();
        if (beamTarget == null) {
            //if beam target is null, set ourselves as beam target
            entityEnderCrystal.setBeamTarget(getPos());
            this.connectedCrystalsIds.add(entityEnderCrystal.getEntityId());
        } else if (beamTarget.equals(getPos())) {
            //if beam target is ourselves, just add it to list
            this.connectedCrystalsIds.add(entityEnderCrystal.getEntityId());
        }
    }

    for (EntityDragon entityDragon : getWorld().getEntities(EntityDragon.class, EntitySelectors.IS_ALIVE)) {
        if (entityDragon.healingEnderCrystal != null && connectedCrystalsIds.contains(entityDragon.healingEnderCrystal.getEntityId())) {
            //if dragon is healing from crystal we draw energy from, reset it's healing crystal
            entityDragon.healingEnderCrystal = null;
            //if dragon is holding pattern, than deal damage and set it's phase to attack ourselves
            if (entityDragon.getPhaseManager().getCurrentPhase().getType() == PhaseList.HOLDING_PATTERN) {
                entityDragon.attackEntityFrom(DamageSource.causeExplosionDamage((EntityLivingBase) null), 10.0f);
                entityDragon.getPhaseManager().setPhase(PhaseList.CHARGING_PLAYER);
                ((PhaseChargingPlayer) entityDragon.getPhaseManager().getCurrentPhase()).setTarget(new Vec3d(getPos()));
            }
        }
    }
}
 
Example 2
Source File: MetaTileEntityMagicEnergyAbsorber.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void resetConnectedEnderCrystals() {
    for (int connectedEnderCrystal : connectedCrystalsIds.toArray()) {
        EntityEnderCrystal entityEnderCrystal = (EntityEnderCrystal) getWorld().getEntityByID(connectedEnderCrystal);
        if (entityEnderCrystal != null && getPos().equals(entityEnderCrystal.getBeamTarget())) {
            //on removal, reset ender crystal beam location so somebody can use it
            entityEnderCrystal.setBeamTarget(null);
        }
    }
    connectedCrystalsIds.clear();
}