Search in sources :

Example 71 with WorldServer

use of net.minecraft.world.WorldServer in project Cavern2 by kegare.

the class WorldProviderCavern method onWorldUpdateEntities.

@Override
public void onWorldUpdateEntities() {
    if (getMonsterSpawn() > 0 && world instanceof WorldServer) {
        WorldServer worldServer = (WorldServer) world;
        if (worldServer.getGameRules().getBoolean("doMobSpawning") && worldServer.getWorldInfo().getTerrainType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
            MinecraftServer server = worldServer.getMinecraftServer();
            boolean spawnHostileMobs = worldServer.getDifficulty() != EnumDifficulty.PEACEFUL;
            if (server != null && !server.isSinglePlayer() && server.isDedicatedServer() && server instanceof DedicatedServer) {
                spawnHostileMobs = ((DedicatedServer) server).allowSpawnMonsters();
            }
            entitySpawner.findChunksForSpawning(worldServer, spawnHostileMobs, false, worldServer.getWorldInfo().getWorldTotalTime() % 400L == 0L);
        }
    }
}
Also used : WorldServer(net.minecraft.world.WorldServer) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 72 with WorldServer

use of net.minecraft.world.WorldServer in project Cavern2 by kegare.

the class CaveEventHooks method onPlayerChangedDimension.

@SubscribeEvent
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event) {
    if (!(event.player instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) event.player;
    if (CavernAPI.dimension.isInCaves(player)) {
        WorldServer world = player.getServerWorld();
        DimensionType type = world.provider.getDimensionType();
        if (type != CaveDimensions.CAVERN) {
            String name = type.getName();
            PlayerHelper.grantCriterion(player, "enter_the_" + name, "entered_" + name);
        }
    }
    MinerStats.adjustData(player);
}
Also used : DimensionType(net.minecraft.world.DimensionType) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 73 with WorldServer

use of net.minecraft.world.WorldServer in project Cavern2 by kegare.

the class CaveCapabilities method onAttachWorldCapabilities.

@SubscribeEvent
public void onAttachWorldCapabilities(AttachCapabilitiesEvent<World> event) {
    World world = event.getObject();
    if (world instanceof WorldServer) {
        WorldServer worldServer = (WorldServer) world;
        event.addCapability(CaveUtils.getKey("world_cache"), new CapabilityWorldCachedData(worldServer));
    }
}
Also used : WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 74 with WorldServer

use of net.minecraft.world.WorldServer in project Cavern2 by kegare.

the class WorldProviderCrownCliffs method init.

@Override
protected void init() {
    hasSkyLight = true;
    biomeProvider = new BiomeProvider(world.getWorldInfo());
    seedData = world instanceof WorldServer ? new CustomSeedData(world.getWorldInfo().getDimensionData(getDimension())) : new CustomSeedData();
}
Also used : BiomeProvider(net.minecraft.world.biome.BiomeProvider) CustomSeedData(cavern.world.CustomSeedData) WorldServer(net.minecraft.world.WorldServer)

Example 75 with WorldServer

use of net.minecraft.world.WorldServer in project RFTools by McJty.

the class NoTeleportAreaManager method isTeleportPrevented.

public static boolean isTeleportPrevented(Entity entity, GlobalCoordinate coordinate) {
    if (areas.isEmpty()) {
        return false;
    }
    List<GlobalCoordinate> toRemove = new ArrayList<>();
    boolean noTeleport = false;
    long curtime = System.currentTimeMillis() - 10000;
    for (Map.Entry<GlobalCoordinate, NoTeleportArea> entry : areas.entrySet()) {
        NoTeleportArea area = entry.getValue();
        GlobalCoordinate entryCoordinate = entry.getKey();
        if (area.in(coordinate, entryCoordinate)) {
            World world = mcjty.lib.varia.TeleportationTools.getWorldForDimension(entryCoordinate.getDimension());
            TileEntity te = world.getTileEntity(entryCoordinate.getCoordinate());
            if (te instanceof EnvironmentalControllerTileEntity) {
                EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                noTeleport = controllerTileEntity.isEntityAffected(entity);
            }
        }
        if (area.getLastTouched() < curtime) {
            // Hasn't been touched for at least 10 seconds. Probably no longer valid.
            // To be sure we will first check this by testing if the environmental controller is still active and running.
            WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
            if (world != null) {
                BlockPos c = entryCoordinate.getCoordinate();
                // If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
                if (RFToolsTools.chunkLoaded(world, c)) {
                    boolean removeArea = true;
                    TileEntity te = world.getTileEntity(c);
                    if (te instanceof EnvironmentalControllerTileEntity) {
                        EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                        for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
                            if (module instanceof NoTeleportEModule) {
                                if (((NoTeleportEModule) module).isActive()) {
                                    removeArea = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (removeArea) {
                        toRemove.add(entryCoordinate);
                    }
                }
            }
        }
    }
    for (GlobalCoordinate globalCoordinate : toRemove) {
        areas.remove(globalCoordinate);
    }
    return noTeleport;
}
Also used : EnvironmentModule(mcjty.rftools.blocks.environmental.modules.EnvironmentModule) NoTeleportEModule(mcjty.rftools.blocks.environmental.modules.NoTeleportEModule) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.world.WorldServer) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WorldServer (net.minecraft.world.WorldServer)338 BlockPos (net.minecraft.util.math.BlockPos)101 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 ItemStack (net.minecraft.item.ItemStack)55 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)47 Entity (net.minecraft.entity.Entity)44 TileEntity (net.minecraft.tileentity.TileEntity)42 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)36 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)32 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)28 ArrayList (java.util.ArrayList)20 PotionEffect (net.minecraft.potion.PotionEffect)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Nullable (javax.annotation.Nullable)17 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)14