@Override public boolean onProject(IProjector projector, Set<Vector3> fieldBlocks) { Set<IBlockFrequency> machines = FrequencyGrid.instance().get(((IFortronFrequency) projector).getFrequency()); for (IBlockFrequency compareProjector : machines) { if (compareProjector instanceof IProjector && compareProjector != projector) { if (((TileEntity) compareProjector).worldObj == ((TileEntity) projector).worldObj) { if (((TileMFFS) compareProjector).isActive() && ((IProjector) compareProjector).getMode() != null) { Iterator<Vector3> it = fieldBlocks.iterator(); while (it.hasNext()) { Vector3 position = it.next(); if (((IProjector) compareProjector) .getMode() .isInField((IProjector) compareProjector, position.clone())) { it.remove(); } } } } } } return false; }
@Override public boolean isInField(IFieldInteraction projector, Vector3 position) { Vector3 posScale = projector.getPositiveScale().clone(); Vector3 negScale = projector.getNegativeScale().clone(); int xStretch = posScale.intX() + negScale.intX(); int yStretch = posScale.intY() + negScale.intY(); int zStretch = posScale.intZ() + negScale.intZ(); Vector3 projectorPos = new Vector3((TileEntity) projector); projectorPos.add(projector.getTranslation()); projectorPos.add(new Vector3(0, -negScale.intY() + 1, 0)); Vector3 relativePosition = position.clone().subtract(projectorPos); relativePosition.rotate(-projector.getRotationYaw(), -projector.getRotationPitch()); Cuboid region = new Cuboid(negScale.scale(-1), posScale); if (region.isIn(relativePosition) && relativePosition.y > 0) { if ((1 - (Math.abs(relativePosition.x) / xStretch) - (Math.abs(relativePosition.z) / zStretch) > relativePosition.y / yStretch)) { return true; } } return false; }
@Override public void update() { if (ticks % 60 == 0) { updateBounds(); } super.update(); pushDelay = Math.max(0, pushDelay - 1); /** Try to use temp link vectors from save/loads to link. */ if (saveLinkVector != null) { tryLink(saveLinkVector, saveLinkSide); saveLinkVector = null; } if (canFunction()) { IInventory inventory = (IInventory) getLatched(); /** Place items or take items from the inventory into the world. */ if (!input) { renderRotation = Math.min(20, renderRotation + 0.8f); /** Attempt to push items out. */ if (pushDelay == 0) { ItemStack retrieved = InventoryUtility.takeTopItemFromInventory( inventory, placementSide.getOpposite().getOpposite().ordinal()); if (retrieved != null) { EntityItem entityItem = getItemWithPosition(retrieved); if (!world().isRemote) { world().spawnEntityInWorld(entityItem); } pushDelay = Settings.LEVITATOR_PUSH_DELAY; } } } else if (input) { renderRotation = Math.max(0, renderRotation - 0.8f); } final int renderPeriod = 1; final boolean renderBeam = ticks % renderPeriod == 0 && hasLink() && getLink().input != input; if (!input) { if (hasLink()) { if (getLink().input) { /** Linked usage. */ if (thread != null) { PathfinderLevitator newPath = thread.getPath(); if (newPath != null) { pathfinder = newPath; pathfinder.results.add(getPosition()); thread = null; } } // Push entity along path. if (pathfinder != null) { List<Vector3> results = pathfinder.results; /** Draw default beams. */ if (renderBeam) { Electrical.proxy.renderElectricShock( world(), getBeamSpawnPosition(), getPosition().translate(0.5), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9); Electrical.proxy.renderElectricShock( world(), getLink().getPosition().translate(0.5), getLink().getBeamSpawnPosition(), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9); } for (int i = 0; i < results.size(); i++) { Vector3 result = results.get(i).clone(); if (canBeMovePath(world(), result)) { if (i - 1 >= 0) { Vector3 prevResult = results.get(i - 1).clone(); Vector3 difference = prevResult.clone().difference(result); final ForgeDirection direction = difference.toForgeDirection(); if (renderBeam) { Electrical.proxy.renderElectricShock( world(), prevResult.clone().translate(0.5), result.clone().translate(0.5), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9); } AxisAlignedBB bounds = AxisAlignedBB.getAABBPool() .getAABB( result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1); List<EntityItem> entities = world().getEntitiesWithinAABB(EntityItem.class, bounds); for (EntityItem entityItem : entities) { moveEntity(entityItem, direction, result); } } } else { updatePath(); break; } } } else { updatePath(); } } } else if (operationBounds != null) { /** Non-linked usage. */ for (EntityItem entityItem : (List<EntityItem>) world().getEntitiesWithinAABB(EntityItem.class, operationBounds)) { moveEntity(entityItem, placementSide.getOpposite(), getPosition()); } if (ticks % renderPeriod == 0) { Electrical.proxy.renderElectricShock( world(), getBeamSpawnPosition(), new Vector3( operationBounds.maxX - 0.5 - placementSide.offsetX / 3f, operationBounds.maxY - 0.5 - placementSide.offsetY / 3f, operationBounds.maxZ - 0.5 - placementSide.offsetZ / 3f), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9); } } } lastCalcTime--; } }