use of micdoodle8.mods.galacticraft.core.wrappers.ScheduledBlockChange in project Galacticraft by micdoodle8.
the class TickHandlerServer method onWorldTick.
@SubscribeEvent
public void onWorldTick(WorldTickEvent event) {
if (event.phase == Phase.START) {
final WorldServer world = (WorldServer) event.world;
CopyOnWriteArrayList<ScheduledBlockChange> changeList = TickHandlerServer.scheduledBlockChanges.get(GCCoreUtil.getDimensionID(world));
if (changeList != null && !changeList.isEmpty()) {
int blockCount = 0;
int blockCountMax = Math.max(this.MAX_BLOCKS_PER_TICK, changeList.size() / 4);
List<ScheduledBlockChange> newList = new ArrayList<ScheduledBlockChange>(Math.max(0, changeList.size() - blockCountMax));
for (ScheduledBlockChange change : changeList) {
if (++blockCount > blockCountMax) {
newList.add(change);
} else {
if (change != null) {
BlockPos changePosition = change.getChangePosition();
Block block = world.getBlockState(changePosition).getBlock();
// Only replace blocks of type BlockAir or fire - this is to prevent accidents where other mods have moved blocks
if (changePosition != null && (block instanceof BlockAir || block == Blocks.fire)) {
world.setBlockState(changePosition, change.getChangeID().getStateFromMeta(change.getChangeMeta()), change.getChangeUpdateFlag());
}
}
}
}
changeList.clear();
TickHandlerServer.scheduledBlockChanges.remove(GCCoreUtil.getDimensionID(world));
if (newList.size() > 0) {
TickHandlerServer.scheduledBlockChanges.put(GCCoreUtil.getDimensionID(world), new CopyOnWriteArrayList<ScheduledBlockChange>(newList));
}
}
CopyOnWriteArrayList<BlockVec3> torchList = TickHandlerServer.scheduledTorchUpdates.get(GCCoreUtil.getDimensionID(world));
if (torchList != null && !torchList.isEmpty()) {
for (BlockVec3 torch : torchList) {
if (torch != null) {
BlockPos pos = new BlockPos(torch.x, torch.y, torch.z);
Block b = world.getBlockState(pos).getBlock();
if (b instanceof BlockUnlitTorch) {
world.scheduleUpdate(pos, b, 2 + world.rand.nextInt(30));
}
}
}
torchList.clear();
TickHandlerServer.scheduledTorchUpdates.remove(GCCoreUtil.getDimensionID(world));
}
if (world.provider instanceof IOrbitDimension) {
try {
int dim = GCCoreUtil.getDimensionID(WorldUtil.getProviderForNameServer(((IOrbitDimension) world.provider).getPlanetToOrbit()));
int minY = ((IOrbitDimension) world.provider).getYCoordToTeleportToPlanet();
final Entity[] entityList = world.loadedEntityList.toArray(new Entity[world.loadedEntityList.size()]);
for (final Entity e : entityList) {
if (e.posY <= minY && e.worldObj == world) {
WorldUtil.transferEntityToDimension(e, dim, world, false, null);
}
}
} catch (Exception ex) {
}
}
int dimensionID = GCCoreUtil.getDimensionID(world);
if (worldsNeedingUpdate.contains(dimensionID)) {
worldsNeedingUpdate.remove(dimensionID);
for (Object obj : event.world.loadedTileEntityList) {
TileEntity tile = (TileEntity) obj;
if (tile instanceof TileEntityFluidTank) {
((TileEntityFluidTank) tile).updateClient = true;
}
}
}
} else if (event.phase == Phase.END) {
final WorldServer world = (WorldServer) event.world;
for (GalacticraftPacketHandler handler : packetHandlers) {
handler.tick(world);
}
int dimID = GCCoreUtil.getDimensionID(world);
Set<BlockPos> edgesList = TickHandlerServer.edgeChecks.get(dimID);
final HashSet<BlockPos> checkedThisTick = new HashSet<>();
if (edgesList != null && !edgesList.isEmpty()) {
List<BlockPos> edgesListCopy = new ArrayList<>();
edgesListCopy.addAll(edgesList);
for (BlockPos edgeBlock : edgesListCopy) {
if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) {
if (TickHandlerServer.scheduledForChange(dimID, edgeBlock)) {
continue;
}
ThreadFindSeal done = new ThreadFindSeal(world, edgeBlock, 0, new ArrayList<TileEntityOxygenSealer>());
checkedThisTick.addAll(done.checkedAll());
}
}
TickHandlerServer.edgeChecks.remove(GCCoreUtil.getDimensionID(world));
}
}
}
use of micdoodle8.mods.galacticraft.core.wrappers.ScheduledBlockChange in project Galacticraft by micdoodle8.
the class ThreadFindSeal method makeSealGood.
private void makeSealGood(boolean ambientThermal) {
if (!this.airToReplace.isEmpty() || !this.airToReplaceBright.isEmpty() || !ambientThermalTracked.isEmpty() || !ambientThermalTracked.isEmpty()) {
List<ScheduledBlockChange> changeList = new LinkedList<ScheduledBlockChange>();
Block breatheableAirID = GCBlocks.breatheableAir;
Block breatheableAirIDBright = GCBlocks.brightBreatheableAir;
int metadata = ambientThermal ? 1 : 0;
// TODO: Can we somehow detect only changes in state of ambientThermal since last check? tricky...
for (BlockVec3 checkedVec : this.airToReplace) {
// No block update for performance reasons; deal with unlit torches separately
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), breatheableAirID, metadata, 0));
}
for (BlockVec3 checkedVec : this.airToReplaceBright) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), breatheableAirIDBright, metadata, 0));
}
for (BlockVec3 checkedVec : this.ambientThermalTracked) {
if (checkedVec.getBlockMetadata(this.world) != metadata) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), breatheableAirID, metadata, 0));
}
}
for (BlockVec3 checkedVec : this.ambientThermalTrackedBright) {
if (checkedVec.getBlockMetadata(this.world) != metadata) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), breatheableAirIDBright, metadata, 0));
}
}
TickHandlerServer.scheduleNewBlockChange(GCCoreUtil.getDimensionID(this.world), changeList);
}
if (!this.torchesToUpdate.isEmpty()) {
TickHandlerServer.scheduleNewTorchUpdate(GCCoreUtil.getDimensionID(this.world), this.torchesToUpdate);
}
}
use of micdoodle8.mods.galacticraft.core.wrappers.ScheduledBlockChange in project Galacticraft by micdoodle8.
the class ThreadFindSeal method makeSealBad.
private void makeSealBad() {
if (!this.breatheableToReplace.isEmpty() || !this.breatheableToReplaceBright.isEmpty()) {
List<ScheduledBlockChange> changeList = new LinkedList<ScheduledBlockChange>();
for (BlockVec3 checkedVec : this.breatheableToReplace) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), Blocks.air, 0, 0));
}
for (BlockVec3 checkedVec : this.fireToReplace) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), Blocks.air, 0, 2));
}
for (BlockVec3 checkedVec : this.breatheableToReplaceBright) {
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), GCBlocks.brightAir, 0, 0));
}
TickHandlerServer.scheduleNewBlockChange(GCCoreUtil.getDimensionID(this.world), changeList);
}
if (!this.torchesToUpdate.isEmpty()) {
TickHandlerServer.scheduleNewTorchUpdate(GCCoreUtil.getDimensionID(this.world), this.torchesToUpdate);
}
}
Aggregations