void ParseBlockDefinition(NbtCompound compound) { byte id = (byte)compound["ID"].Value; BlockInfo info = game.BlockInfo; info.Name[id] = (string)compound["Name"].Value; info.CollideType[id] = (BlockCollideType)compound["CollideType"].Value; info.SpeedMultiplier[id] = (float)compound["Speed"].Value; byte[] data = (byte[])compound["Textures"].Value; info.SetTex(data[0], TileSide.Top, (Block)id); info.SetTex(data[1], TileSide.Bottom, (Block)id); info.SetTex(data[2], TileSide.Left, (Block)id); info.SetTex(data[3], TileSide.Right, (Block)id); info.SetTex(data[4], TileSide.Front, (Block)id); info.SetTex(data[5], TileSide.Back, (Block)id); info.BlocksLight[id] = (byte)compound["TransmitsLight"].Value == 0; byte soundId = (byte)compound["WalkSound"].Value; info.DigSounds[id] = NetworkProcessor.breakSnds[soundId]; info.StepSounds[id] = NetworkProcessor.stepSnds[soundId]; info.FullBright[id] = (byte)compound["FullBright"].Value != 0; info.IsSprite[id] = (byte)compound["Shape"].Value == 0; NetworkProcessor.SetBlockDraw(info, id, (byte)compound["BlockDraw"].Value); data = (byte[])compound["Fog"].Value; info.FogDensity[id] = (data[0] + 1) / 128f; info.FogColour[id] = new FastColour(data[1], data[2], data[3]); data = (byte[])compound["Coords"].Value; info.MinBB[id] = new Vector3(data[0] / 16f, data[1] / 16f, data[2] / 16f); info.MaxBB[id] = new Vector3(data[3] / 16f, data[4] / 16f, data[5] / 16f); if (info.CollideType[id] != BlockCollideType.Solid) { info.IsTransparent[id] = true; info.IsOpaque[id] = false; } info.SetupCullingCache(id); info.InitLightOffsets(); game.Events.RaiseBlockDefinitionChanged(); info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F)); game.Inventory.CanPlace.SetNotOverridable(true, id); game.Inventory.CanDelete.SetNotOverridable(true, id); game.Events.RaiseBlockPermissionsChanged(); }
protected override void OnLoad(EventArgs e) { #if !USE_DX Graphics = new OpenGLApi(); #else Graphics = new Direct3D9Api(this); #endif Graphics.MakeGraphicsInfo(); Players = new EntityList(this); Options.Load(); AcceptedUrls.Load(); DeniedUrls.Load(); ViewDistance = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512); UserViewDistance = ViewDistance; CameraClipping = Options.GetBool(OptionsKey.CameraClipping, true); InputHandler = new InputHandler(this); Chat = new ChatLog(this); ParticleManager = new ParticleManager(this); HudScale = Options.GetFloat(OptionsKey.HudScale, 0.25f, 5f, 1f); ChatScale = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f); defaultIb = Graphics.MakeDefaultIb(); MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30); UseClassicGui = Options.GetBool(OptionsKey.UseClassicGui, false); BlockInfo = new BlockInfo(); BlockInfo.Init(); ChatLines = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12); ClickableChat = Options.GetBool(OptionsKey.ClickableChat, true); ModelCache = new ModelCache(this); ModelCache.InitCache(); AsyncDownloader = new AsyncDownloader(skinServer); Drawer2D = new GdiPlusDrawer2D(Graphics); Drawer2D.UseBitmappedChat = !Options.GetBool(OptionsKey.ArialChatFont, false); ViewBobbing = Options.GetBool(OptionsKey.ViewBobbing, false); ShowBlockInHand = Options.GetBool(OptionsKey.ShowBlockInHand, true); InvertMouse = Options.GetBool(OptionsKey.InvertMouse, false); SimpleArmsAnim = Options.GetBool(OptionsKey.SimpleArmsAnim, false); TerrainAtlas1D = new TerrainAtlas1D(Graphics); TerrainAtlas = new TerrainAtlas2D(Graphics, Drawer2D); Animations = new Animations(this); defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip"; TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract("default.zip", this); // in case the user's default texture pack doesn't have all required textures if (defTexturePack != "default.zip") { extractor.Extract(DefaultTexturePack, this); } Inventory = new Inventory(this); BlockInfo.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete); Map = new Map(this); LocalPlayer = new LocalPlayer(this); Players[255] = LocalPlayer; width = Width; height = Height; MapRenderer = new MapRenderer(this); MapBordersRenderer = new MapBordersRenderer(this); EnvRenderer = new StandardEnvRenderer(this); if (IPAddress == null) { Network = new Singleplayer.SinglePlayerServer(this); } else { Network = new NetworkProcessor(this); } Graphics.LostContextFunction = Network.Tick; firstPersonCam = new FirstPersonCamera(this); thirdPersonCam = new ThirdPersonCamera(this); forwardThirdPersonCam = new ForwardThirdPersonCamera(this); Camera = firstPersonCam; FieldOfView = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70); ZoomFieldOfView = FieldOfView; UpdateProjection(); CommandManager = new CommandManager(); CommandManager.Init(this); SelectionManager = new SelectionManager(this); WeatherRenderer = new WeatherRenderer(this); WeatherRenderer.Init(); BlockHandRenderer = new BlockHandRenderer(this); BlockHandRenderer.Init(); FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync); SetFpsLimitMethod(method); Graphics.DepthTest = true; Graphics.DepthTestFunc(CompareFunc.LessEqual); //Graphics.DepthWrite = true; Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f); fpsScreen = new FpsScreen(this); fpsScreen.Init(); hudScreen = new HudScreen(this); hudScreen.Init(); Culling = new FrustumCulling(); EnvRenderer.Init(); MapBordersRenderer.Init(); Picking = new PickingRenderer(this); AudioPlayer = new AudioPlayer(this); LiquidsBreakable = Options.GetBool(OptionsKey.LiquidsBreakable, false); AxisLinesRenderer = new AxisLinesRenderer(this); LoadIcon(); string connectString = "Connecting to " + IPAddress + ":" + Port + ".."; Graphics.WarnIfNecessary(Chat); SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake")); Network.Connect(IPAddress, Port); }