use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class PeacefulAreaManager method isPeaceful.
public static boolean isPeaceful(GlobalCoordinate coordinate) {
if (areas.isEmpty()) {
return false;
}
List<GlobalCoordinate> toRemove = new ArrayList<>();
boolean peaceful = false;
long curtime = System.currentTimeMillis() - 10000;
for (Map.Entry<GlobalCoordinate, PeacefulArea> entry : areas.entrySet()) {
PeacefulArea area = entry.getValue();
GlobalCoordinate entryCoordinate = entry.getKey();
if (area.in(coordinate, entryCoordinate)) {
peaceful = true;
}
if (area.getLastTouched() < curtime) {
// Hasn't been touched for at least 10 seconds. Probably no longer valid.
// To be sure we will first check this by testing if the environmental controller is still active and running.
WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
if (world != null) {
BlockPos c = entryCoordinate.getCoordinate();
// If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
if (RFToolsTools.chunkLoaded(world, c)) {
boolean removeArea = true;
TileEntity te = world.getTileEntity(c);
if (te instanceof EnvironmentalControllerTileEntity) {
EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
if (module instanceof PeacefulEModule) {
if (((PeacefulEModule) module).isActive()) {
removeArea = false;
break;
}
}
}
}
if (removeArea) {
toRemove.add(entryCoordinate);
}
}
}
}
}
for (GlobalCoordinate globalCoordinate : toRemove) {
areas.remove(globalCoordinate);
}
return peaceful;
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class LevelEmitterTileEntity method getCurrentCount.
public int getCurrentCount() {
ItemStack module = inventoryHelper.getStackInSlot(LevelEmitterContainer.SLOT_MODULE);
int count = -1;
if (!module.isEmpty()) {
ItemStack matcher = inventoryHelper.getStackInSlot(LevelEmitterContainer.SLOT_ITEMMATCH);
if (matcher.isEmpty()) {
return count;
}
int dimension = RFToolsTools.getDimensionFromModule(module);
BlockPos scannerPos = RFToolsTools.getPositionFromModule(module);
WorldServer world = DimensionManager.getWorld(dimension);
if (RFToolsTools.chunkLoaded(world, scannerPos)) {
TileEntity te = world.getTileEntity(scannerPos);
if (te instanceof StorageScannerTileEntity) {
StorageScannerTileEntity scannerTE = (StorageScannerTileEntity) te;
count = scannerTE.countItems(matcher, starred, oreDict);
}
}
}
return count;
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class StorageTerminalBlock method createServerContainer.
@Override
public Container createServerContainer(EntityPlayer entityPlayer, TileEntity tileEntity) {
if (!entityPlayer.isSneaking()) {
if (tileEntity instanceof StorageTerminalTileEntity) {
StorageTerminalTileEntity terminalTileEntity = (StorageTerminalTileEntity) tileEntity;
ItemStack module = terminalTileEntity.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
if (!module.isEmpty()) {
int dimension = RFToolsTools.getDimensionFromModule(module);
BlockPos pos = RFToolsTools.getPositionFromModule(module);
WorldServer world = DimensionManager.getWorld(dimension);
if (!RFToolsTools.chunkLoaded(world, pos)) {
entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner out of range!"), false);
return null;
}
TileEntity scannerTE = world.getTileEntity(pos);
if (!(scannerTE instanceof StorageScannerTileEntity)) {
entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner is missing!"), false);
return null;
}
return new StorageScannerContainer(entityPlayer, (IInventory) scannerTE, terminalTileEntity);
}
}
}
return super.createServerContainer(entityPlayer, tileEntity);
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class StorageTerminalTileEntity method craft.
@Override
@Nonnull
public int[] craft(EntityPlayer player, int n, boolean test) {
ItemStack module = inventoryHelper.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
if (module.isEmpty()) {
// No module. Should not be possible
return new int[0];
}
int dimension = RFToolsTools.getDimensionFromModule(module);
BlockPos scannerPos = RFToolsTools.getPositionFromModule(module);
WorldServer world = DimensionManager.getWorld(dimension);
StorageScannerTileEntity scannerTE = null;
if (RFToolsTools.chunkLoaded(world, scannerPos)) {
TileEntity te = world.getTileEntity(scannerPos);
if (te instanceof StorageScannerTileEntity) {
scannerTE = (StorageScannerTileEntity) te;
}
}
if (scannerTE == null) {
// Scanner is not chunkloaded or not valid. Only use player inventory
IItemSource itemSource = new InventoriesItemSource().add(player.inventory, 0);
if (test) {
return StorageCraftingTools.testCraftItems(player, n, craftingGrid.getActiveRecipe(), itemSource);
} else {
StorageCraftingTools.craftItems(player, n, craftingGrid.getActiveRecipe(), itemSource);
return new int[0];
}
} else {
// Delegate crafting to scanner
return scannerTE.craft(player, n, test, craftingGrid.getActiveRecipe());
}
}
use of net.minecraft.world.WorldServer in project SpongeVanilla by SpongePowered.
the class MixinMinecraftServer method updateTimeLightAndEntities.
/**
* @author Zidane
* @reason Handles ticking the additional worlds loaded by Sponge.
*/
@Overwrite
public void updateTimeLightAndEntities() {
this.profiler.startSection("jobs");
synchronized (this.futureTaskQueue) {
while (!this.futureTaskQueue.isEmpty()) {
Util.runTask(this.futureTaskQueue.poll(), LOGGER);
}
}
this.profiler.endStartSection("levels");
// Sponge: Tick chunk loader
tickChunkLoader();
// Sponge start - Iterate over all our dimensions
for (final ObjectIterator<Int2ObjectMap.Entry<WorldServer>> it = WorldManager.worldsIterator(); it.hasNext(); ) {
Int2ObjectMap.Entry<WorldServer> entry = it.next();
final WorldServer worldServer = entry.getValue();
// Sponge end
long i = System.nanoTime();
if (entry.getIntKey() == 0 || this.getAllowNether()) {
// Sponge start - copy from SpongeCommon MixinMinecraftServer
IMixinWorldServer spongeWorld = (IMixinWorldServer) worldServer;
if (spongeWorld.getChunkGCTickInterval() > 0) {
spongeWorld.doChunkGC();
}
// Sponge end
this.profiler.startSection(worldServer.getWorldInfo().getWorldName());
if (this.tickCounter % 20 == 0) {
this.profiler.startSection("timeSync");
this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldServer.getTotalWorldTime(), worldServer.getWorldTime(), worldServer.getGameRules().getBoolean("doDaylightCycle")), ((IMixinWorldServer) worldServer).getDimensionId());
this.profiler.endSection();
}
this.profiler.startSection("tick");
try {
worldServer.tick();
} catch (Throwable throwable1) {
CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world");
worldServer.addWorldInfoToCrashReport(crashreport);
throw new ReportedException(crashreport);
}
try {
worldServer.updateEntities();
} catch (Throwable throwable) {
CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Exception ticking world entities");
worldServer.addWorldInfoToCrashReport(crashreport1);
throw new ReportedException(crashreport1);
}
this.profiler.endSection();
this.profiler.startSection("tracker");
// Sponge start - copy from SpongeCommon MixinMinecraftServer
if (spongeWorld.getChunkGCTickInterval() > 0) {
worldServer.getChunkProvider().tick();
}
// Sponge end
worldServer.getEntityTracker().tick();
this.profiler.endSection();
this.profiler.endSection();
}
// Sponge start - Write tick times to our custom map
this.worldTickTimes.get(entry.getIntKey())[this.tickCounter % 100] = System.nanoTime() - i;
// Sponge end
}
// Sponge start - Unload requested worlds
this.profiler.endStartSection("dim_unloading");
WorldManager.unloadQueuedWorlds();
// Sponge end
this.profiler.endStartSection("connection");
this.getNetworkSystem().networkTick();
this.profiler.endStartSection("players");
this.playerList.onTick();
this.profiler.endStartSection("tickables");
for (int k = 0; k < this.tickables.size(); ++k) {
this.tickables.get(k).update();
}
this.profiler.endSection();
}
Aggregations