Search in sources :

Example 76 with WorldServer

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;
}
Also used : EnvironmentModule(mcjty.rftools.blocks.environmental.modules.EnvironmentModule) ArrayList(java.util.ArrayList) PeacefulEModule(mcjty.rftools.blocks.environmental.modules.PeacefulEModule) WorldServer(net.minecraft.world.WorldServer) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Example 77 with WorldServer

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;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) LogicTileEntity(mcjty.rftools.blocks.logic.generic.LogicTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity)

Example 78 with WorldServer

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);
}
Also used : StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StorageScannerContainer(mcjty.rftools.blocks.storagemonitor.StorageScannerContainer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 79 with WorldServer

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());
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) LogicTileEntity(mcjty.rftools.blocks.logic.generic.LogicTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) Nonnull(javax.annotation.Nonnull)

Example 80 with WorldServer

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();
}
Also used : SPacketTimeUpdate(net.minecraft.network.play.server.SPacketTimeUpdate) CrashReport(net.minecraft.crash.CrashReport) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) ReportedException(net.minecraft.util.ReportedException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WorldServer (net.minecraft.world.WorldServer)338 BlockPos (net.minecraft.util.math.BlockPos)101 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 ItemStack (net.minecraft.item.ItemStack)55 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)47 Entity (net.minecraft.entity.Entity)44 TileEntity (net.minecraft.tileentity.TileEntity)42 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)36 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)32 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)28 ArrayList (java.util.ArrayList)20 PotionEffect (net.minecraft.potion.PotionEffect)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Nullable (javax.annotation.Nullable)17 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)14