Java Code Examples for net.minecraft.world.World#getChunkProvider()

The following examples show how to use net.minecraft.world.World#getChunkProvider() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private boolean canParticlePassThrough(World world, BlockPos pos) {
    ChunkProviderServer serverProvider = (ChunkProviderServer) world.getChunkProvider();
    // If the chunk isn't loaded, then no problem ignore it.
    long chunkKey = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
    if (!serverProvider.loadedChunks.containsKey(chunkKey)) {
        this.isParticleDead = true;
        return true;
    }
    IBlockState collisionState = serverProvider.loadedChunks.get(chunkKey)
        .getBlockState(pos);
    // Otherwise we have to bypass the world blockstate get because sponge has some protection on it.
    // System.out.println("oof");
    return collisionState.getBlock().isPassable(world, pos);
}
 
Example 2
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 3
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 4
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.originalLoadChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 5
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
    IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;

    long pos = ChunkCoordIntPair.chunkXZ2Int(x, z);
    Chunk mcChunk;
    if (chunkServer.chunkExists(x, z)) {
        mcChunk = chunkServer.loadChunk(x, z);
        mcChunk.onChunkUnload();
    }
    try {
        Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
        droppedChunksSetField.setAccessible(true);
        Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
        droppedChunksSet.remove(pos);
    } catch (Throwable e) {
        MainUtil.handleError(e);
    }
    chunkServer.id2ChunkMap.remove(pos);
    mcChunk = chunkProvider.provideChunk(x, z);
    chunkServer.id2ChunkMap.add(pos, mcChunk);
    chunkServer.loadedChunks.add(mcChunk);
    if (mcChunk != null) {
        mcChunk.onChunkLoad();
        mcChunk.populateChunk(chunkProvider, chunkProvider, x, z);
    }
    return true;
}
 
Example 6
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 7
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 8
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.originalLoadChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 9
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 10
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 11
private FakeWorldServer(World world) {

        super(MinecraftServer.getServer(), new NonSavingHandler(), world.getWorldInfo().getWorldName(), world.provider.dimensionId,
                new WorldSettings(world.getWorldInfo()), world.theProfiler);
        DimensionManager.setWorld(world.provider.dimensionId, (WorldServer) world);

        chunkProvider = world.getChunkProvider();
    }
 
Example 12
Source Project: BigReactors   File: BRSimpleOreGenerator.java    License: MIT License 5 votes vote down vote up
/**
 * Call to discover if this generator WISHES to generate in this world.
 * @param world
 * @return
 */
public boolean shouldGenerateInWorld(World world) {
	IChunkProvider chunkProvider = world.getChunkProvider();
	if(dimensionBlacklist.contains(world.provider.dimensionId)) {
		return false;
	}
	else if(chunkProvider instanceof ChunkProviderHell) {
		return false;
	}
	else if(chunkProvider instanceof ChunkProviderEnd) {
		return false;
	}

	return true;
}
 
Example 13
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }


    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}
 
Example 14
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = chunkServer.id2ChunkMap;
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 15
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}
 
Example 16
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 17
Source Project: AdvancedRocketry   File: SatelliteOreMapping.java    License: MIT License 4 votes vote down vote up
public static int[][] scanChunk(World world, int offsetX, int offsetZ, int radius, int blocksPerPixel, ItemStack block) {
	blocksPerPixel = Math.max(blocksPerPixel, 1);
	int[][] ret = new int[(radius*2)/blocksPerPixel][(radius*2)/blocksPerPixel];

	Chunk chunk = world.getChunkFromChunkCoords(offsetX << 4, offsetZ << 4);
	IChunkProvider provider = world.getChunkProvider();


	for(int z = -radius; z < radius; z+=blocksPerPixel){
		for(int x = -radius; x < radius; x+=blocksPerPixel) {
			int oreCount = 0, otherCount = 0;


			for(int y = world.getHeight(); y > 0; y--) {
				for(int deltaY = 0; deltaY < blocksPerPixel; deltaY++) {
					for(int deltaZ = 0; deltaZ < blocksPerPixel; deltaZ++) {

						BlockPos pos = new BlockPos(x + offsetX, y, z + offsetZ);
						if(world.isAirBlock(pos))
							continue;

						//Note:May not work with tileEntities (GT ores)
						boolean found = false;
						List<ItemStack> drops;
						IBlockState state = world.getBlockState(pos);
						if((drops = state.getBlock().getDrops(world,pos, state, 0)) != null)
							for(ItemStack stack : drops) {
								if(stack.getItem() == block.getItem() && stack.getItemDamage() == block.getItemDamage()) {
									oreCount++;
									found = true;
								}
							}

						if(!found)
							otherCount++;
					}
				}
			}
			oreCount /= Math.pow(blocksPerPixel,2);
			otherCount /= Math.pow(blocksPerPixel,2);

			if(Thread.interrupted())
				return null;


			ret[(x+radius)/blocksPerPixel][(z+radius)/blocksPerPixel] = (int)((oreCount/(float)Math.max(otherCount,1))*0xFFFF);
		}
	}

	return ret;
}
 
Example 18
Source Project: AdvancedRocketry   File: SatelliteOreMapping.java    License: MIT License 4 votes vote down vote up
/**
 * Note: array returned will be [radius/blocksPerPixel][radius/blocksPerPixel]
 * @param world
 * @param offsetX
 * @param offsetY
 * @param radius in blocks
 * @param blocksPerPixel number of blocks squared (n*n) that take up one pixel
 * @return array of ore vs other block values
 */
public static int[][] scanChunk(World world, int offsetX, int offsetZ, int radius, int blocksPerPixel) {
	blocksPerPixel = Math.max(blocksPerPixel, 1);
	int[][] ret = new int[(radius*2)/blocksPerPixel][(radius*2)/blocksPerPixel];

	Chunk chunk = world.getChunkFromChunkCoords(offsetX << 4, offsetZ << 4);
	IChunkProvider provider = world.getChunkProvider();

	if(oreList.isEmpty()) {
		String[] strings = OreDictionary.getOreNames();
		for(String str : strings) {
			if(str.startsWith("ore") || str.startsWith("dust") || str.startsWith("gem"))
				oreList.add(OreDictionary.getOreID(str));
		}
	}

	for(int z = -radius; z < radius; z+=blocksPerPixel){
		for(int x = -radius; x < radius; x+=blocksPerPixel) {
			int oreCount = 0, otherCount = 0;


			for(int y = world.getHeight(); y > 0; y--) {
				for(int deltaY = 0; deltaY < blocksPerPixel; deltaY++) {
					for(int deltaZ = 0; deltaZ < blocksPerPixel; deltaZ++) {

						BlockPos pos = new BlockPos(x + offsetX, y, z + offsetZ);
						if(world.isAirBlock(pos))
							continue;
						boolean exists = false;
						out:
							for(int i : oreList) {
								List<ItemStack> itemlist = OreDictionary.getOres(OreDictionary.getOreName(i));

								for(ItemStack item : itemlist) {
									if(item.getItem() == Item.getItemFromBlock(world.getBlockState(pos).getBlock())) {
										exists = true;
										break out;
									}
								}
							}
						if(exists)
							oreCount++;
						else
							otherCount++;
					}
				}
			}
			oreCount /= Math.pow(blocksPerPixel,2);
			otherCount /= Math.pow(blocksPerPixel,2);

			if(Thread.interrupted())
				return null;


			ret[(x+radius)/blocksPerPixel][(z+radius)/blocksPerPixel] = (int)((oreCount/(float)Math.max(otherCount,1))*0xFFFF);
		}
	}

	return ret;
}