Java Code Examples for net.minecraft.util.math.ChunkPos

The following are top voted examples for showing how to use net.minecraft.util.math.ChunkPos. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CustomWorldGen   File: AnvilChunkLoader.java   Source Code and License 6 votes vote down vote up
public Object[] loadChunk__Async(World worldIn, int x, int z) throws IOException
{
    ChunkPos chunkpos = new ChunkPos(x, z);
    NBTTagCompound nbttagcompound = (NBTTagCompound)this.chunksToRemove.get(chunkpos);

    if (nbttagcompound == null)
    {
        DataInputStream datainputstream = RegionFileCache.getChunkInputStream(this.chunkSaveLocation, x, z);

        if (datainputstream == null)
        {
            return null;
        }

        nbttagcompound = this.dataFixer.process(FixTypes.CHUNK, CompressedStreamTools.read(datainputstream));
    }

    return this.checkedReadChunkFromNBT__Async(worldIn, x, z, nbttagcompound);
}
 
Example 2
Project: CustomWorldGen   File: ChunkIOProvider.java   Source Code and License 6 votes vote down vote up
public void syncCallback()
{
    if (chunk == null)
    {
        this.runCallbacks();
        return;
    }

    // Load Entities
    this.loader.loadEntities(this.chunkInfo.world, this.nbt.getCompoundTag("Level"), this.chunk);

    MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(this.chunk, this.nbt)); // Don't call ChunkDataEvent.Load async

    this.chunk.setLastSaveTime(provider.worldObj.getTotalWorldTime());
    this.provider.chunkGenerator.recreateStructures(this.chunk, this.chunkInfo.x, this.chunkInfo.z);

    provider.id2ChunkMap.put(ChunkPos.asLong(this.chunkInfo.x, this.chunkInfo.z), this.chunk);
    this.chunk.onChunkLoad();
    this.chunk.populateChunk(provider, provider.chunkGenerator);

    this.runCallbacks();
}
 
Example 3
Project: Backmemed   File: WorldClient.java   Source Code and License 6 votes vote down vote up
public WorldClient(NetHandlerPlayClient netHandler, WorldSettings settings, int dimension, EnumDifficulty difficulty, Profiler profilerIn)
{
    super(new SaveHandlerMP(), new WorldInfo(settings, "MpServer"), makeWorldProvider(dimension), profilerIn, true);
    this.ambienceTicks = this.rand.nextInt(12000);
    this.viewableChunks = Sets.<ChunkPos>newHashSet();
    this.connection = netHandler;
    this.getWorldInfo().setDifficulty(difficulty);
    this.provider.registerWorld(this);
    this.setSpawnPoint(new BlockPos(8, 64, 8));
    this.chunkProvider = this.createChunkProvider();
    this.mapStorage = new SaveDataMemoryStorage();
    this.calculateInitialSkylight();
    this.calculateInitialWeather();
    Reflector.call(this, Reflector.ForgeWorld_initCapabilities, new Object[0]);
    Reflector.postForgeBusEvent(Reflector.WorldEvent_Load_Constructor, new Object[] {this});

    if (this.mc.playerController != null && this.mc.playerController.getClass() == PlayerControllerMP.class)
    {
        this.mc.playerController = new PlayerControllerOF(this.mc, netHandler);
    }
}
 
Example 4
Project: CustomWorldGen   File: WorldClient.java   Source Code and License 6 votes vote down vote up
public WorldClient(NetHandlerPlayClient netHandler, WorldSettings settings, int dimension, EnumDifficulty difficulty, Profiler profilerIn)
{
    super(new SaveHandlerMP(), new WorldInfo(settings, "MpServer"), net.minecraftforge.common.DimensionManager.createProviderFor(dimension), profilerIn, true);
    this.ambienceTicks = this.rand.nextInt(12000);
    this.viewableChunks = Sets.<ChunkPos>newHashSet();
    this.connection = netHandler;
    this.getWorldInfo().setDifficulty(difficulty);
    this.provider.registerWorld(this);
    this.setSpawnPoint(new BlockPos(8, 64, 8)); //Forge: Moved below registerWorld to prevent NPE in our redirect.
    this.chunkProvider = this.createChunkProvider();
    this.mapStorage = new SaveDataMemoryStorage();
    this.calculateInitialSkylight();
    this.calculateInitialWeather();
    this.initCapabilities();
    net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(this));
}
 
Example 5
Project: Loot-Slash-Conquer   File: EventEntityJoinWorld.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
	if (event.getEntity() instanceof EntityLivingBase && !(event.getEntity() instanceof EntityPlayer))
	{
		EntityLivingBase entity = (EntityLivingBase) event.getEntity();
		World world = entity.getEntityWorld();
		IEnemyLevel enemyLevelCap = entity.getCapability(CapabilityEnemyLevel.ENEMY_LEVEL, null);
		IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
		
		if (enemyLevelCap != null && chunkLevelHolder != null)
		{
			if (enemyLevelCap.getEnemyLevel() == 0)
			{
				IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(new ChunkPos(entity.getPosition()));
				int level = chunkLevel.getChunkLevel();
				
				enemyLevelCap.setEnemyLevel(level);
				entity.setCustomNameTag("Level: " + enemyLevelCap.getEnemyLevel());
				
				if (level > 1) setAttributeModifiers(entity, level);
			}
		}
	}
}
 
Example 6
Project: Loot-Slash-Conquer   File: ItemShadowfall.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.DEXTERITY.addAttribute(nbt, 10);
	WeaponAttribute.MAX_DAMAGE.addAttribute(nbt, 3);
	WeaponAttribute.LIFE_STEAL.addAttribute(nbt, 0.15);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 7
Project: Loot-Slash-Conquer   File: ItemDivineRapier.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.FIRE.addAttribute(nbt, 5);
	WeaponAttribute.STRENGTH.addAttribute(nbt, 3);
	WeaponAttribute.DURABLE.addAttribute(nbt, 0.3);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 8
Project: Loot-Slash-Conquer   File: ItemAlakaslam.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.EXOTIC);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.STRENGTH.addAttribute(nbt, 10);
	WeaponAttribute.FORTITUDE.addAttribute(nbt, 10);
	WeaponAttribute.FROST.addAttribute(nbt, 7);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 9
Project: Loot-Slash-Conquer   File: ItemGoldenPummel.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.FORTITUDE.addAttribute(nbt, 10);
	WeaponAttribute.LIGHTNING.addAttribute(nbt, 7);
	WeaponAttribute.MANA_STEAL.addAttribute(nbt, 0.2);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 10
Project: Loot-Slash-Conquer   File: ItemDoomshadow.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.STRENGTH.addAttribute(nbt, 6);
	WeaponAttribute.FORTITUDE.addAttribute(nbt, 4);
	WeaponAttribute.CHAINED.addAttribute(nbt, 10);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 11
Project: Loot-Slash-Conquer   File: ItemExcaliburRapier.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.EXOTIC);
	nbt.setInteger("Level", level);
	
	// Attributes
	WeaponAttribute.FIRE.addAttribute(nbt, 3);
	WeaponAttribute.FROST.addAttribute(nbt, 3);
	WeaponAttribute.LIGHTNING.addAttribute(nbt, 3);
	WeaponAttribute.STRENGTH.addAttribute(nbt, 8);
	
	ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
}
 
Example 12
Project: Loot-Slash-Conquer   File: ItemBlazefury.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	ItemGeneratorHelper.setRune(nbt);
	
	// Attributes
	WeaponAttribute.FIRE.addAttribute(nbt, 3);
	WeaponAttribute.FROST.addAttribute(nbt, 3);
	WeaponAttribute.LIGHTNING.addAttribute(nbt, 3);
	
	// Damage and Attack Speed
	double baseDamage = this.getBaseDamage();
	double baseAttackSpeed = this.getBaseAttackSpeed();
	double weightedDamage = ItemGeneratorHelper.getWeightedDamage(nbt, Rarity.getRarity(nbt), baseDamage);
	double weightedAttackSpeed = ItemGeneratorHelper.getWeightedAttackSpeed(Rarity.getRarity(nbt), baseAttackSpeed);
	
	ItemGeneratorHelper.setMinMaxDamage(nbt, weightedDamage);
	nbt.setDouble("AttackSpeed", weightedAttackSpeed);
}
 
Example 13
Project: Loot-Slash-Conquer   File: ItemGazeOfTruth.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.EXOTIC);
	nbt.setInteger("Level", level);
	ItemGeneratorHelper.setRune(nbt);
	
	// Attributes
	WeaponAttribute.FIRE.addAttribute(nbt, 5);
	WeaponAttribute.MIN_DAMAGE.addAttribute(nbt, 3);
	WeaponAttribute.FORTITUDE.addAttribute(nbt, 5);
	WeaponAttribute.CHAINED.addAttribute(nbt, 15);
	
	// Damage and Attack Speed
	double baseDamage = this.getBaseDamage();
	double baseAttackSpeed = this.getBaseAttackSpeed();
	double weightedDamage = ItemGeneratorHelper.getWeightedDamage(nbt, Rarity.getRarity(nbt), baseDamage);
	double weightedAttackSpeed = ItemGeneratorHelper.getWeightedAttackSpeed(Rarity.getRarity(nbt), baseAttackSpeed);
	
	ItemGeneratorHelper.setMinMaxDamage(nbt, weightedDamage);
	nbt.setDouble("AttackSpeed", weightedAttackSpeed);
}
 
Example 14
Project: Loot-Slash-Conquer   File: ItemMoonlitRod.java   Source Code and License 6 votes vote down vote up
@Override
public void createSpecial(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos) 
{
	IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
	IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
	int level = chunkLevel.getChunkLevel();
	
	Rarity.setRarity(nbt, Rarity.LEGENDARY);
	nbt.setInteger("Level", level);
	ItemGeneratorHelper.setRune(nbt);
	
	// Attributes
	WeaponAttribute.INTELLIGENCE.addAttribute(nbt, 3);
	WeaponAttribute.WISDOM.addAttribute(nbt, 3);
	WeaponAttribute.LIGHTNING.addAttribute(nbt, 5);
	
	// Damage and Attack Speed
	double baseDamage = this.getBaseDamage();
	double baseAttackSpeed = this.getBaseAttackSpeed();
	double weightedDamage = ItemGeneratorHelper.getWeightedDamage(nbt, Rarity.getRarity(nbt), baseDamage);
	double weightedAttackSpeed = ItemGeneratorHelper.getWeightedAttackSpeed(Rarity.getRarity(nbt), baseAttackSpeed);
	
	ItemGeneratorHelper.setMinMaxDamage(nbt, weightedDamage);
	nbt.setDouble("AttackSpeed", weightedAttackSpeed);
}
 
Example 15
Project: harshencastle   File: VolatileChunkProvider.java   Source Code and License 6 votes vote down vote up
@Override
public Chunk provideChunk(int x, int z) {
	Chunk chunk = this.loadChunk(x, z);

	if (chunk == null) {
		long i = ChunkPos.asLong(x, z);

		try {
			chunk = ((IChunkProvider) chunkGenerator).provideChunk(x, z);
		}
		catch (Throwable throwable) {
			CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception generating new chunk");
			CrashReportCategory crashreportcategory = crashreport.makeCategory("Chunk to be generated");
			crashreportcategory.addCrashSection("Location",
					String.format("%d,%d", new Object[] { Integer.valueOf(x), Integer.valueOf(z) }));
			crashreportcategory.addCrashSection("Position hash", Long.valueOf(i));
			crashreportcategory.addCrashSection("Generator", chunkGenerator);
			throw new ReportedException(crashreport);
		}

		id2ChunkMap.put(i, chunk);
		chunk.onLoad();
	}

	return chunk;
}
 
Example 16
Project: CustomWorldGen   File: ForgeChunkManager.java   Source Code and License 6 votes vote down vote up
public static Iterator<Chunk> getPersistentChunksIterableFor(final World world, Iterator<Chunk> chunkIterator)
{
    final ImmutableSetMultimap<ChunkPos, Ticket> persistentChunksFor = getPersistentChunksFor(world);
    final ImmutableSet.Builder<Chunk> builder = ImmutableSet.builder();
    world.theProfiler.startSection("forcedChunkLoading");
    builder.addAll(Iterators.transform(persistentChunksFor.keys().iterator(), new Function<ChunkPos, Chunk>() {
        @Nullable
        @Override
        public Chunk apply(@Nullable ChunkPos input)
        {
            return world.getChunkFromChunkCoords(input.chunkXPos, input.chunkZPos);
        }
    }));
    world.theProfiler.endStartSection("regularChunkLoading");
    builder.addAll(chunkIterator);
    world.theProfiler.endSection();
    return builder.build().iterator();
}
 
Example 17
Project: InControl   File: StructureCache.java   Source Code and License 6 votes vote down vote up
public boolean isInStructure(World world, String structure, BlockPos pos) {
    int dimension = world.provider.getDimension();
    ChunkPos cp = new ChunkPos(pos);
    long cplong = ChunkPos.asLong(cp.chunkXPos, cp.chunkZPos);
    StructureCacheEntry entry = new StructureCacheEntry(structure, dimension, cplong);
    if (structureCache.containsKey(entry)) {
        return structureCache.get(entry);
    }

    MapGenStructureData data = (MapGenStructureData) world.getPerWorldStorage().getOrLoadData(MapGenStructureData.class, structure);
    if (data == null) {
        return false;
    }

    Set<Long> longs = parseStructureData(data);
    for (Long l : longs) {
        structureCache.put(new StructureCacheEntry(structure, dimension, l), true);
    }
    if (structureCache.containsKey(entry)) {
        return true;
    } else {
        structureCache.put(entry, false);
        return false;
    }
}
 
Example 18
Project: Etheric   File: WorldGenRift.java   Source Code and License 6 votes vote down vote up
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {

	if (!worldIn.isRemote && StabilityHandler.getChunkStability(worldIn.provider.getDimension(),
			new ChunkPos(position)) < 0.65F) {
		if (Config.RIFT_FREQUENCY > 0 && rand.nextInt(Config.RIFT_FREQUENCY) == 0) {
			int x = position.getX() + rand.nextInt(16);
			int z = position.getZ() + rand.nextInt(16);
			BlockPos genPos = worldIn.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).up(rand.nextInt(3) + 2);

			for (int i = 0; i < 5; i++) {
				if (!worldIn.isAirBlock(genPos.up(i))) {
					return false;
				}
			}
			worldIn.setBlockState(genPos, RegistryManager.rift.getDefaultState());
			return true;
		}
	}

	return false;
}
 
Example 19
Project: Etheric   File: StabilityHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public static void onServerWorldTick(TickEvent.WorldTickEvent event) {
	if (event.side != Side.CLIENT) {

		int dim = event.world.provider.getDimension();
		if (ticks % 20 == 0) {
			for (ChunkPos pos : getDirtyChunks(dim)) {
				event.world.markChunkDirty(new BlockPos(pos.x << 4, 16, pos.z << 4), null);
			}
			getDirtyChunks(dim).clear();

			// for (InstabilityEvent e : instabilityEvents.get(dim)) {
			// e.affectChunk(event.world);
			// }
			// instabilityEvents.clear();
		}

		ticks++;
	}
}
 
Example 20
Project: CustomWorldGen   File: MapGenStronghold.java   Source Code and License 6 votes vote down vote up
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
    if (!this.ranBiomeCheck)
    {
        this.generatePositions();
        this.ranBiomeCheck = true;
    }

    for (ChunkPos chunkpos : this.structureCoords)
    {
        if (chunkX == chunkpos.chunkXPos && chunkZ == chunkpos.chunkZPos)
        {
            return true;
        }
    }

    return false;
}
 
Example 21
Project: modName   File: Tile.java   Source Code and License 6 votes vote down vote up
private ChunkPos[][] createChunkArray()
{
	ChunkPos[][] chunkArray = new ChunkPos[4][4];
	
	for(int i=0; i<4; i++)
	{
		for(int j=0; j<4; j++)
		{
			int chunkZ = this.tilePosition.z * 4 + j;
			int chunkX = this.tilePosition.x * 4 - 2 * (this.tilePosition.z % 2);
			
			chunkArray[i][j] = new ChunkPos(chunkX, chunkZ);
		}
	}
	
	return chunkArray;
}
 
Example 22
Project: Backmemed   File: MapGenStronghold.java   Source Code and License 6 votes vote down vote up
public MapGenStronghold(Map<String, String> p_i2068_1_)
{
    this();

    for (Entry<String, String> entry : p_i2068_1_.entrySet())
    {
        if (((String)entry.getKey()).equals("distance"))
        {
            this.distance = MathHelper.getDouble((String)entry.getValue(), this.distance, 1.0D);
        }
        else if (((String)entry.getKey()).equals("count"))
        {
            this.structureCoords = new ChunkPos[MathHelper.getInt((String)entry.getValue(), this.structureCoords.length, 1)];
        }
        else if (((String)entry.getKey()).equals("spread"))
        {
            this.spread = MathHelper.getInt((String)entry.getValue(), this.spread, 1);
        }
    }
}
 
Example 23
Project: CustomWorldGen   File: MapGenStronghold.java   Source Code and License 6 votes vote down vote up
public MapGenStronghold(Map<String, String> p_i2068_1_)
{
    this();

    for (Entry<String, String> entry : p_i2068_1_.entrySet())
    {
        if (((String)entry.getKey()).equals("distance"))
        {
            this.distance = MathHelper.parseDoubleWithDefaultAndMax((String)entry.getValue(), this.distance, 1.0D);
        }
        else if (((String)entry.getKey()).equals("count"))
        {
            this.structureCoords = new ChunkPos[MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.structureCoords.length, 1)];
        }
        else if (((String)entry.getKey()).equals("spread"))
        {
            this.spread = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.spread, 1);
        }
    }
}
 
Example 24
Project: CustomWorldGen   File: StructureOceanMonument.java   Source Code and License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound tagCompound)
{
    super.writeToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

    for (ChunkPos chunkpos : this.processed)
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        nbttagcompound.setInteger("X", chunkpos.chunkXPos);
        nbttagcompound.setInteger("Z", chunkpos.chunkZPos);
        nbttaglist.appendTag(nbttagcompound);
    }

    tagCompound.setTag("Processed", nbttaglist);
}
 
Example 25
Project: Backmemed   File: ChunkProviderServer.java   Source Code and License 5 votes vote down vote up
/**
 * Unloads a chunk
 */
public void unload(Chunk chunkIn)
{
    if (this.worldObj.provider.canDropChunk(chunkIn.xPosition, chunkIn.zPosition))
    {
        this.droppedChunksSet.add(Long.valueOf(ChunkPos.asLong(chunkIn.xPosition, chunkIn.zPosition)));
        chunkIn.unloaded = true;
    }
}
 
Example 26
Project: Backmemed   File: WorldServer.java   Source Code and License 5 votes vote down vote up
@Nullable
public List<NextTickListEntry> getPendingBlockUpdates(Chunk chunkIn, boolean p_72920_2_)
{
    ChunkPos chunkpos = chunkIn.getChunkCoordIntPair();
    int i = (chunkpos.chunkXPos << 4) - 2;
    int j = i + 16 + 2;
    int k = (chunkpos.chunkZPos << 4) - 2;
    int l = k + 16 + 2;
    return this.getPendingBlockUpdates(new StructureBoundingBox(i, 0, k, j, 256, l), p_72920_2_);
}
 
Example 27
Project: Backmemed   File: StructureOceanMonument.java   Source Code and License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound tagCompound)
{
    super.writeToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

    for (ChunkPos chunkpos : this.processed)
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        nbttagcompound.setInteger("X", chunkpos.chunkXPos);
        nbttagcompound.setInteger("Z", chunkpos.chunkZPos);
        nbttaglist.appendTag(nbttagcompound);
    }

    tagCompound.setTag("Processed", nbttaglist);
}
 
Example 28
Project: Loot-Slash-Conquer   File: ItemGenerator.java   Source Code and License 5 votes vote down vote up
/** Creates a melee weapon/armor with randomized stats. */
public static void create(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos)
{
	/*
	 * Set rarity
	 * Set level
	 * Generate attributes based on Rarity
	 * 		- Common: 0-1 attributes
	 * 		- Uncommon: 1-2 attributes
	 * 		- Rare: 2-3 attributes
	 * 		- Legendary: 3-4 attributes
	 * 		- Mythic: 4-5 attributes
	 * Generate base damage and base attack speed
	 * Generate name based on attributes + material/type
	 */
	
	if (Rarity.getRarity(nbt) != Rarity.DEFAULT)
	{
		IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
		IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
		int level = chunkLevel.getChunkLevel();
		
		//Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, ItemGeneratorHelper.rand)); // sets a random rarity
		ItemGeneratorHelper.setTypes(stack, nbt);
		nbt.setInteger("Level", level); // set level to current player level
		ItemGeneratorHelper.setRandomAttributes(stack, nbt, Rarity.getRarity(nbt));
		ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
		nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags
	}
}
 
Example 29
Project: modName   File: ChunkProviderBasic.java   Source Code and License 5 votes vote down vote up
public boolean populateFeatures(ChunkPos chunkpos) {
    boolean village = false;

    for (MapGenStructure mapgenstructure : this.structureGenerators)
    {
        boolean flag = mapgenstructure.generateStructure(this.world, this.random, chunkpos);

        if (mapgenstructure instanceof MapGenVillage)
        {
            village |= flag;
        }
    }

    return village;
}
 
Example 30
Project: Backmemed   File: MapGenStructure.java   Source Code and License 5 votes vote down vote up
protected void initializeStructureData(World worldIn)
{
    if (this.structureData == null)
    {
        this.structureData = (MapGenStructureData)worldIn.loadItemData(MapGenStructureData.class, this.getStructureName());

        if (this.structureData == null)
        {
            this.structureData = new MapGenStructureData(this.getStructureName());
            worldIn.setItemData(this.getStructureName(), this.structureData);
        }
        else
        {
            NBTTagCompound nbttagcompound = this.structureData.getTagCompound();

            for (String s : nbttagcompound.getKeySet())
            {
                NBTBase nbtbase = nbttagcompound.getTag(s);

                if (nbtbase.getId() == 10)
                {
                    NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbtbase;

                    if (nbttagcompound1.hasKey("ChunkX") && nbttagcompound1.hasKey("ChunkZ"))
                    {
                        int i = nbttagcompound1.getInteger("ChunkX");
                        int j = nbttagcompound1.getInteger("ChunkZ");
                        StructureStart structurestart = MapGenStructureIO.getStructureStart(nbttagcompound1, worldIn);

                        if (structurestart != null)
                        {
                            this.structureMap.put(ChunkPos.asLong(i, j), structurestart);
                        }
                    }
                }
            }
        }
    }
}
 
Example 31
Project: minecraft-territorialdealings   File: _FactionSaveData.java   Source Code and License 5 votes vote down vote up
public void removeChunk(ChunkPos pos) 
{
	_ChunkSaveData data = new _ChunkSaveData(pos, 0);
	
	if (this.chunkList.contains(data))	// Will compare by position
	{
		this.chunkList.remove(data);
	}
	// else, huh?
}
 
Example 32
Project: CustomWorldGen   File: ForgeChunkManager.java   Source Code and License 5 votes vote down vote up
/**
 * Reorganize the internal chunk list so that the chunk supplied is at the *end* of the list
 * This helps if you wish to guarantee a certain "automatic unload ordering" for the chunks
 * in the ticket list
 *
 * @param ticket The ticket holding the chunk list
 * @param chunk The chunk you wish to push to the end (so that it would be unloaded last)
 */
public static void reorderChunk(Ticket ticket, ChunkPos chunk)
{
    if (ticket == null || chunk == null || !ticket.requestedChunks.contains(chunk))
    {
        return;
    }
    ticket.requestedChunks.remove(chunk);
    ticket.requestedChunks.add(chunk);
}
 
Example 33
Project: harshencastle   File: VolatileChunkProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
public Chunk loadChunk(int x, int z, Runnable runnable) {
	Chunk chunk = getLoadedChunk(x, z);
	if (chunk == null) {
		long pos = ChunkPos.asLong(x, z);
		chunk = net.minecraftforge.common.ForgeChunkManager.fetchDormantChunk(pos, worldObj);
		if (chunk != null) {
			if (!loadingChunks.add(pos)) {
				net.minecraftforge.fml.common.FMLLog.bigWarning(
						"There is an attempt to load a chunk (%d,%d) in dimension %d that is already being loaded. This will cause weird chunk breakages.",
						x, z, worldObj.provider.getDimension());
			}

			if (chunk != null) {
				id2ChunkMap.put(ChunkPos.asLong(x, z), chunk);
				chunk.onLoad();
				chunk.populate(this, chunkGenerator);
			}

			loadingChunks.remove(pos);
		}
	}

	// If we didn't load the chunk async and have a callback run it now
	if (runnable != null) {
		runnable.run();
	}
	return chunk;
}
 
Example 34
Project: CustomWorldGen   File: SPacketMultiBlockChange.java   Source Code and License 5 votes vote down vote up
public SPacketMultiBlockChange(int p_i46959_1_, short[] p_i46959_2_, Chunk p_i46959_3_)
{
    this.chunkPos = new ChunkPos(p_i46959_3_.xPosition, p_i46959_3_.zPosition);
    this.changedBlocks = new SPacketMultiBlockChange.BlockUpdateData[p_i46959_1_];

    for (int i = 0; i < this.changedBlocks.length; ++i)
    {
        this.changedBlocks[i] = new SPacketMultiBlockChange.BlockUpdateData(p_i46959_2_[i], p_i46959_3_);
    }
}
 
Example 35
Project: Etheric   File: StabilityWorldData.java   Source Code and License 5 votes vote down vote up
public StabilityData getStabilityData(ChunkPos inPos) {
	for (ChunkPos cPos : chunkData.keySet()) {
		if (cPos.equals(inPos)) {
			return chunkData.get(cPos);
		}
	}
	return StabilityData.NO_DATA;
}
 
Example 36
Project: Etheric   File: StabilityWorldData.java   Source Code and License 5 votes vote down vote up
public float getBaseStability(ChunkPos inPos) {
	for (ChunkPos cPos : chunkData.keySet()) {
		if (cPos.equals(inPos)) {
			return chunkData.get(cPos).getBaseStability();
		}
	}
	return -1;
}
 
Example 37
Project: Etheric   File: StabilityWorldData.java   Source Code and License 5 votes vote down vote up
public float getStability(ChunkPos inPos) {
	for (ChunkPos cPos : chunkData.keySet()) {
		if (cPos.equals(inPos)) {
			return chunkData.get(cPos).getStability();
		}
	}
	return -1;
}
 
Example 38
Project: Etheric   File: StabilityWorldData.java   Source Code and License 5 votes vote down vote up
public float setStability(ChunkPos inPos, float stability) {
	for (ChunkPos cPos : chunkData.keySet()) {
		if (cPos.equals(inPos)) {
			return chunkData.get(cPos).setStability(stability).getStability();
		}
	}
	return -1F;
}
 
Example 39
Project: Backmemed   File: StructureOceanMonument.java   Source Code and License 5 votes vote down vote up
public void readFromNBT(NBTTagCompound tagCompound)
{
    super.readFromNBT(tagCompound);

    if (tagCompound.hasKey("Processed", 9))
    {
        NBTTagList nbttaglist = tagCompound.getTagList("Processed", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            this.processed.add(new ChunkPos(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Z")));
        }
    }
}
 
Example 40
Project: CustomWorldGen   File: ChunkProviderServer.java   Source Code and License 5 votes vote down vote up
/**
 * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
 */
public boolean unloadQueuedChunks()
{
    if (!this.worldObj.disableLevelSaving)
    {
        if (!this.droppedChunksSet.isEmpty())
        {
            for (ChunkPos forced : this.worldObj.getPersistentChunks().keySet())
            {
                this.droppedChunksSet.remove(ChunkPos.asLong(forced.chunkXPos, forced.chunkZPos));
            }

            Iterator<Long> iterator = this.droppedChunksSet.iterator();

            for (int i = 0; i < 100 && iterator.hasNext(); iterator.remove())
            {
                Long olong = (Long)iterator.next();
                Chunk chunk = (Chunk)this.id2ChunkMap.get(olong);

                if (chunk != null && chunk.unloaded)
                {
                    chunk.onChunkUnload();
                    this.saveChunkData(chunk);
                    this.saveChunkExtraData(chunk);
                    this.id2ChunkMap.remove(olong);
                    ++i;
                    net.minecraftforge.common.ForgeChunkManager.putDormantChunk(ChunkPos.asLong(chunk.xPosition, chunk.zPosition), chunk);
                    if (id2ChunkMap.size() == 0 && net.minecraftforge.common.ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !this.worldObj.provider.getDimensionType().shouldLoadSpawn()){
                        net.minecraftforge.common.DimensionManager.unloadWorld(this.worldObj.provider.getDimension());
                        break;
                    }
                }
            }
        }

        this.chunkLoader.chunkTick();
    }

    return false;
}