Search in sources :

Example 1 with WorldServer

use of net.minecraft.world.WorldServer in project malmo by Microsoft.

the class EnvironmentHelper method setMissionWeather.

public static void setMissionWeather(MissionInit minit) {
    ServerSection ss = minit.getMission().getServerSection();
    ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
    if (sic != null && sic.getWeather() != null && !sic.getWeather().equalsIgnoreCase("normal")) {
        // Max allowed by Minecraft's own Weather Command.
        int maxtime = 1000000 * 20;
        int cleartime = (sic.getWeather().equalsIgnoreCase("clear")) ? maxtime : 0;
        int raintime = (sic.getWeather().equalsIgnoreCase("rain")) ? maxtime : 0;
        int thundertime = (sic.getWeather().equalsIgnoreCase("thunder")) ? maxtime : 0;
        WorldServer worldserver = MinecraftServer.getServer().worldServers[0];
        WorldInfo worldinfo = worldserver.getWorldInfo();
        worldinfo.setCleanWeatherTime(cleartime);
        worldinfo.setRainTime(raintime);
        worldinfo.setThunderTime(thundertime);
        worldinfo.setRaining(raintime + thundertime > 0);
        worldinfo.setThundering(thundertime > 0);
    }
}
Also used : ServerSection(com.microsoft.Malmo.Schemas.ServerSection) WorldInfo(net.minecraft.world.storage.WorldInfo) WorldServer(net.minecraft.world.WorldServer) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions)

Example 2 with WorldServer

use of net.minecraft.world.WorldServer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method saveWorld.

static void saveWorld(World world) {
    // only persist persistent worlds
    if (!(world instanceof WorldServer)) {
        return;
    }
    WorldServer worldServer = (WorldServer) world;
    File chunkDir = worldServer.getChunkSaveLocation();
    File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");
    NBTTagCompound forcedChunkData = new NBTTagCompound();
    NBTTagList ticketList = new NBTTagList();
    forcedChunkData.setTag("TicketList", ticketList);
    Multimap<String, Ticket> ticketSet = tickets.get(worldServer);
    if (ticketSet == null)
        return;
    for (String modId : ticketSet.keySet()) {
        NBTTagCompound ticketHolder = new NBTTagCompound();
        ticketList.appendTag(ticketHolder);
        ticketHolder.setString("Owner", modId);
        NBTTagList tickets = new NBTTagList();
        ticketHolder.setTag("Tickets", tickets);
        for (Ticket tick : ticketSet.get(modId)) {
            NBTTagCompound ticket = new NBTTagCompound();
            ticket.setByte("Type", (byte) tick.ticketType.ordinal());
            ticket.setByte("ChunkListDepth", (byte) tick.maxDepth);
            if (tick.isPlayerTicket()) {
                ticket.setString("ModId", tick.modId);
                ticket.setString("Player", tick.player);
            }
            if (tick.modData != null) {
                ticket.setTag("ModData", tick.modData);
            }
            if (tick.ticketType == Type.ENTITY && tick.entity != null && tick.entity.writeToNBTOptional(new NBTTagCompound())) {
                ticket.setInteger("chunkX", MathHelper.floor(tick.entity.chunkCoordX));
                ticket.setInteger("chunkZ", MathHelper.floor(tick.entity.chunkCoordZ));
                ticket.setLong("PersistentIDMSB", tick.entity.getPersistentID().getMostSignificantBits());
                ticket.setLong("PersistentIDLSB", tick.entity.getPersistentID().getLeastSignificantBits());
                tickets.appendTag(ticket);
            } else if (tick.ticketType != Type.ENTITY) {
                tickets.appendTag(ticket);
            }
        }
    }
    try {
        CompressedStreamTools.write(forcedChunkData, chunkLoaderData);
    } catch (IOException e) {
        FMLLog.log(Level.WARN, e, "Unable to write forced chunk data to %s - chunkloading won't work", chunkLoaderData.getAbsolutePath());
        return;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) IOException(java.io.IOException) File(java.io.File)

Example 3 with WorldServer

use of net.minecraft.world.WorldServer in project Witchworks by Um-Mitternacht.

the class ItemRitual method onUpdate.

@Override
public void onUpdate(RitualHolder<TileKettle> ritual, TileKettle tile, World world, BlockPos pos) {
    if (getCost() > 0 && ritual.energy_left > 0 && ritual.ticks % 10 == 0) {
        List<EntityPlayer> list = EnergyHandler.getEnergySources(EntityPlayer.class, world, pos, 5);
        int taken = (split / list.size()) + 1;
        for (int i = 0, size = list.size(); i < size; i++) {
            EntityPlayer player = list.get(i);
            if (EnergyHandler.addEnergy(player, -taken)) {
                ritual.energy_left -= taken;
            } else if (i + 1 >= size) {
                ritual.fail();
            }
        }
    }
    if (world instanceof WorldServer && ritual.ticks % 5 == 0) {
        double x = world.rand.nextFloat();
        double y = 0.2F + world.rand.nextFloat();
        double z = world.rand.nextFloat();
        ((WorldServer) world).spawnParticle(EnumParticleTypes.SPELL_WITCH, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, 4, x, y, z, 0D);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 4 with WorldServer

use of net.minecraft.world.WorldServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method injectChunkIntoWorld.

public void injectChunkIntoWorld(Chunk chunk, int x, int z, boolean putInId2ChunkMap) {
    ChunkProviderServer provider = (ChunkProviderServer) worldObj.getChunkProvider();
    //TileEntities will break if you don't do this
    chunk.isChunkLoaded = true;
    chunk.isModified = true;
    claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
    if (putInId2ChunkMap) {
        provider.id2ChunkMap.put(ChunkPos.chunkXZ2Int(x, z), chunk);
    }
    PlayerChunkMap map = ((WorldServer) worldObj).getPlayerChunkMap();
    PlayerChunkMapEntry entry = new PlayerChunkMapEntry(map, x, z) {

        @Override
        public boolean hasPlayerMatchingInRange(double range, Predicate<EntityPlayerMP> predicate) {
            return true;
        }
    };
    long i = map.getIndex(x, z);
    map.playerInstances.put(i, entry);
    map.playerInstanceList.add(entry);
    entry.sentToPlayers = true;
    entry.players = watchingPlayers;
    claimedChunksEntries[x - ownedChunks.minX][z - ownedChunks.minZ] = entry;
//		MinecraftForge.EVENT_BUS.post(new ChunkEvent.Load(chunk));
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) WorldServer(net.minecraft.world.WorldServer) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) PlayerChunkMap(net.minecraft.server.management.PlayerChunkMap) Predicate(com.google.common.base.Predicate)

Example 5 with WorldServer

use of net.minecraft.world.WorldServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysObjectManager method getTickablePhysicsEntities.

/**
	 * Returns the list of PhysicsEntities that aren't too far away from players to justify being ticked
	 * @return
	 */
public ArrayList<PhysicsWrapperEntity> getTickablePhysicsEntities() {
    ArrayList<PhysicsWrapperEntity> list = (ArrayList<PhysicsWrapperEntity>) physicsEntities.clone();
    ArrayList<PhysicsWrapperEntity> frozenShips = new ArrayList<PhysicsWrapperEntity>();
    if (worldObj instanceof WorldServer) {
        WorldServer worldServer = (WorldServer) worldObj;
        for (PhysicsWrapperEntity wrapper : list) {
            if (!wrapper.isDead) {
                if (wrapper.wrapping.surroundingWorldChunksCache != null) {
                    int chunkCacheX = MathHelper.floor_double(wrapper.posX / 16D) - wrapper.wrapping.surroundingWorldChunksCache.chunkX;
                    int chunkCacheZ = MathHelper.floor_double(wrapper.posZ / 16D) - wrapper.wrapping.surroundingWorldChunksCache.chunkZ;
                    chunkCacheX = Math.max(0, Math.min(chunkCacheX, wrapper.wrapping.surroundingWorldChunksCache.chunkArray.length - 1));
                    chunkCacheZ = Math.max(0, Math.min(chunkCacheZ, wrapper.wrapping.surroundingWorldChunksCache.chunkArray[0].length - 1));
                    Chunk chunk = wrapper.wrapping.surroundingWorldChunksCache.chunkArray[chunkCacheX][chunkCacheZ];
                    //		        		Chunk chunk = wrapper.wrapping.surroundingWorldChunksCache.chunkArray[(wrapper.wrapping.surroundingWorldChunksCache.chunkArray.length)/2][(wrapper.wrapping.surroundingWorldChunksCache.chunkArray[0].length)/2];
                    if (chunk != null && !worldServer.thePlayerManager.contains(chunk.xPosition, chunk.zPosition)) {
                        frozenShips.add(wrapper);
                    //Then I should freeze any ships in this chunk
                    }
                }
            } else {
                frozenShips.add(wrapper);
            }
        }
    }
    ArrayList<PhysicsWrapperEntity> dumbShips = new ArrayList<PhysicsWrapperEntity>();
    for (PhysicsWrapperEntity wrapper : list) {
        if (wrapper.isDead || wrapper.wrapping == null || (wrapper.wrapping.physicsProcessor == null && !wrapper.worldObj.isRemote)) {
            dumbShips.add(wrapper);
        }
    }
    /*if(droppedChunksField == null){
			try{
				if(ValkyrienWarfarePlugin.isObfuscatedEnvironment){
					droppedChunksField = ChunkProviderServer.class.getDeclaredField("field_73248_b");
				}else{
					droppedChunksField = ChunkProviderServer.class.getDeclaredField("droppedChunksSet");
				}
				droppedChunksField.setAccessible(true);
			}catch(Exception e){}
		}
		ChunkProviderServer serverProvider = (ChunkProviderServer) worldObj.getChunkProvider();

		try{
			Set<Long> droppedChunks = (Set<Long>) droppedChunksField.get(serverProvider);

			for(PhysicsWrapperEntity entity:list){
				int chunkX = entity.chunkCoordX;
				int chunkZ = entity.chunkCoordZ;
				if(droppedChunks.contains(ChunkPos.chunkXZ2Int(chunkX, chunkZ))){
					frozenShips.add(entity);
				}
			}
		}catch(Exception e){}*/
    list.removeAll(frozenShips);
    list.removeAll(dumbShips);
    return list;
}
Also used : ArrayList(java.util.ArrayList) WorldServer(net.minecraft.world.WorldServer) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

WorldServer (net.minecraft.world.WorldServer)322 BlockPos (net.minecraft.util.math.BlockPos)96 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 ItemStack (net.minecraft.item.ItemStack)48 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)48 TileEntity (net.minecraft.tileentity.TileEntity)42 Entity (net.minecraft.entity.Entity)41 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)35 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)31 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)26 EntityLivingBase (net.minecraft.entity.EntityLivingBase)23 ArrayList (java.util.ArrayList)20 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 Nullable (javax.annotation.Nullable)17 PotionEffect (net.minecraft.potion.PotionEffect)16 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)13