use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class TileEntityElevatorBase method updateFloors.
public void updateFloors() {
List<Integer> floorList = new ArrayList<Integer>();
List<ChunkPosition> callerList = new ArrayList<ChunkPosition>();
if (multiElevators != null) {
int i = 0;
boolean shouldBreak = false;
while (!shouldBreak) {
boolean registeredThisFloor = false;
for (TileEntityElevatorBase base : multiElevators) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN) {
if (base.worldObj.getBlock(base.xCoord + dir.offsetX, base.yCoord + i + 2, base.zCoord + dir.offsetZ) == Blockss.elevatorCaller) {
callerList.add(new ChunkPosition(base.xCoord + dir.offsetX, base.yCoord + i + 2, base.zCoord + dir.offsetZ));
if (!registeredThisFloor)
floorList.add(i);
registeredThisFloor = true;
}
}
}
}
i++;
for (TileEntityElevatorBase base : multiElevators) {
if (base.worldObj.getBlock(base.xCoord, base.yCoord + i, base.zCoord) != Blockss.elevatorFrame) {
shouldBreak = true;
break;
}
}
}
for (TileEntityElevatorBase base : multiElevators) {
base.floorHeights = new int[floorList.size()];
for (i = 0; i < base.floorHeights.length; i++) {
base.floorHeights[i] = floorList.get(i);
}
}
}
double buttonHeight = 0.06D;
double buttonSpacing = 0.02D;
TileEntityElevatorCaller.ElevatorButton[] elevatorButtons = new TileEntityElevatorCaller.ElevatorButton[floorHeights.length];
int columns = (elevatorButtons.length - 1) / 12 + 1;
for (int j = 0; j < columns; j++) {
for (int i = j * 12; i < floorHeights.length && i < j * 12 + 12; i++) {
elevatorButtons[i] = new TileEntityElevatorCaller.ElevatorButton(0.2D + 0.6D / columns * j, 0.5D + (Math.min(floorHeights.length, 12) - 2) * (buttonSpacing + buttonHeight) / 2 - i % 12 * (buttonHeight + buttonSpacing), 0.58D / columns, buttonHeight, i, floorHeights[i]);
elevatorButtons[i].setColor(floorHeights[i] == targetExtension ? 0 : 1, 1, floorHeights[i] == targetExtension ? 0 : 1);
String floorName = floorNames.get(floorHeights[i]);
if (floorName != null) {
elevatorButtons[i].buttonText = floorName;
} else {
floorNames.put(floorHeights[i], elevatorButtons[i].buttonText);
}
}
}
if (multiElevators != null) {
for (TileEntityElevatorBase base : multiElevators) {
base.floorNames = new HashMap<Integer, String>(floorNames);
}
}
for (ChunkPosition p : callerList) {
TileEntity te = worldObj.getTileEntity(p.chunkPosX, p.chunkPosY, p.chunkPosZ);
if (te instanceof TileEntityElevatorCaller) {
int callerFloorHeight = p.chunkPosY - yCoord - 2;
int callerFloor = -1;
for (TileEntityElevatorCaller.ElevatorButton floor : elevatorButtons) {
if (floor.floorHeight == callerFloorHeight) {
callerFloor = floor.floorNumber;
break;
}
}
if (callerFloor == -1) {
Log.error("Error while updating elevator floors! This will cause a indexOutOfBoundsException, index = -1");
}
((TileEntityElevatorCaller) te).setEmittingRedstone(PneumaticCraftUtils.areFloatsEqual(targetExtension, extension, 0.1F) && PneumaticCraftUtils.areFloatsEqual(extension, callerFloorHeight, 0.1F));
((TileEntityElevatorCaller) te).setFloors(elevatorButtons, callerFloor);
}
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class TileEntityGasLift method suckLiquid.
public boolean suckLiquid() {
Block block = worldObj.getBlock(xCoord, yCoord - currentDepth - 1, zCoord);
Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
if (fluid != null) {
if (fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), false) == 1000) {
if (pumpingLake == null) {
pumpingLake = new ArrayList<ChunkPosition>();
Stack<ChunkPosition> pendingPositions = new Stack<ChunkPosition>();
ChunkPosition thisPos = new ChunkPosition(xCoord, yCoord - currentDepth - 1, zCoord);
pendingPositions.add(thisPos);
pumpingLake.add(thisPos);
while (!pendingPositions.empty()) {
ChunkPosition checkingPos = pendingPositions.pop();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (d == ForgeDirection.DOWN)
continue;
ChunkPosition newPos = new ChunkPosition(checkingPos.chunkPosX + d.offsetX, checkingPos.chunkPosY + d.offsetY, checkingPos.chunkPosZ + d.offsetZ);
if (PneumaticCraftUtils.distBetween(newPos, xCoord + 0.5, yCoord - currentDepth - 1, zCoord + 0.5) <= MAX_PUMP_RANGE && worldObj.getBlock(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == block && !pumpingLake.contains(newPos)) {
pendingPositions.add(newPos);
pumpingLake.add(newPos);
}
}
}
Collections.sort(pumpingLake, new ChunkPositionSorter(xCoord + 0.5, yCoord - currentDepth - 1, zCoord + 0.5));
Collections.reverse(pumpingLake);
}
ChunkPosition curPos = null;
boolean foundSource = false;
while (pumpingLake.size() > 0) {
curPos = pumpingLake.get(0);
if (worldObj.getBlock(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ) == block && worldObj.getBlockMetadata(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ) == 0) {
foundSource = true;
break;
}
pumpingLake.remove(0);
}
if (pumpingLake.size() == 0) {
pumpingLake = null;
} else if (foundSource) {
worldObj.setBlockToAir(curPos.chunkPosX, curPos.chunkPosY, curPos.chunkPosZ);
fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), true);
addAir(-100, ForgeDirection.UNKNOWN);
status = 1;
}
}
return true;
} else {
pumpingLake = null;
return false;
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class TileEntityKeroseneLamp method updateRange.
private void updateRange(int targetRange) {
if (targetRange > range) {
range++;
ChunkPosition lampPos = new ChunkPosition(xCoord, yCoord, zCoord);
int roundedRange = range / LIGHT_SPACING * LIGHT_SPACING;
for (int x = -roundedRange; x <= roundedRange; x += LIGHT_SPACING) {
for (int y = -roundedRange; y <= roundedRange; y += LIGHT_SPACING) {
for (int z = -roundedRange; z <= roundedRange; z += LIGHT_SPACING) {
ChunkPosition pos = new ChunkPosition(x + xCoord, y + yCoord, z + zCoord);
if (!managingLights.contains(pos)) {
tryAddLight(pos, lampPos);
}
}
}
}
} else if (targetRange < range) {
range--;
Iterator<ChunkPosition> iterator = managingLights.iterator();
ChunkPosition lampPos = new ChunkPosition(xCoord, yCoord, zCoord);
while (iterator.hasNext()) {
ChunkPosition pos = iterator.next();
if (!isLampLight(pos)) {
iterator.remove();
} else if (PneumaticCraftUtils.distBetween(pos, lampPos) > range) {
worldObj.setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
iterator.remove();
}
}
}
isOn = range > 0;
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class TileEntityUniversalSensor method addLuaMethods.
@Override
public void addLuaMethods() {
super.addLuaMethods();
luaMethods.add(new LuaMethod("getSensorNames") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
return SensorHandler.instance().getSensorNames();
} else {
throw new IllegalArgumentException("getSensorNames doesn't accept any arguments!");
}
}
});
luaMethods.add(new LuaMethod("setSensor") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 1) {
ISensorSetting sensor = null;
if (args[0] instanceof String) {
sensor = SensorHandler.instance().getSensorForName((String) args[0]);
} else {
sensor = SensorHandler.instance().getSensorByIndex(((Double) args[0]).intValue() - 1);
}
if (sensor != null)
return new Object[] { setSensorSetting(sensor) };
throw new IllegalArgumentException("Invalid sensor name/index: " + args[0]);
} else if (args.length == 0) {
setSensorSetting("");
return new Object[] { true };
} else {
throw new IllegalArgumentException("setSensor needs one argument(a number as index, or a sensor name).");
}
}
});
luaMethods.add(new LuaMethod("getSensor") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
ISensorSetting curSensor = SensorHandler.instance().getSensorFromPath(getSensorSetting());
return curSensor == null ? null : new Object[] { getSensorSetting().substring(getSensorSetting().lastIndexOf('/') + 1) };
} else {
throw new IllegalArgumentException("getSensor doesn't take any arguments!");
}
}
});
luaMethods.add(new LuaMethod("setTextfield") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 1) {
setText(0, (String) args[0]);
return null;
} else {
throw new IllegalArgumentException("setTextfield takes one argument (string)");
}
}
});
luaMethods.add(new LuaMethod("getTextfield") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
return new Object[] { getText(0) };
} else {
throw new IllegalArgumentException("getTextfield takes no arguments");
}
}
});
luaMethods.add(new LuaMethod("isSensorEventBased") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
return new Object[] { SensorHandler.instance().getSensorFromPath(getSensorSetting()) instanceof IEventSensorSetting };
} else {
throw new IllegalArgumentException("isSensorEventBased takes no arguments");
}
}
});
luaMethods.add(new LuaMethod("getSensorValue") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
ISensorSetting s = SensorHandler.instance().getSensorFromPath(getSensorSetting());
if (s instanceof IPollSensorSetting) {
requestPollPullEvent = true;
return new Object[] { redstoneStrength };
} else if (s != null) {
throw new IllegalArgumentException("The selected sensor is pull event based. You can't poll the value.");
} else {
throw new IllegalArgumentException("There's no sensor selected!");
}
} else {
throw new IllegalArgumentException("getSensorValue takes no arguments");
}
}
});
luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR));
luaMethods.add(new LuaMethod("setGPSToolCoordinate") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 4) {
//minus one, as lua is 1-oriented.
ItemStack stack = getStackInSlot(((Double) args[0]).intValue() - 1);
if (stack != null && stack.getItem() == Itemss.GPSTool) {
ItemGPSTool.setGPSLocation(stack, ((Double) args[1]).intValue(), ((Double) args[2]).intValue(), ((Double) args[3]).intValue());
return new Object[] { true };
} else {
return new Object[] { false };
}
} else {
throw new IllegalArgumentException("setGPSToolCoordinate needs 4 arguments: slot, x, y, z");
}
}
});
luaMethods.add(new LuaMethod("getGPSToolCoordinate") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 1) {
//minus one, as lua is 1-oriented.
ItemStack stack = getStackInSlot(((Double) args[0]).intValue() - 1);
if (stack != null && stack.getItem() == Itemss.GPSTool) {
ChunkPosition pos = ItemGPSTool.getGPSLocation(stack);
if (pos != null) {
return new Object[] { pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ };
} else {
return new Object[] { 0, 0, 0 };
}
} else {
return null;
}
} else {
throw new IllegalArgumentException("setGPSToolCoordinate needs 1 argument: slot");
}
}
});
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class TileEntityKeroseneLamp method updateLights.
private void updateLights() {
int roundedRange = range / LIGHT_SPACING * LIGHT_SPACING;
checkingX += LIGHT_SPACING;
if (checkingX > xCoord + roundedRange) {
checkingX = xCoord - roundedRange;
checkingY += LIGHT_SPACING;
if (checkingY > yCoord + roundedRange) {
checkingY = yCoord - roundedRange;
checkingZ += LIGHT_SPACING;
if (checkingZ > zCoord + roundedRange)
checkingZ = zCoord - roundedRange;
}
}
ChunkPosition pos = new ChunkPosition(checkingX, checkingY, checkingZ);
ChunkPosition lampPos = new ChunkPosition(xCoord, yCoord, zCoord);
if (managingLights.contains(pos)) {
if (isLampLight(pos)) {
if (!passesRaytraceTest(pos, lampPos)) {
worldObj.setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
managingLights.remove(pos);
}
} else {
managingLights.remove(pos);
}
} else {
tryAddLight(pos, lampPos);
}
}
Aggregations