GT5-Unofficial/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java

43 lines
2 KiB
Java
Raw Normal View History

2015-04-23 16:14:22 +00:00
package gregtech.api.threads;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
2015-10-22 02:15:09 +00:00
import java.util.ArrayList;
2015-04-23 16:14:22 +00:00
public class GT_Runnable_MachineBlockUpdate implements Runnable {
2015-10-22 02:15:09 +00:00
private final int mX, mY, mZ;
private final World mWorld;
public GT_Runnable_MachineBlockUpdate(World aWorld, int aX, int aY, int aZ) {
mWorld = aWorld;
mX = aX;
mY = aY;
mZ = aZ;
}
private static void stepToUpdateMachine(World aWorld, int aX, int aY, int aZ, ArrayList<ChunkPosition> aList) {
aList.add(new ChunkPosition(aX, aY, aZ));
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
2016-08-13 08:10:38 +00:00
if (tTileEntity instanceof IMachineBlockUpdateable)
2015-10-22 02:15:09 +00:00
((IMachineBlockUpdateable) tTileEntity).onMachineBlockUpdate();
2016-08-13 08:10:38 +00:00
if (aList.size() < 5 || (tTileEntity instanceof IMachineBlockUpdateable) || GregTech_API.isMachineBlock(aWorld.getBlock(aX, aY, aZ), aWorld.getBlockMetadata(aX, aY, aZ))) {
2015-10-22 02:15:09 +00:00
if (!aList.contains(new ChunkPosition(aX + 1, aY, aZ))) stepToUpdateMachine(aWorld, aX + 1, aY, aZ, aList);
if (!aList.contains(new ChunkPosition(aX - 1, aY, aZ))) stepToUpdateMachine(aWorld, aX - 1, aY, aZ, aList);
if (!aList.contains(new ChunkPosition(aX, aY + 1, aZ))) stepToUpdateMachine(aWorld, aX, aY + 1, aZ, aList);
if (!aList.contains(new ChunkPosition(aX, aY - 1, aZ))) stepToUpdateMachine(aWorld, aX, aY - 1, aZ, aList);
if (!aList.contains(new ChunkPosition(aX, aY, aZ + 1))) stepToUpdateMachine(aWorld, aX, aY, aZ + 1, aList);
if (!aList.contains(new ChunkPosition(aX, aY, aZ - 1))) stepToUpdateMachine(aWorld, aX, aY, aZ - 1, aList);
}
}
@Override
public void run() {
try {
stepToUpdateMachine(mWorld, mX, mY, mZ, new ArrayList<ChunkPosition>());
} catch (Throwable e) {/**/}
}
2015-04-23 16:14:22 +00:00
}