use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.
the class PneumaticTube method getTubeBoxes.
protected List<Vec3dCube> getTubeBoxes() {
List<Vec3dCube> aabbs = getOcclusionBoxes();
for (int i = 0; i < 6; i++) {
ForgeDirection d = ForgeDirection.getOrientation(i);
if (connections[i] || redstoneConnections[i] || getDeviceOnSide(d) != null) {
Vec3dCube c = sideBB.clone().rotate(d, Vec3d.center);
aabbs.add(c);
}
}
return aabbs;
}
use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.
the class PneumaticTube method updateConnections.
private void updateConnections() {
if (getWorld() != null && !getWorld().isRemote) {
int connectionCount = 0;
boolean clearedCache = false;
clearCache();
for (int i = 0; i < 6; i++) {
boolean oldState = connections[i];
ForgeDirection d = ForgeDirection.getOrientation(i);
TileEntity neighbor = getTileCache(d);
connections[i] = IOHelper.canInterfaceWith(neighbor, d.getOpposite(), this, canConnectToInventories());
if (!connections[i])
connections[i] = neighbor instanceof ITubeConnection && ((ITubeConnection) neighbor).isConnectedTo(d.getOpposite());
if (connections[i]) {
connections[i] = isConnected(d, null);
}
if (connections[i])
connectionCount++;
if (!clearedCache && oldState != connections[i]) {
if (Config.enableTubeCaching)
getLogic().clearNodeCaches();
clearedCache = true;
}
}
isCrossOver = connectionCount != 2;
sendUpdatePacket();
}
initialized = true;
}
use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.
the class PneumaticTube method onUpdate.
/**
* Event called whenever a nearby block updates
*/
@Override
public void onUpdate() {
if (getParent() != null && getWorld() != null) {
// Don't to anything if propagation-related stuff is going on
if (RedstoneApi.getInstance().shouldWiresHandleUpdates()) {
getRedstoneConnectionCache().recalculateConnections();
ForgeDirection d = ForgeDirection.UNKNOWN;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) if (getDeviceOnSide(dir) != null)
d = dir;
RedstoneApi.getInstance().getRedstonePropagator(this, d).propagate();
sendUpdatePacket();
}
// Cache and connection refresh
clearCache();
updateConnections();
}
}
use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.
the class TubeLogic method clearNodeCaches.
public void clearNodeCaches() {
List<PneumaticTube> clearedTubes = new ArrayList<PneumaticTube>();
Stack<PneumaticTube> todoTubes = new Stack<PneumaticTube>();
clearNodeCache();
boolean firstRun = true;
todoTubes.push(tube);
while (!todoTubes.isEmpty()) {
PneumaticTube tube = todoTubes.pop();
if (tube.getParent() != null && tube.getWorld() != null) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
PneumaticTube neighbor = tube.getPartCache(d);
if (neighbor != null) {
if (!clearedTubes.contains(neighbor)) {
neighbor.getLogic().clearNodeCache();
clearedTubes.add(neighbor);
if (firstRun || !neighbor.isCrossOver)
todoTubes.push(neighbor);
}
}
}
}
firstRun = false;
}
}
use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.
the class TubeLogic method retrieveStack.
public boolean retrieveStack(TileEntity target, ForgeDirection dirToRetrieveInto, ItemStack filter, TubeColor color) {
if (tube.getWorld() == null)
return false;
TubeStack stack = new TubeStack(filter, null, color);
stack.setTarget(target, dirToRetrieveInto);
Pair<ForgeDirection, TileEntity> result = getHeadingForItem(stack, false);
if (result == null)
return false;
int fuzzySetting = 0;
if (target instanceof IFuzzyRetrieving) {
fuzzySetting = ((IFuzzyRetrieving) target).getFuzzySetting();
}
ItemStack extractedItem = null;
if (result.getValue() instanceof TileManager) {
// Exception for managers, the result can only end up as a manager if the pulling inventory was
// a manager.
TileEntity managedInventory = ((TileManager) result.getValue()).getTileCache(((TileManager) result.getValue()).getFacingDirection());
extractedItem = IOHelper.extract(managedInventory, result.getKey().getOpposite(), filter, false, false, fuzzySetting);
} else if (filter != null) {
extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), filter, !(target instanceof TileManager), false, fuzzySetting);
} else {
extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), false);
}
if (extractedItem == null)
throw new IllegalArgumentException("This isn't possible!");
stack = new TubeStack(extractedItem, result.getKey().getOpposite(), color);
stack.setTarget(target, dirToRetrieveInto);
PneumaticTube tube = MultipartCompatibility.getPart(this.tube.getWorld(), result.getValue().xCoord - result.getKey().offsetX, result.getValue().yCoord - result.getKey().offsetY, result.getValue().zCoord - result.getKey().offsetZ, PneumaticTube.class);
if (tube == null)
throw new IllegalArgumentException("wieeeeerd!");
return tube.getLogic().injectStack(stack, result.getKey().getOpposite(), false);
}
Aggregations