use of net.minecraft.world.WorldServer in project Pearcel-Mod by MiningMark48.
the class CommandSpawnStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
World world = sender.getEntityWorld();
if (!world.isRemote) {
if (args.length == 0) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + Translate.toLocal("command.spawn_structure.no_args")));
return;
}
Random rand = new Random();
if (!(world instanceof WorldServer))
return;
WorldServer worldServer = (WorldServer) world;
try {
switch(Integer.valueOf(args[0])) {
default:
case 1:
StructureGenPearcel1.generateStructure(worldServer, sender.getPosition().add(1, 0, 1), rand);
break;
case 2:
StructureGenPearcel2.generateStructure(worldServer, sender.getPosition().add(1, 0, 1), rand);
break;
case 3:
StructureGenPearcel3.generateStructure(worldServer, sender.getPosition().add(1, 0, 1), rand);
break;
}
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + Translate.toLocal("command.spawn_structure.spawned")));
} catch (NumberFormatException e) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + Translate.toLocal("command.spawn_structure.invalid")));
}
}
}
use of net.minecraft.world.WorldServer in project minecolonies by Minecolonies.
the class ItemScanTool method saveStructure.
/**
* Scan the structure and save it to the disk.
*
* @param world Current world.
* @param from First corner.
* @param to Second corner.
* @param player causing this action.
*/
private static void saveStructure(@Nullable final World world, @Nullable final BlockPos from, @Nullable final BlockPos to, @NotNull final EntityPlayer player) {
//todo if on clientSide check if isRemote and if it is -> don't seed message, execute right away.
if (world == null || from == null || to == null) {
throw new IllegalArgumentException("Invalid method call, arguments can't be null. Contact a developer.");
}
final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
final BlockPos size = blockpos1.subtract(blockpos).add(1, 1, 1);
final WorldServer worldserver = (WorldServer) world;
final MinecraftServer minecraftserver = world.getMinecraftServer();
final TemplateManager templatemanager = worldserver.getStructureTemplateManager();
final long currentMillis = System.currentTimeMillis();
final String currentMillisString = Long.toString(currentMillis);
final String fileName = "/minecolonies/scans/" + LanguageHandler.format("item.scepterSteel.scanFormat", "", currentMillisString + ".nbt");
final Template template = templatemanager.getTemplate(minecraftserver, new ResourceLocation(fileName));
template.takeBlocksFromWorld(world, blockpos, size, true, Blocks.STRUCTURE_VOID);
template.setAuthor(Constants.MOD_ID);
MineColonies.getNetwork().sendTo(new SaveScanMessage(template.writeToNBT(new NBTTagCompound()), currentMillis), (EntityPlayerMP) player);
}
use of net.minecraft.world.WorldServer in project ArsMagica2 by Mithion.
the class MeteorSpawnHelper method spawnMeteor.
public void spawnMeteor() {
ticksSinceLastMeteor = 48000;
if (MinecraftServer.getServer().worldServers.length < 1)
return;
WorldServer ws = null;
for (WorldServer world : MinecraftServer.getServer().worldServers) {
if (world.provider.dimensionId == 0) {
ws = world;
break;
}
}
if (ws == null)
return;
long time = ws.getWorldTime() % 24000;
if (time > 14500 && time < 21500) {
//night time range (just past dusk and just before dawn)
if (ws.playerEntities.size() < 1)
return;
int playerID = rand.nextInt(ws.playerEntities.size());
EntityPlayer player = (EntityPlayer) ws.playerEntities.get(playerID);
if (ExtendedProperties.For(player).getMagicLevel() < AMCore.config.getMeteorMinSpawnLevel())
return;
AMVector3 spawnCoord = new AMVector3(player);
boolean found = false;
int meteorOffsetRadius = 64;
AMVector3 attractorCoord = FlickerOperatorMoonstoneAttractor.getMeteorAttractor(spawnCoord);
if (attractorCoord != null) {
spawnCoord = attractorCoord;
meteorOffsetRadius = 4;
}
for (int i = 0; i < 10; ++i) {
AMVector3 offsetCoord = spawnCoord.copy().add(new AMVector3(rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2), 0, rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2)));
offsetCoord.y = correctYCoord(ws, (int) offsetCoord.x, (int) offsetCoord.y, (int) offsetCoord.z);
if (offsetCoord.y < 0)
return;
if (topBlockIsBiomeGeneric(ws, (int) offsetCoord.x, (int) offsetCoord.y, (int) offsetCoord.z)) {
spawnCoord = offsetCoord;
found = true;
break;
}
}
if (!found)
return;
EntityThrownRock meteor = new EntityThrownRock(ws);
meteor.setPosition(spawnCoord.x + rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2), ws.getActualHeight(), spawnCoord.z + rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2));
meteor.setMoonstoneMeteor();
meteor.setMoonstoneMeteorTarget(spawnCoord);
ws.spawnEntityInWorld(meteor);
}
}
use of net.minecraft.world.WorldServer in project RFToolsDimensions by McJty.
the class GenericChunkGenerator method populate.
@Override
public void populate(int chunkX, int chunkZ) {
BlockFalling.fallInstantly = true;
int x = chunkX * 16;
int z = chunkZ * 16;
World w = this.worldObj;
Biome Biome = w.getBiomeForCoordsBody(new BlockPos(x + 16, 0, z + 16));
this.rand.setSeed(w.getSeed());
long i1 = this.rand.nextLong() / 2L * 2L + 1L;
long j1 = this.rand.nextLong() / 2L * 2L + 1L;
this.rand.setSeed(chunkX * i1 + chunkZ * j1 ^ w.getSeed());
boolean flag = false;
if (dimensionInformation.getTerrainType() == TerrainType.TERRAIN_INVERTIGO) {
if (upsidedownWorld == null) {
World ww = worldObj;
upsidedownWorld = new UpsidedownWorld((WorldServer) worldObj) {
@Override
protected IChunkProvider createChunkProvider() {
IChunkLoader ichunkloader = ww.getSaveHandler().getChunkLoader(ww.provider);
return new ChunkProviderServer((WorldServer) ww, ichunkloader, ww.provider.createChunkGenerator());
}
@Override
public ChunkProviderServer getChunkProvider() {
return (ChunkProviderServer) ww.getChunkProvider();
}
};
net.minecraftforge.common.DimensionManager.setWorld(ww.provider.getDimension(), (WorldServer) ww, ww.getMinecraftServer());
}
upsidedownWorld.worldObj = (WorldServer) worldObj;
w = upsidedownWorld;
}
MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(this, w, rand, chunkX, chunkZ, flag));
ChunkPos cp = new ChunkPos(chunkX, chunkZ);
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_MINESHAFT)) {
this.mineshaftGenerator.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_VILLAGE)) {
flag = this.villageGenerator.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_STRONGHOLD)) {
this.strongholdGenerator.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_FORTRESS)) {
this.genNetherBridge.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_SCATTERED)) {
this.scatteredFeatureGenerator.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_SWAMPHUT)) {
this.genSwampHut.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_DESERTTEMPLE)) {
this.genDesertTemple.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_JUNGLETEMPLE)) {
this.genJungleTemple.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_IGLOO)) {
this.genIgloo.generateStructure(w, this.rand, cp);
}
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_OCEAN_MONUMENT)) {
this.oceanMonumentGenerator.generateStructure(w, this.rand, cp);
}
int k1;
int l1;
int i2;
if (dimensionInformation.getTerrainType() != TerrainType.TERRAIN_INVERTIGO) {
if (dimensionInformation.hasFeatureType(FeatureType.FEATURE_LAKES)) {
if (dimensionInformation.getFluidsForLakes().length == 0) {
// No specific liquid dimlets specified: we generate default lakes (water and lava were appropriate).
if (Biome != Biomes.DESERT && Biome != Biomes.DESERT_HILLS && !flag && this.rand.nextInt(4) == 0 && TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAKE)) {
k1 = x + this.rand.nextInt(16) + 8;
l1 = this.rand.nextInt(256);
i2 = z + this.rand.nextInt(16) + 8;
(new WorldGenLakes(Blocks.WATER)).generate(w, this.rand, new BlockPos(k1, l1, i2));
}
if (TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAVA) && !flag && this.rand.nextInt(8) == 0) {
k1 = x + this.rand.nextInt(16) + 8;
l1 = this.rand.nextInt(this.rand.nextInt(248) + 8);
i2 = z + this.rand.nextInt(16) + 8;
if (l1 < 63 || this.rand.nextInt(10) == 0) {
(new WorldGenLakes(Blocks.LAVA)).generate(w, this.rand, new BlockPos(k1, l1, i2));
}
}
} else {
// Generate lakes for the specified biomes.
for (Block liquid : dimensionInformation.getFluidsForLakes()) {
if (!flag && this.rand.nextInt(4) == 0 && TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAKE)) {
k1 = x + this.rand.nextInt(16) + 8;
l1 = this.rand.nextInt(256);
i2 = z + this.rand.nextInt(16) + 8;
(new WorldGenLakes(liquid)).generate(w, this.rand, new BlockPos(k1, l1, i2));
}
}
}
}
}
boolean doGen = false;
if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_DUNGEON)) {
doGen = TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.DUNGEON);
for (k1 = 0; doGen && k1 < 8; ++k1) {
l1 = x + this.rand.nextInt(16) + 8;
i2 = this.rand.nextInt(256);
int j2 = z + this.rand.nextInt(16) + 8;
(new WorldGenDungeons()).generate(w, this.rand, new BlockPos(l1, i2, j2));
}
}
BlockPos pos = new BlockPos(x, 0, z);
Biome.decorate(w, this.rand, pos);
// OresAPlenty
if (dimensionInformation.hasFeatureType(FeatureType.FEATURE_ORESAPLENTY)) {
generateOre(w, this.rand, coalGen, OreGenEvent.GenerateMinable.EventType.COAL, pos, OresAPlentyConfiguration.coal);
generateOre(w, this.rand, ironGen, OreGenEvent.GenerateMinable.EventType.IRON, pos, OresAPlentyConfiguration.iron);
generateOre(w, this.rand, goldGen, OreGenEvent.GenerateMinable.EventType.GOLD, pos, OresAPlentyConfiguration.gold);
generateOre(w, this.rand, lapisGen, OreGenEvent.GenerateMinable.EventType.LAPIS, pos, OresAPlentyConfiguration.lapis);
generateOre(w, this.rand, diamondGen, OreGenEvent.GenerateMinable.EventType.DIAMOND, pos, OresAPlentyConfiguration.diamond);
generateOre(w, this.rand, redstoneGen, OreGenEvent.GenerateMinable.EventType.REDSTONE, pos, OresAPlentyConfiguration.redstone);
generateOre(w, this.rand, emeraldGen, OreGenEvent.GenerateMinable.EventType.EMERALD, pos, OresAPlentyConfiguration.emerald);
}
if (TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.ANIMALS)) {
WorldEntitySpawner.performWorldGenSpawning(w, Biome, x + 8, z + 8, 16, 16, this.rand);
}
x += 8;
z += 8;
doGen = TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.ICE);
for (k1 = 0; doGen && k1 < 16; ++k1) {
for (l1 = 0; l1 < 16; ++l1) {
i2 = w.getPrecipitationHeight(new BlockPos(x + k1, 0, z + l1)).getY();
if (w.canBlockFreeze(new BlockPos(k1 + x, i2 - 1, l1 + z), false)) {
w.setBlockState(new BlockPos(k1 + x, i2 - 1, l1 + z), Blocks.ICE.getDefaultState(), 2);
}
if (w.canSnowAt(new BlockPos(k1 + x, i2, l1 + z), true)) {
w.setBlockState(new BlockPos(k1 + x, i2, l1 + z), Blocks.SNOW_LAYER.getDefaultState(), 2);
}
}
}
MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(this, w, rand, chunkX, chunkZ, flag));
BlockFalling.fallInstantly = false;
}
use of net.minecraft.world.WorldServer in project minecolonies by Minecolonies.
the class EntityFishHook method checkIfFishBites.
/**
* Server side method to do.
* some animation and movement stuff.
* when the hook swims in water.
* <p>
* will set isFishCaught if a fish bites.
*
* @param waterDensity the amount of water around.
*/
private void checkIfFishBites(final double waterDensity) {
if (!this.world.isRemote && waterDensity > 0.0) {
int fishingProgressStep = 1;
if (this.rand.nextDouble() < NO_CLEAR_SKY_CHANCE && !this.world.canBlockSeeSky(new BlockPos(MathHelper.floor(this.posX), MathHelper.floor(this.posY) + 1, MathHelper.floor(this.posZ)))) {
--fishingProgressStep;
}
if (this.countdownNoFish > 0) {
updateNoFishCounter();
return;
}
@NotNull final WorldServer worldServer = (WorldServer) this.world;
if (this.countdownFishNear > 0) {
renderBubble(fishingProgressStep, worldServer);
return;
}
if (this.countdownFishBites > 0) {
this.countdownFishBites -= fishingProgressStep;
renderFishBiteOrSwim(worldServer);
} else {
this.countdownFishNear = MathHelper.getInt(this.rand, 100, 900);
this.countdownFishNear -= fishingSpeedEnchantment * 20 * 5;
}
}
}
Aggregations