public static void queueChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) { QueuedChunk key = new QueuedChunk(x, z, world); ChunkIOProvider task = tasks.get(key); if (task == null) { task = new ChunkIOProvider(key, loader, provider); task.addCallback(runnable); // Add before calling execute for thread safety tasks.put(key, task); pool.execute(task); } else { task.addCallback(runnable); } }
public Chunk callStage1(QueuedChunk queuedChunk) throws RuntimeException { AnvilChunkLoader loader = queuedChunk.loader; Object[] data = null; try { data = loader.loadChunk__Async(queuedChunk.world, queuedChunk.x, queuedChunk.z); } catch (IOException e) { e.printStackTrace(); } if (data != null) { queuedChunk.compound = (net.minecraft.nbt.NBTTagCompound) data[1]; return (net.minecraft.world.chunk.Chunk) data[0]; } return null; }
public File getSaveFile(ISaveHandler saveHandler, World world, String name, boolean backup) { File worldDir = new File(saveHandler.getWorldDirectoryName()); IChunkLoader loader = saveHandler.getChunkLoader(world.provider); if((loader instanceof AnvilChunkLoader)) { worldDir = ((AnvilChunkLoader) loader).chunkSaveLocation; } File file = new File(worldDir, name + (backup ? ".bak" : "")); if(!file.exists()) { try { file.createNewFile(); } catch(Exception e) { e.printStackTrace(); } } return file; }
public Entity getCachedEntity() { if (this.cachedEntity == null) { this.cachedEntity = AnvilChunkLoader.readWorldEntity(this.randomEntity.getNbt(), this.getSpawnerWorld(), false); if (this.randomEntity.getNbt().getSize() == 1 && this.randomEntity.getNbt().hasKey("id", 8) && this.cachedEntity instanceof EntityLiving) { ((EntityLiving)this.cachedEntity).onInitialSpawn(this.getSpawnerWorld().getDifficultyForLocation(new BlockPos(this.cachedEntity)), (IEntityLivingData)null); } } return this.cachedEntity; }
public static Chunk syncChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z) { QueuedChunk key = new QueuedChunk(x, z, world); ChunkIOProvider task = tasks.remove(key); // Remove task because we will call the sync callbacks directly if (task != null) { if (!pool.remove(task)) // If it wasn't in the pool, and run hasn't finished, then wait for the async thread. { synchronized(task) { while (!task.runFinished()) { try { task.wait(); } catch (InterruptedException e) { e.printStackTrace(); // Something happened? Log it? } } } } else { // If the task was not run yet we still need to load the chunk task.run(); } } else { task = new ChunkIOProvider(key, loader, provider); task.run(); } task.syncCallback(); return task.getChunk(); }
@SideOnly(Side.CLIENT) public Entity getCachedEntity() { if (this.cachedEntity == null) { this.cachedEntity = AnvilChunkLoader.readWorldEntity(this.randomEntity.getNbt(), this.getSpawnerWorld(), false); if (this.randomEntity.getNbt().getSize() == 1 && this.randomEntity.getNbt().hasKey("id", 8) && this.cachedEntity instanceof EntityLiving) { ((EntityLiving)this.cachedEntity).onInitialSpawn(this.getSpawnerWorld().getDifficultyForLocation(new BlockPos(this.cachedEntity)), (IEntityLivingData)null); } } return this.cachedEntity; }
@Nullable public static File getWorldDirectory(World world) { IChunkProvider chunkProvider = world.getChunkProvider(); if (chunkProvider instanceof ChunkProviderServer) { ChunkProviderServer chunkProviderServer = (ChunkProviderServer) chunkProvider; IChunkLoader chunkLoader = chunkProviderServer.chunkLoader; if (chunkLoader instanceof AnvilChunkLoader) { return ((AnvilChunkLoader) chunkLoader).chunkSaveLocation; } return null; } // If this method gets called before ChunkProviderServer has been set yet, // then we mimic the vanilla code in AnvilSaveHandler#getChunkLoader() to get the directory. else { File mainWorldDir = world.getSaveHandler().getWorldDirectory(); String dimensionDir = world.provider.getSaveFolder(); if (dimensionDir != null) { mainWorldDir = new File(mainWorldDir, dimensionDir); mainWorldDir.mkdirs(); } return mainWorldDir; } }
public QueuedChunk(int x, int z, AnvilChunkLoader loader, World world, ChunkProviderServer provider) { this.x = x; this.z = z; this.loader = loader; this.world = world; this.provider = provider; }
/** * @author jamierocks - 30th October 2016 * @reason Use the Canary directory structure */ @Overwrite public IChunkLoader getChunkLoader(WorldProvider provider) { if (provider instanceof WorldProviderHell) { return new AnvilChunkLoader(new File(this.getWorldDirectory(), this.getWorldDirectoryName() + "_" + DimensionType.NETHER.getName())); } else if (provider instanceof WorldProviderEnd) { return new AnvilChunkLoader(new File(this.getWorldDirectory(), this.getWorldDirectoryName() + "_" + DimensionType.END.getName())); } else { return new AnvilChunkLoader(new File(this.getWorldDirectory(), this.getWorldDirectoryName() + "_" + DimensionType.NORMAL.getName())); } }
/** Load the previously saved TileEntities and add them to the Chunk **/ public static void importTileEntities( Chunk chunk ) { File chunkSaveLocation = (File) Reflexion.stealField( AnvilChunkLoader.class, File.class ).get(chunkLoader); DataInputStream dis = RegionFileCache.getChunkInputStream( chunkSaveLocation, chunk.xPosition, chunk.zPosition ); try { NBTTagCompound chunkNBT = CompressedStreamTools.read( dis ); NBTTagCompound levelNBT = chunkNBT.getCompoundTag( "Level" ); // The official code checks if the chunk is in the right location. Should I too?. NBTTagList tileEntitiesNBT = levelNBT.getTagList( "TileEntities" ); for( int i = 0; i < tileEntitiesNBT.tagCount(); i++ ) { NBTTagCompound tileEntityNBT = (NBTTagCompound) tileEntitiesNBT.tagAt( i ); TileEntity te = TileEntity.createAndLoadEntity( tileEntityNBT ); String entityType = getTEName(te); if(( isImportableTileEntity( te ) )) { if( ! newTileEntities.contains( new ChunkPosition( te.xCoord, te.yCoord, te.zCoord ) ) ) { wc.setBlockTileEntity( te.xCoord, te.yCoord, te.zCoord, te ); chatDebug("Loaded TE: " + entityType + " at " + te.xCoord + " " + te.yCoord + " " + te.zCoord ); } else { chatDebug( "Dropping old TE: " + entityType + " at " + te.xCoord + " " + te.yCoord + " " + te.zCoord ); } } else { chatDebug( "TE is not importable: " + entityType + " at " + te.xCoord + " " + te.yCoord + " " + te.zCoord ); } } } catch ( Exception e ) { } // Couldn't load the old chunk. Nothing unusual. Happens with every not downloaded chunk. }
public IChunkLoader func_75763_a(WorldProvider p_75763_1_) { File var2 = this.func_75765_b(); File var3; if(p_75763_1_ instanceof WorldProviderHell) { var3 = new File(var2, "DIM-1"); var3.mkdirs(); return new AnvilChunkLoader(var3); } else if(p_75763_1_ instanceof WorldProviderEnd) { var3 = new File(var2, "DIM1"); var3.mkdirs(); return new AnvilChunkLoader(var3); } else { return new AnvilChunkLoader(var2); } }
protected static File getWorldSaveDir(World world) { ISaveHandler worldSaver = world.getSaveHandler(); if (worldSaver.getChunkLoader(world.provider) instanceof AnvilChunkLoader) { return ((AnvilChunkLoader) worldSaver.getChunkLoader(world.provider)).chunkSaveLocation; } return null; }
private static boolean chunkIsSaved(World world, int chunkX, int chunkZ) { if (world.getChunkProvider() instanceof ChunkProviderServer) { IChunkLoader loader = ((ChunkProviderServer)world.getChunkProvider()).chunkLoader; if (loader instanceof AnvilChunkLoader) { //if (((AnvilChunkLoader) loader).chunkExists(world, chunkX, chunkZ)) // CustomOreGenBase.log.info("[" + chunkX + "," + chunkZ + "]: saved on disk"); return ((AnvilChunkLoader) loader).chunkExists(world, chunkX, chunkZ); } } return false; }
ChunkIOProvider(QueuedChunk chunk, AnvilChunkLoader loader, ChunkProviderServer provider) { this.chunkInfo = chunk; this.loader = loader; this.provider = provider; }
public static DataFixer createFixer() { DataFixer datafixer = new DataFixer(512); WorldInfo.registerFixes(datafixer); EntityPlayer.registerFixesPlayer(datafixer); AnvilChunkLoader.registerFixes(datafixer); ItemStack.registerFixes(datafixer); EntityArmorStand.registerFixesArmorStand(datafixer); EntityArrow.registerFixesArrow(datafixer); EntityBat.registerFixesBat(datafixer); EntityBlaze.registerFixesBlaze(datafixer); EntityCaveSpider.registerFixesCaveSpider(datafixer); EntityChicken.registerFixesChicken(datafixer); EntityCow.registerFixesCow(datafixer); EntityCreeper.registerFixesCreeper(datafixer); EntityDragonFireball.registerFixesDragonFireball(datafixer); EntityDragon.registerFixesDragon(datafixer); EntityEnderman.registerFixesEnderman(datafixer); EntityEndermite.registerFixesEndermite(datafixer); EntityFallingBlock.registerFixesFallingBlock(datafixer); EntityLargeFireball.registerFixesLargeFireball(datafixer); EntityFireworkRocket.registerFixesFireworkRocket(datafixer); EntityGhast.registerFixesGhast(datafixer); EntityGiantZombie.registerFixesGiantZombie(datafixer); EntityGuardian.registerFixesGuardian(datafixer); EntityHorse.registerFixesHorse(datafixer); EntityItem.registerFixesItem(datafixer); EntityItemFrame.registerFixesItemFrame(datafixer); EntityMagmaCube.registerFixesMagmaCube(datafixer); EntityMinecartChest.registerFixesMinecartChest(datafixer); EntityMinecartCommandBlock.registerFixesMinecartCommand(datafixer); EntityMinecartFurnace.registerFixesMinecartFurnace(datafixer); EntityMinecartHopper.registerFixesMinecartHopper(datafixer); EntityMinecartEmpty.registerFixesMinecartEmpty(datafixer); EntityMinecartMobSpawner.registerFixesMinecartMobSpawner(datafixer); EntityMinecartTNT.registerFixesMinecartTNT(datafixer); EntityLiving.registerFixesMob(datafixer); EntityMob.registerFixesMonster(datafixer); EntityMooshroom.registerFixesMooshroom(datafixer); EntityOcelot.registerFixesOcelot(datafixer); EntityPig.registerFixesPig(datafixer); EntityPigZombie.registerFixesPigZombie(datafixer); EntityRabbit.registerFixesRabbit(datafixer); EntitySheep.registerFixesSheep(datafixer); EntityShulker.registerFixesShulker(datafixer); EntitySilverfish.registerFixesSilverfish(datafixer); EntitySkeleton.registerFixesSkeleton(datafixer); EntitySlime.registerFixesSlime(datafixer); EntitySmallFireball.registerFixesSmallFireball(datafixer); EntitySnowman.registerFixesSnowman(datafixer); EntitySnowball.registerFixesSnowball(datafixer); EntitySpectralArrow.registerFixesSpectralArrow(datafixer); EntitySpider.registerFixesSpider(datafixer); EntitySquid.registerFixesSquid(datafixer); EntityEgg.registerFixesEgg(datafixer); EntityEnderPearl.registerFixesEnderPearl(datafixer); EntityExpBottle.registerFixesExpBottle(datafixer); EntityPotion.registerFixesPotion(datafixer); EntityTippedArrow.registerFixesTippedArrow(datafixer); EntityVillager.registerFixesVillager(datafixer); EntityIronGolem.registerFixesIronGolem(datafixer); EntityWitch.registerFixesWitch(datafixer); EntityWither.registerFixesWither(datafixer); EntityWitherSkull.registerFixesWitherSkull(datafixer); EntityWolf.registerFixesWolf(datafixer); EntityZombie.registerFixesZombie(datafixer); TileEntityPiston.registerFixesPiston(datafixer); TileEntityFlowerPot.registerFixesFlowerPot(datafixer); TileEntityFurnace.registerFixesFurnace(datafixer); TileEntityChest.registerFixesChest(datafixer); TileEntityDispenser.registerFixes(datafixer); TileEntityDropper.registerFixesDropper(datafixer); TileEntityBrewingStand.registerFixesBrewingStand(datafixer); TileEntityHopper.registerFixesHopper(datafixer); BlockJukebox.registerFixesJukebox(datafixer); TileEntityMobSpawner.registerFixesMobSpawner(datafixer); registerFixes(datafixer); return datafixer; }
public static void init() { if (!init) { Field[] f = ChunkProviderServer.class.getDeclaredFields(); for(int i = 0; i < f.length; i++) { if((unloadqueue == null) && f[i].getType().isAssignableFrom(java.util.Set.class)) { unloadqueue = f[i]; //Log.info("Found unloadqueue - " + f[i].getName()); unloadqueue.setAccessible(true); } else if((currentchunkloader == null) && f[i].getType().isAssignableFrom(IChunkLoader.class)) { currentchunkloader = f[i]; //Log.info("Found currentchunkprovider - " + f[i].getName()); currentchunkloader.setAccessible(true); } } f = WorldServer.class.getDeclaredFields(); for(int i = 0; i < f.length; i++) { if((updateEntityTick == null) && f[i].getType().isAssignableFrom(int.class)) { updateEntityTick = f[i]; //Log.info("Found updateEntityTick - " + f[i].getName()); updateEntityTick.setAccessible(true); } } f = AnvilChunkLoader.class.getDeclaredFields(); for(int i = 0; i < f.length; i++) { if((chunksToRemove == null) && (f[i].getType().equals(List.class))) { chunksToRemove = f[i]; chunksToRemove.setAccessible(true); } else if((pendingAnvilChunksCoordinates == null) && (f[i].getType().equals(Set.class))) { pendingAnvilChunksCoordinates = f[i]; pendingAnvilChunksCoordinates.setAccessible(true); } else if((syncLockObject == null) && (f[i].getType().equals(Object.class))) { syncLockObject = f[i]; syncLockObject.setAccessible(true); } else if((chunkSaveLocation == null) && (f[i].getType().equals(File.class))) { chunkSaveLocation = f[i]; chunkSaveLocation.setAccessible(true); } } // Get writeChunkToNBT method Method[] ma = AnvilChunkLoader.class.getDeclaredMethods(); for (Method m : ma) { Class<?>[] p = m.getParameterTypes(); if ((p.length == 3) && (p[0].equals(Chunk.class)) && (p[1].equals(World.class)) && (p[2].equals(NBTTagCompound.class))) { writechunktonbt = m; m.setAccessible(true); break; } } if ((unloadqueue == null) || (currentchunkloader == null) || (writechunktonbt == null)) { Log.severe("ERROR: cannot find unload queue or chunk provider field - dynmap cannot load chunks"); } if (updateEntityTick == null) { Log.severe("ERROR: cannot find updateEntityTick - dynmap cannot drive entity cleanup when no players are active"); } init = true; } }
public File getChunkSaveLocation() { return ((AnvilChunkLoader) theChunkProviderServer.currentChunkLoader).chunkSaveLocation; }
public static Chunk syncChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z) { return instance.getSkipQueue(new QueuedChunk(x, z, loader, world, provider)); }
public static void queueChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) { instance.add(new QueuedChunk(x, z, loader, world, provider), runnable); }
/** * Callback for when the command is executed */ public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length < 1) { throw new WrongUsageException("commands.summon.usage", new Object[0]); } else { String s = args[0]; BlockPos blockpos = sender.getPosition(); Vec3d vec3d = sender.getPositionVector(); double d0 = vec3d.xCoord; double d1 = vec3d.yCoord; double d2 = vec3d.zCoord; if (args.length >= 4) { d0 = parseDouble(d0, args[1], true); d1 = parseDouble(d1, args[2], false); d2 = parseDouble(d2, args[3], true); blockpos = new BlockPos(d0, d1, d2); } World world = sender.getEntityWorld(); if (!world.isBlockLoaded(blockpos)) { throw new CommandException("commands.summon.outOfWorld", new Object[0]); } else if ("LightningBolt".equals(s)) { world.addWeatherEffect(new EntityLightningBolt(world, d0, d1, d2, false)); notifyCommandListener(sender, this, "commands.summon.success", new Object[0]); } else { NBTTagCompound nbttagcompound = new NBTTagCompound(); boolean flag = false; if (args.length >= 5) { ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 4); try { nbttagcompound = JsonToNBT.getTagFromJson(itextcomponent.getUnformattedText()); flag = true; } catch (NBTException nbtexception) { throw new CommandException("commands.summon.tagError", new Object[] {nbtexception.getMessage()}); } } nbttagcompound.setString("id", s); Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, true); if (entity == null) { throw new CommandException("commands.summon.failed", new Object[0]); } else { entity.setLocationAndAngles(d0, d1, d2, entity.rotationYaw, entity.rotationPitch); if (!flag && entity instanceof EntityLiving) { ((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null); } notifyCommandListener(sender, this, "commands.summon.success", new Object[0]); } } } }
public File getChunkSaveLocation() { return ((AnvilChunkLoader)theChunkProviderServer.currentChunkLoader).chunkSaveLocation; }
public void plan(IChunkProvider chunkProvider, World world, int chunkX, int chunkZ, Block[] blocks) { if (!this.allowedInWorld(world)) { //Physis.logger.info("NOT VALID DIM"); return; } if (!(world.getChunkProvider() instanceof ChunkProviderServer)) { //Physis.logger.info("NOT CPS"); return; } ChunkProviderServer cps = (ChunkProviderServer)world.getChunkProvider(); if (!(cps.currentChunkLoader instanceof AnvilChunkLoader)) { //Physis.logger.info("NOT ACL"); return; } AnvilChunkLoader acl = (AnvilChunkLoader)cps.currentChunkLoader; // check around this chunk for (int rx=-this.radius; rx<=this.radius; rx++) { scan: for (int rz=-this.radius; rz<=this.radius; rz++) { long coordhash = StructureData.idFromCoords(chunkX+rx, chunkZ+rz); if (!this.structureMap.containsKey(world)) { this.structureMap.put(world, new HashMap<Long, StructureData>()); } if (this.structureMap.get(world).containsKey(coordhash)) { //Physis.logger.info("Duplicate"); continue; } if (this.canGenerateInChunk(world, chunkX + rx, chunkZ + rz)) { // ok, we can generate in the found chunk - find out if only the source chunk was generated for (int sx=-this.radius; sx<=this.radius; sx++) { for (int sz=-this.radius; sz<=this.radius; sz++) { int checkX = chunkX + rx + sx; int checkZ = chunkZ + rz + sz; if (checkX == chunkX || checkZ == chunkZ) { continue; } if (acl.chunkExists(world, checkX, checkZ)) { //Physis.logger.info("Rejected structure at "+(chunkX + rx)+","+(chunkZ + rz)+" due to generated chunk at "+checkX+","+checkZ); continue scan; } } } StructureData sdata = this.createStructureInChunk(world, chunkX + rx, chunkZ + rz); if (!this.structureMap.containsKey(world)) { this.structureMap.put(world, new HashMap<Long, StructureData>()); } this.structureMap.get(world).put(sdata.id, sdata); //Physis.logger.info("Generating a new structure at chunk "+sdata.x+","+sdata.z); //saveGeneratorsToWorldData(); } } } }