Java 类net.minecraftforge.common.DimensionManager 实例源码

项目:pnc-repressurized    文件:ItemRemote.java   
private boolean isAllowedToEdit(EntityPlayer player, ItemStack remote) {
    NBTTagCompound tag = remote.getTagCompound();
    if (tag != null) {
        if (tag.hasKey("securityX")) {
            int x = tag.getInteger("securityX");
            int y = tag.getInteger("securityY");
            int z = tag.getInteger("securityZ");
            int dimensionId = tag.getInteger("securityDimension");
            WorldServer world = DimensionManager.getWorld(dimensionId);
            if (world != null) {
                TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
                if (te instanceof TileEntitySecurityStation) {
                    boolean canAccess = ((TileEntitySecurityStation) te).doesAllowPlayer(player);
                    if (!canAccess) {
                        player.sendStatusMessage(new TextComponentTranslation("gui.remote.noEditRights", x, y, z), false);
                    }
                    return canAccess;
                }
            }
        }
    }
    return true;
}
项目:pnc-repressurized    文件:ItemRemote.java   
@Override
public void onUpdate(ItemStack remote, World worl, Entity entity, int slot, boolean holdingItem) {
    if (!worl.isRemote) {
        NBTTagCompound tag = remote.getTagCompound();
        if (tag != null) {
            if (tag.hasKey("securityX")) {
                int x = tag.getInteger("securityX");
                int y = tag.getInteger("securityY");
                int z = tag.getInteger("securityZ");
                int dimensionId = tag.getInteger("securityDimension");
                WorldServer world = DimensionManager.getWorld(dimensionId);
                if (world != null) {
                    TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
                    if (!(te instanceof TileEntitySecurityStation)) {
                        tag.removeTag("securityX");
                        tag.removeTag("securityY");
                        tag.removeTag("securityZ");
                        tag.removeTag("securityDimension");
                    }
                }
            }
        }
    }
}
项目:Firma    文件:JoinHandler.java   
@SubscribeEvent
public void move(TickEvent.PlayerTickEvent event) {


    if (event.player.world.isRemote) {
        //System.out.println("CLIENT "+event.player.world.getBiome(event.player.getPosition()).getBiomeName());

        return;
    }
    //System.out.println(event.player.world.getBiome(event.player.getPosition()).getBiomeName());
    if (CommonProxy.d == 0) {
        return;
    }
    World w = event.player.world;
    if (w != null && w.getWorldType() == WorldType.DEFAULT) {
        new SpawnTeleport(DimensionManager.getWorld(CommonProxy.d)).teleport(event.player, DimensionManager.getWorld(CommonProxy.d));
    }
}
项目:InControl    文件:GenericRuleEvaluator.java   
private boolean isFakePlayer(Entity entity) {
    if (!(entity instanceof EntityPlayer)) {
        return false;
    }

    if (entity instanceof FakePlayer) {
        return true;
    }

    // If this returns false it is still possible we have a fake player. Try to find the player in the list of online players
    PlayerList playerList = DimensionManager.getWorld(0).getMinecraftServer().getPlayerList();
    EntityPlayerMP playerByUUID = playerList.getPlayerByUUID(((EntityPlayer) entity).getGameProfile().getId());
    if (playerByUUID == null) {
        // The player isn't online. Then it can't be real
        return true;
    }

    // The player is in the list. But is it this player?
    return entity != playerByUUID;
}
项目:MeeCreeps    文件:EntityProjectile.java   
/**
 * Called when this EntityThrowable hits a block or entity.
 */
@Override
protected void onImpact(RayTraceResult result) {
    if (!world.isRemote) {
        if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
            EntityPlayer player = null;
            if (playerId != null) {
                MinecraftServer server = DimensionManager.getWorld(0).getMinecraftServer();
                player = playerId == null ? null : server.getPlayerList().getPlayerByUUID(playerId);
            }
            if (player != null) {
                TeleportationTools.makePortalPair(player, result.getBlockPos(), result.sideHit, destination);
            } else {
                TeleportationTools.makePortalPair(world, result.getBlockPos(), result.sideHit, destination);
            }
        }
        this.setDead();
    }
}
项目:VoidApi    文件:HandlerBiome.java   
@Override
public void handleData(NBTTagCompound data)
{
    Biome b = Biome.getBiome(data.getInteger("biomeID"));
    DimBlockPos dbp = SerializationUtils.deserialize(data.getByteArray("blockPosData"));
    if (MC.getSide() == Side.CLIENT)
    {
        VoidApi.proxy.getClientListener().addScheduledTask(() -> {
                if (VoidApi.proxy.getClientWorld().isBlockLoaded(dbp.pos))
                    ChunkUtils.setBiomeAt(b, dbp.pos, VoidApi.proxy.getClientWorld());}
        );
    }
    else
    {
        WorldServer ws = DimensionManager.getWorld(dbp.dim);
        ws.addScheduledTask(() -> {
                if (ws.isBlockLoaded(dbp.pos))
                    ChunkUtils.setBiomeAt(b, dbp.pos, ws);}
        );
    }
}
项目:PurificatiMagicae    文件:SifStorageServer.java   
@Override
public void set(GlobalChunkPos pos, float value)
{
    if (loaded.containsKey(pos))
        if (loaded.get(pos).equals(value))
            return;
    loaded.put(pos, value);
    WorldServer wrld = DimensionManager.getWorld(pos.getDimension());
    wrld.getChunkFromChunkCoords(pos.getX(), pos.getZ()).markDirty();
    PlayerChunkMapEntry map = wrld.getPlayerChunkMap().getEntry(pos.getX(), pos.getZ());
    if (map != null)
    {
        for (EntityPlayerMP p : map.players)
        {
            NetworkManager.sendTo(new CPacketSyncSif(pos, value), p);
        }
    }
}
项目:UniversalRemote    文件:Util.java   
public static String getNiceDimensionName(int dim) {
    // try to get a nice dimension name
    String dimName = DimensionManager.getProvider(dim).getDimensionType().getName()
            .replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2").replace("_", " ").trim();

    // TODO clean up this formatting mess
    String[] dimNameWords = dimName.split(" ");

    for (int i = 0; i < dimNameWords.length; i++)
    {
        if (dimNameWords[i].length() > 1)
        {
            dimNameWords[i] = dimNameWords[i].substring(0, 1).toUpperCase() + dimNameWords[i].substring(1);
        }
    }

    return String.join(" ", dimNameWords);
}
项目:FirstAid    文件:MorpheusHelper.java   
@Override
public void startNewDay() {
    if (oldHandler != null) oldHandler.startNewDay(); //Start the new day

    if (FirstAidConfig.externalHealing.sleepHealing == 0F) return;

    WorldSleepState sleepState = Morpheus.playerSleepStatus.get(0);
    if (sleepState == null) return;

    if (areEnoughPlayersAsleep(sleepState)) {
        World world = DimensionManager.getWorld(0);
        for (EntityPlayer player : world.playerEntities) {
            if (player.isPlayerFullyAsleep()) {
                HealthDistribution.distributeHealth(FirstAid.activeHealingConfig.sleepHealing, player, true); //heal the player who did sleep
            }
        }
    }
}
项目:refinedstorageaddons    文件:WirelessCraftingGrid.java   
@Override
public void onCraftingMatrixChanged() {
    if (currentRecipe == null || !currentRecipe.matches(matrix, DimensionManager.getWorld(controllerDimension))) {
        currentRecipe = CraftingManager.findMatchingRecipe(matrix, DimensionManager.getWorld(controllerDimension));
    }

    if (currentRecipe == null) {
        result.setInventorySlotContents(0, ItemStack.EMPTY);
    } else {
        result.setInventorySlotContents(0, currentRecipe.getCraftingResult(matrix));
    }

    if (!getStack().hasTagCompound()) {
        getStack().setTagCompound(new NBTTagCompound());
    }

    StackUtils.writeItems(matrix, 1, getStack().getTagCompound());
}
项目:Thermionics    文件:ItemChunkUnloader.java   
public Optional<Boolean> isChunkLoaded(ItemStack stack) {
    if (!stack.hasTagCompound()) return UNATTUNED;

    NBTTagCompound tag = stack.getTagCompound();
    if (tag.hasKey("world")) {
        int worldId = tag.getInteger("world");
        if (!DimensionManager.isDimensionRegistered(worldId)) return UNATTUNED;

        //We're reasonably certain at this point the unloader is attuned to a valid world.

        WorldServer world = DimensionManager.getWorld(worldId);
        if (world==null) return UNLOADED;

        //boolean playerLoad = world.getPlayerChunkMap().contains(tag.getInteger("x"), tag.getInteger("z"));
        //System.out.println("chunk["+tag.getInteger("x")+","+tag.getInteger("z")+"] isPlayerLoaded:"+playerLoad);

        Chunk chunk = world.getChunkProvider().getLoadedChunk(tag.getInteger("x"), tag.getInteger("z"));
        return (chunk!=null) ? LOADED : UNLOADED;
        //Chunk chunk = world.getChunkFromChunkCoords(tag.getInteger("x"),tag.getInteger("z"));
        //return (chunk.isLoaded()) ? LOADED : UNLOADED;
    }

    return UNATTUNED;
}
项目:Thermionics    文件:ItemChunkUnloader.java   
public boolean unloadChunk(ItemStack stack) {
    if (!stack.hasTagCompound()) return false;
    NBTTagCompound tag = stack.getTagCompound();
    if (tag.getBoolean("ignoreClick")) {
        tag.removeTag("ignoreClick");
        stack.setTagCompound(tag);
        return false;
    }

    int worldId = tag.getInteger("world");
    int x = tag.getInteger("x");
    int z = tag.getInteger("z");
    World world = DimensionManager.getWorld(worldId);
    if (world==null) return false;

    IChunkProvider provider = world.getChunkProvider();
    Chunk chunk = provider.getLoadedChunk(x, z);
    if (chunk==null) return false;
    if (provider instanceof ChunkProviderServer) {
        ((ChunkProviderServer) provider).queueUnload(chunk);
        return true;
    } else {
        return false;
    }
}
项目:modName    文件:GrassColours.java   
public static void init() {
    ExampleMod.logger.info("ATTEMPTING TO COMMIT GREAT EVIL:");
    try {
        doImmenseEvil();
    } catch(Throwable e) {
        e.printStackTrace();
    }
    MinecraftForge.EVENT_BUS.register(new Listener());

    grassCache = CacheBuilder.newBuilder()
        .maximumSize(2048)
        .build(
            new CacheLoader<GrassCacheKey, Biome>() {
                @Override
                public Biome load(GrassCacheKey key) {
                    return DimensionManager.getWorld(key.dim).getBiome(new BlockPos(key.x, 63, key.z));
                }
            }
        );
}
项目:DebugServerInfo    文件:ServerHelper.java   
public static Data getData()
{
    if (data != null) return data;

    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();

    Integer[] dimsObj = DimensionManager.getIDs();
    TIntDoubleMap map = new TIntDoubleHashMap(dimsObj.length);

    for (Integer dim : dimsObj)
    {
        map.put(dim, mean(server.worldTickTimes.get(dim)) * 1.0E-6D);
    }

    double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D;

    int total = (int) (Runtime.getRuntime().totalMemory() / 1024 / 1024);
    int max = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024);
    int free = (int) (Runtime.getRuntime().freeMemory() / 1024 / 1024);

    data = new Data(meanTickTime, map, free, total, max);
    return data;
}
项目:World-Border    文件:Worlds.java   
/**
 * Performs a case-sensitive search for a loaded world by a given name.
 *
 * First, it tries to match the name with dimension 0 (overworld), then it tries to
 * match from the world's save folder name (e.g. DIM_MYST10) and then finally the
 * Dynmap compatible identifier (e.g. DIM10)
 *
 * @param name Name of world to find
 * @return World if found, else null
 */
public static WorldServer getWorld(String name)
{
    if ( name == null || name.isEmpty() )
        throw new IllegalArgumentException("World name cannot be empty or null");

    for ( WorldServer world : DimensionManager.getWorlds() )
    {
        String dimName    = "DIM" + world.provider.getDimension();
        String saveFolder = world.provider.getSaveFolder();

        if (world.provider.getDimension() == 0)
        {   // Special case for dimension 0 (overworld)
            if ( WorldBorder.SERVER.getFolderName().equals(name) )
                return world;
        }
        else if ( saveFolder.equals(name) || dimName.equals(name) )
            return world;
    }

    return null;
}
项目:ExtraUtilities    文件:EventHandlerSiege.java   
public static void checkPlayers() {
    final World worldObj = (World)DimensionManager.getWorld(1);
    if (worldObj == null || worldObj.isRemote) {
        EventHandlerSiege.SiegeParticipants.clear();
        return;
    }
    if (EventHandlerSiege.SiegeParticipants.size() > 0) {
        for (int i = 0; i < EventHandlerSiege.SiegeParticipants.size(); ++i) {
            if (worldObj.getPlayerEntityByName((String)EventHandlerSiege.SiegeParticipants.get(i)) == null) {
                EventHandlerSiege.SiegeParticipants.remove(EventHandlerSiege.SiegeParticipants.get(i));
                --i;
            }
        }
        if (EventHandlerSiege.SiegeParticipants.size() == 0) {
            endSiege(worldObj, true);
        }
    }
}
项目:ExtraUtilities    文件:TConEvents.java   
@SubscribeEvent
public void addUnstableTimer(final SmelteryCastedEvent.CastingTable event) {
    if (ExtraUtils.tcon_unstable_material_id <= 0) {
        return;
    }
    final ItemStack output = event.output;
    if (output == null || !(output.getItem() instanceof IToolPart)) {
        return;
    }
    final IToolPart part = (IToolPart)output.getItem();
    if (part.getMaterialID(output) != ExtraUtils.tcon_unstable_material_id) {
        return;
    }
    final NBTTagCompound tag = getOrInitTag(output);
    final WorldServer world = DimensionManager.getWorld(0);
    if (world == null) {
        return;
    }
    tag.setLong("XUDeadline", world.getTotalWorldTime());
    final WorldServer localWorld = DimensionManager.getWorld(this.curDim);
    if (localWorld != null) {
        tag.setLong("XULocalDeadline", localWorld.getTotalWorldTime());
        tag.setInteger("XULocalDim", this.curDim);
    }
}
项目:ExtraUtilities    文件:TConEvents.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void denyCraft(final ToolBuildEvent event) {
    if (ExtraUtils.tcon_unstable_material_id <= 0) {
        return;
    }
    final WorldServer world = DimensionManager.getWorld(0);
    if (world == null) {
        return;
    }
    if (isToolExpired(event.headStack, world) || isToolExpired(event.handleStack, world) || isToolExpired(event.accessoryStack, world) || isToolExpired(event.extraStack, world)) {
        event.headStack = null;
        event.handleStack = null;
        event.accessoryStack = null;
        event.extraStack = null;
    }
}
项目:Overlord    文件:Squads.java   
private static void readFromFile() {
    if (saveDir == null)
        saveDir = DimensionManager.getCurrentSaveRootDirectory();
    if (saveDir == null) {
        Overlord.logError("Could not get save directory. Either you are connected to a server or Squads will not load properly.");
        instance = new Squads();
        return;
    }
    File f = new File(saveDir, dataFileName);
    if (f.exists()) {
        try {
            ObjectInputStream stream = new ObjectInputStream(new FileInputStream(f));
            instance = (Squads) stream.readObject();
            stream.close();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            instance = new Squads();
            f.delete();
        }
    }
    if (instance == null)
        instance = new Squads();
}
项目:justenoughdimensions    文件:DimensionConfig.java   
public void registerOverriddenDimensions()
{
    for (DimensionConfigEntry entry : this.dimensions.values())
    {
        if (Configs.enableUnregisteringDimensions && entry.getUnregister() &&
            DimensionManager.isDimensionRegistered(entry.getId()))
        {
            JustEnoughDimensions.logInfo("Unregistering dimension {}...", entry.getId());
            DimensionManager.unregisterDimension(entry.getId());
        }
        else if (entry.getOverride() &&
                    (Configs.enableReplacingRegisteredDimensions ||
                     DimensionManager.isDimensionRegistered(entry.getId()) == false))
        {
            this.registerDimension(entry.getId(), entry);
        }
    }
}
项目:Overlord    文件:Enemies.java   
private static void readFromFile() {
    if (saveDir == null)
        saveDir = DimensionManager.getCurrentSaveRootDirectory();
    if (saveDir == null) {
        Overlord.logError("Could not get save directory. Enemies will not load properly.");
        instance = new Enemies();
        return;
    }
    File f = new File(saveDir, dataFileName);
    if (f.exists()) {
        try {
            ObjectInputStream stream = new ObjectInputStream(new FileInputStream(f));
            instance = (Enemies) stream.readObject();
            stream.close();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            instance = new Enemies();
            f.delete();
        }
    }
    if (instance == null)
        instance = new Enemies();
}
项目:4Space-5    文件:GalacticraftRegistry.java   
/***
 * Now returns a boolean to indicate whether registration of the WorldProvider type was successful.
 * (If it failed, you should probably set the CelestialBody as unreachable.)
 * 
 * @param id
 * @param provider
 * @param keepLoaded
 * @return <boolean> success
 */
public static boolean registerProvider(int id, Class<? extends WorldProvider> provider, boolean keepLoaded, int defaultID)
{
    boolean flag = DimensionManager.registerProviderType(id, provider, keepLoaded);
    if (flag)
    {
        GalacticraftRegistry.worldProviderIDs.add(id);
        return true;
    }
    else
    {
        GalacticraftRegistry.worldProviderIDs.add(defaultID);  //Adding the 0 here preserves the order, important for network compatibility between GC versions
        FMLLog.severe("Could not register dimension " + id + " - does it clash with another mod?  Change the ID in config.");
        return false;
    }
}
项目:4Space-5    文件:ChunkLoadingCallback.java   
private static File getSaveDir()
{
    if (DimensionManager.getWorld(0) != null)
    {
        File saveDir = new File(DimensionManager.getCurrentSaveRootDirectory(), "galacticraft");

        if (!saveDir.exists())
        {
            if (!saveDir.mkdirs())
            {
                GCLog.severe("Could not create chunk loader save data folder: " + saveDir.getAbsolutePath());
            }
        }

        return saveDir;
    }

    return null;
}
项目:4Space-5    文件:WorldUtil.java   
public static void registerPlanetClient(Integer dimID, int providerIndex)
{
    int providerID = GalacticraftRegistry.getProviderID(providerIndex);

    if (providerID == 0)
    {
        GCLog.severe("Server dimension " + dimID + " has no match on client due to earlier registration problem.");
    }
    else
    {
        if (!WorldUtil.registeredPlanets.contains(dimID))
        {
            WorldUtil.registeredPlanets.add(dimID);
            DimensionManager.registerDimension(dimID, providerID);
        }
        else
        {
            GCLog.severe("Dimension already registered to another mod: unable to register planet dimension " + dimID);
        }
    }
}
项目:4Space-5    文件:WorldUtil.java   
public static SpaceStationWorldData bindSpaceStationToNewDimension(World world, EntityPlayerMP player, int homePlanetID)
{
    int dynamicProviderID = -1;
    int staticProviderID = -1;
    for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values())
    {
        if (satellite.getParentPlanet().getDimensionID() == homePlanetID)
        {
            dynamicProviderID = satellite.getDimensionID();
            staticProviderID = satellite.getDimensionIdStatic();
        }
    }
    if (dynamicProviderID == -1 || staticProviderID == -1)
    {
        throw new RuntimeException("Space station being bound on bad provider IDs!");
    }
    int newID = DimensionManager.getNextFreeDimId();
    SpaceStationWorldData data = WorldUtil.createSpaceStation(world, newID, homePlanetID, dynamicProviderID, staticProviderID, player);
    dimNames.put(newID, "Space Station " + newID);
    GCPlayerStats stats = GCPlayerStats.get(player);
    stats.spaceStationDimensionData.put(homePlanetID, newID);
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, new Object[] { WorldUtil.spaceStationDataToString(stats.spaceStationDimensionData) }), player);
    return data;
}
项目:justenoughdimensions    文件:DimensionConfig.java   
public void unregisterCustomDimensions()
{
    Set<Integer> toRemove = new HashSet<Integer>();

    for (int dimension : this.registeredDimensions)
    {
        if (dimension != 0 && DimensionManager.isDimensionRegistered(dimension) && DimensionManager.getWorld(dimension) == null)
        {
            JustEnoughDimensions.logInfo("Unregistering dimension {}...", dimension);
            DimensionManager.unregisterDimension(dimension);
            toRemove.add(dimension);
        }
    }

    this.registeredDimensions.removeAll(toRemove);
}
项目:Factorization    文件:FZDSCommand.java   
@Override
public void call(String[] args) {
    DSTeleporter tp = getTp();
    if (arg0.equalsIgnoreCase("gob")) {
        tp.destination = selected.getMinCorner();
    } else if (arg0.equalsIgnoreCase("got")) {
        tp.destination = selected.getMaxCorner();
    } else {
        tp.destination = selected.getCenter();
    }
    if (DimensionManager.getWorld(DeltaChunk.getDimensionId()) != player.worldObj) {
        manager.transferPlayerToDimension(player, DeltaChunk.getDimensionId(), tp);
    } else {
        tp.destination.x--;
        tp.destination.moveToTopBlock();
        player.setPositionAndUpdate(tp.destination.x + 0.5, tp.destination.y, tp.destination.z + 0.5);
    }
}
项目:CrystalMod    文件:StringUtils.java   
public static final String getDimensionName(UUID requestID, int dimension){
    if(FMLCommonHandler.instance().getSide() == Side.SERVER){
        try{
            DimensionType type = DimensionManager.getProviderType(dimension);
            return type.getName();
        } catch(Exception e){}
    } else {
        if(!DIMENSION_NAMES.containsKey(dimension)){
            CrystalModNetwork.sendToServer(new PacketDimensionNameRequest(requestID, dimension));
        } else {
            return DIMENSION_NAMES.get(dimension);
        }
    }

    return ""+dimension;
}
项目:TechnicalDimensions    文件:ModDimensions.java   
public static void worldLoad(FMLServerStartedEvent serverStartedEvent) throws IOException {
    File worldFile = new File(FMLCommonHandler.instance().getSavesDirectory(), FMLCommonHandler.instance().getMinecraftServerInstance().getFolderName());
    File dataFile = new File(worldFile, fileName);

    if (!dataFile.exists()) {
        return;
    }

    String json = FileUtils.readFileToString(dataFile);
    Gson gson = new Gson();
    Type typeOfHashMap = new TypeToken<List<DimData>>() {
    }.getType();
    List<DimData> tempDataList = gson.fromJson(json, typeOfHashMap);
    for (DimData data : tempDataList) {
        DimensionType type = DimensionType.register("technicaldimensions", data.name, data.id, CustomWorldProvider.class, false);
        DimensionManager.registerDimension(data.id, type);
        data.type = type;
        dimDataHashMap.put(data.id, data);
        dimDataList.add(data);
    }
}
项目:TechnicalDimensions    文件:ModDimensions.java   
public static void unloadAll(FMLServerStoppingEvent serverStoppingEvent) {
    File worldFile = new File(FMLCommonHandler.instance().getSavesDirectory(), FMLCommonHandler.instance().getMinecraftServerInstance().getFolderName());
    File dataFile = new File(worldFile, fileName);

    if (dimDataList == null || dimDataList.isEmpty()) {
        return;
    }
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(dimDataList);
    try {
        if (dataFile.exists()) {
            dataFile.delete();
        }
        FileUtils.writeStringToFile(dataFile, json);
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (DimData data : dimDataList) {
        DimensionManager.unloadWorld(data.id);
        DimensionManager.unregisterDimension(data.id);
    }
    dimDataList.clear();
    dimDataHashMap.clear();
}
项目:CraftingHarmonics    文件:SetTimeCallback.java   
@Override
protected void applyWithTargetDimension(Entity target, int targetDim, CallbackMetadata metadata) {
    WorldServer worldServer = DimensionManager.getWorld(targetDim);
    if(worldServer == null) {
        LogHelper.error("Attempted to set the time for a world (" + targetDim + ") that doesn't exist.");
        runCallbacks(onFailure, target, metadata);
        runCallbacks(onComplete, target, metadata);
        return;
    }

    // Calc how far we need to set it:
    int dayTickLength = CraftingHarmonicsMod.getConfigManager().getDayTickLength();
    long curTime = worldServer.getWorldTime();
    long newTime = (curTime % dayTickLength) + time;

    // If we were going to set it back, then we need to add a day:
    if(newTime < curTime) newTime += dayTickLength;

    // Actually set the time now...
    worldServer.setWorldTime(newTime);
    runCallbacks(onSuccess, target, metadata);
    runCallbacks(onComplete, target, metadata);
}
项目:nVoid    文件:nVoid.java   
@Mod.EventHandler
public void load(FMLInitializationEvent event) {
    if (Config.voidNether == true) {
        wtvn = new WorldTypeVoidNether();
        DimensionManager.unregisterDimension(-1);
        DimensionManager.registerDimension(-1,
                DimensionType.register("VoidNether", "_nether", -1, WorldProviderVoidNether.class, false));
    }
    if (Config.voidOverworld == true) {
        wtvo = new WorldTypeVoidOverworld();
        DimensionManager.unregisterDimension(0);
        DimensionManager.registerDimension(0,
                DimensionType.register("VoidOverworld", "overworld", 0, WorldProviderVoidOverworld.class, false));
    }
    if (Config.voidEnd == true) {
        wtve = new WorldTypeVoidEnd();
        DimensionManager.unregisterDimension(1);
        DimensionManager.registerDimension(1,
                DimensionType.register("VoidEnd", "end", 1, WorldProviderVoidEnd.class, false));
    }
}
项目:TeslaEssentials    文件:TileCharger.java   
@Override
public void update() {
    if (inventory[0] != null && inventory[0].hasCapability(TeslaCapabilities.CAPABILITY_CONSUMER, EnumFacing.DOWN) &&
            inventory[0].hasCapability(TeslaCapabilities.CAPABILITY_HOLDER, EnumFacing.DOWN)) {
        ITeslaConsumer c = inventory[0].getCapability(TeslaCapabilities.CAPABILITY_CONSUMER, EnumFacing.DOWN);
        ITeslaHolder h = inventory[0].getCapability(TeslaCapabilities.CAPABILITY_HOLDER, EnumFacing.DOWN);
        if (h.getStoredPower() < h.getCapacity()) container.takePower(c.givePower(Math.min(container.getOutputRate(), container.getStoredPower()), false), false);
    }
    if(syncTick==10 && !worldObj.isRemote){
        if(pos!=null){
            int dim = 0;
            for(int i : DimensionManager.getIDs())
                if(DimensionManager.getWorld(i).equals(worldObj)) {
                    dim = i;
                    break;
                }
            ModSquad.channel.sendToAll(new TileDataSync(pos, serializeNBT().toString(), dim));
        }
        syncTick = 0;
    }else if(syncTick<10) ++syncTick;
}
项目:justenoughdimensions    文件:GamemodeInventory.java   
private NBTTagCompound readFromDisk(EntityPlayerMP player)
  {
NBTTagCompound nbt = new NBTTagCompound();
try
      {
          File saveDir = DimensionManager.getCurrentSaveRootDirectory();

          if (saveDir != null)
          {
              File file = new File(new File(saveDir, Reference.MOD_ID), player.getUniqueID() + ".dat");

              if (file.exists() && file.isFile())
              {
                // read player inventory file
                FileInputStream in = new FileInputStream(file);
                nbt = CompressedStreamTools.readCompressed(in);
                in.close();
              }
          }
      }
      catch (Exception e)
      {
          JustEnoughDimensions.logger.warn("Failed to read GamemodeInventory for player " + player.getName());
      }
return nbt;
  }
项目:Malgra    文件:SyncResearchDimensions.java   
@Override
public void process(EntityPlayer player, Side side)
{
    if(ResearchDimensions.get(player.world).researchDimIDs.get(this.username) == null) {
        DimensionType researchDim = DimensionType.register("research" + this.username, "", this.dimID, WorldProviderResearch.class, false);

        DimensionManager.registerDimension(this.dimID, researchDim);

        ResearchDimensions.get(player.world).researchDimIDs.put(this.username, this.dimID);
        ResearchDimensions.get(player.world).researchDimTypes.put(this.dimID, researchDim);
    }else{

        ResearchDimensions.get(player.world).researchDimIDs.put(this.username, this.dimID);
        ResearchDimensions.get(player.world).researchDimTypes.put(this.dimID, DimensionType.getById(this.dimID));

    }

}
项目:WorldBorder-Forge    文件:Worlds.java   
/**
 * Performs a case-sensitive search for a loaded world by a given name.
 *
 * First, it tries to match the name with dimension 0 (overworld), then it tries to
 * match from the world's save folder name (e.g. DIM_MYST10) and then finally the
 * Dynmap compatible identifier (e.g. DIM10)
 *
 * @param name Name of world to find
 * @return World if found, else null
 */
public static WorldServer getWorld(String name)
{
    if ( name == null || name.isEmpty() )
        throw new IllegalArgumentException("World name cannot be empty or null");

    for ( WorldServer world : DimensionManager.getWorlds() )
    {
        String dimName    = "DIM" + world.provider.dimensionId;
        String saveFolder = world.provider.getSaveFolder();

        if (world.provider.dimensionId == 0)
        {   // Special case for dimension 0 (overworld)
            if ( WorldBorder.SERVER.getFolderName().equals(name) )
                return world;
        }
        else if ( saveFolder.equals(name) || dimName.equals(name) )
            return world;
    }

    return null;
}
项目:Bonfires    文件:CommandBonfires.java   
@Override
@Nonnull
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
    List<String> filters = new ArrayList<>();
    filters.add("all");
    filters.add("dim");
    filters.add("name");
    filters.add("owner");
    filters.add("radius");
    if (args.length == 1 && !filters.contains(args[0])) {
        return filters;
    } else if (args.length == 2 && args[1].isEmpty()) {
        if (args[0].equals("dim")) {
            List<Integer> dimList = new ArrayList<>(Arrays.asList(DimensionManager.getStaticDimensionIDs()));
            dimList = Lists.reverse(dimList);
            Function<Integer, String> toString = input -> toString();
            return Lists.transform(dimList, toString::apply);
        }
        else if (args[0].equals("owner")) {
            if (sender.getServer() != null)
                return new ArrayList<>(Arrays.asList(sender.getServer().getPlayerProfileCache().getUsernames()));
        }
    }
    return super.getTabCompletions(server, sender, args, pos);
}
项目:TorchMaster    文件:TorchRegistry.java   
@SubscribeEvent
public void onGlobalTick(TickEvent.ServerTickEvent event)
{
    if(event.side == Side.CLIENT) return;
    if(this.torches.size() == 0) return;

    this.checkIndex = (this.checkIndex + 1) % this.torches.size();
    TorchLocation loc = this.torches.get(this.checkIndex);
    World world = DimensionManager.getWorld(loc.DimensionId);
    if(world == null) return;
    if(world.isBlockLoaded(loc.Position))
    {
        if(!this.blockValidator.test(world.getBlockState(loc.Position)))
        {
            TorchMasterMod.Log.info("Torch @ " + loc + " is no longer valid, removing from registry");
        }
    }
}
项目:pnc-repressurized    文件:ItemAmadronTablet.java   
public static IFluidHandler getLiquidProvider(ItemStack tablet) {
    BlockPos pos = getLiquidProvidingLocation(tablet);
    if (pos != null) {
        int dimension = getLiquidProvidingDimension(tablet);
        return FluidUtil.getFluidHandler(DimensionManager.getWorld(dimension), pos, null);
    }
    return null;
}
项目:pnc-repressurized    文件:PneumaticCraftUtils.java   
public static TileEntity getTileEntity(BlockPos pos, int dimension) {
    World world = DimensionManager.getWorld(dimension);
    if (world != null && world.isBlockLoaded(pos)) {
        return world.getTileEntity(pos);
    }
    return null;
}