private void Init() { //TODO - just a test - WORKS! //_installedMods.Add(new TestMod()); GlSetup(); _itemRegistry = new ItemRegistry(); _blockRegistry = new BlockRegistry(); _recipeRegistry = new RecipeRegistry(); LoadMods(); GameRegistry(); WorldRenderer = new WorldRenderer(); EntityRenderer = new EntityRenderer(); GuiRenderer = new GuiRenderer(); FontRenderer = new FontRenderer(); SettingsManager.Load(); //load settings Camera.SetTargetFov(SettingsManager.GetFloat("fov")); _sensitivity = SettingsManager.GetFloat("sensitivity"); WorldRenderer.RenderDistance = SettingsManager.GetInt("renderdistance"); OpenGuiScreen(new GuiScreenMainMenu()); }
public override void Update() { _ticksLast = _ticks; _ticks = (_ticks + 1) % 90; if (_ticksLast > _ticks) { _ticksLast = _ticks - 1; } for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (_placeDelay[x, y] > 0) { _placeDelay[x, y]--; } } } Item[] table = new Item[9]; for (var y = 0; y < _grid.GetLength(1); y++) { for (var x = 0; x < _grid.GetLength(0); x++) { table[y * 3 + x] = _grid[x, y]?.Item; } } _product = RecipeRegistry.GetProduct(table); }
public override void Execute(CommandQueue queue, CommandEntry entry) { TemplateObject cb = entry.GetArgumentObject(queue, 0); if (cb.ToString() == "\0CALLBACK") { return; } if (entry.InnerCommandBlock == null) { queue.HandleError(entry, "Invalid or missing command block!"); return; } ListTag mode = ListTag.For(cb); List <ItemStack> items = new List <ItemStack>(); for (int i = 1; i < entry.Arguments.Count; i++) { ItemTag required = ItemTag.For(TheServer, entry.GetArgumentObject(queue, i)); if (required == null) { queue.HandleError(entry, "Invalid required item!"); return; } items.Add(required.Internal); } TheServer.Recipes.AddRecipe(RecipeRegistry.ModeFor(mode), entry.InnerCommandBlock, entry.BlockStart, items.ToArray()); queue.CurrentEntry.Index = entry.BlockEnd + 2; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Added recipe!"); } }
/// <summary> /// Starts up and run the server. /// </summary> /// <param name="game">The game name.</param> /// <param name="loaded">The action to fire when the server is loaded.</param> public void StartUp(string game, Action loaded = null) { CurThread = Thread.CurrentThread; Files = new FileHandler(); GameName = FileHandler.CleanFileName(game); Files.SetSaveDirEarly("server_" + GameName); SysConsole.Written += OnConsoleWritten; SysConsole.Output(OutputType.INIT, "Launching as new server, this is " + (this == Central ? "" : "NOT ") + "the Central server."); SysConsole.Output(OutputType.INIT, "Loading console input handler..."); ConsoleHandler.Init(); ConsoleHandler.OnCommandInput += CommandInputHandle; SysConsole.Output(OutputType.INIT, "Loading command engine..."); Commands = new ServerCommands(); Commands.Init(new ServerOutputter(this), this); SysConsole.Output(OutputType.INIT, "Loading CVar engine..."); CVars = new ServerCVar(); CVars.Init(this, Commands.Output); SysConsole.Output(OutputType.INIT, "Loading default settings..."); Config = new FDSSection(Files.ReadText("server_config.fds")); Settings = new ServerSettings(this, Config); if (Files.Exists("serverdefaultsettings.cfg")) { string contents = Files.ReadText("serverdefaultsettings.cfg"); Commands.ExecuteCommands(contents); } if (Files.Exists("server_eid.txt")) { cID = long.Parse(Files.ReadText("server_eid.txt") ?? "1"); } SysConsole.Output(OutputType.INIT, "Loading player command engine..."); PCEngine = new PlayerCommandEngine(); SysConsole.Output(OutputType.INIT, "Loading permissions engine..."); PermGroups = new PermissionsGroupEngine() { TheServer = this }; SysConsole.Output(OutputType.INIT, "Loading item registry..."); ItemInfos = new ItemInfoRegistry(); Items = new ItemRegistry(this); Recipes = new RecipeRegistry() { TheServer = this }; SysConsole.Output(OutputType.INIT, "Loading model handler..."); Models = new ModelEngine(this); SysConsole.Output(OutputType.INIT, "Loading animation handler..."); Animations = new AnimationEngine(); SysConsole.Output(OutputType.INIT, "Preparing networking..."); Networking = new NetworkBase(this); Networking.Init(); SysConsole.Output(OutputType.INIT, "Loading plugins..."); Plugins = new PluginManager(this); Plugins.Init(); SysConsole.Output(OutputType.INIT, "Loading scripts..."); AutorunScripts(); SysConsole.Output(OutputType.INIT, "Building initial world(s)..."); foreach (string str in Settings.Worlds) { LoadWorld(str.ToLowerFast()); } SysConsole.Output(OutputType.INIT, "Preparing block image system..."); BlockImages = new BlockImageManager(); BlockImages.Init(this); loaded?.Invoke(); SysConsole.Output(OutputType.INIT, "Ticking..."); // Tick double TARGETFPS = 30d; Stopwatch Counter = new Stopwatch(); Stopwatch DeltaCounter = new Stopwatch(); DeltaCounter.Start(); double TotalDelta = 0; double CurrentDelta = 0d; double TargetDelta = 0d; int targettime = 0; try { while (true) { // Update the tick time usage counter Counter.Reset(); Counter.Start(); // Update the tick delta counter DeltaCounter.Stop(); // Delta time = Elapsed ticks * (ticks/second) CurrentDelta = ((double)DeltaCounter.ElapsedTicks) / ((double)Stopwatch.Frequency); // Begin the delta counter to find out how much time is /really/ slept+ticked for DeltaCounter.Reset(); DeltaCounter.Start(); // How much time should pass between each tick ideally TARGETFPS = Settings.FPS; if (TARGETFPS < 1 || TARGETFPS > 600) { Settings.FPS = 30; TARGETFPS = 30; } TargetDelta = (1d / TARGETFPS); // How much delta has been built up TotalDelta += CurrentDelta; while (TotalDelta > TargetDelta * 3) { // Lagging - cheat to catch up! TargetDelta *= 2; } // As long as there's more delta built up than delta wanted, tick while (TotalDelta > TargetDelta) { if (NeedShutdown.IsCancellationRequested) { CurThread = Thread.CurrentThread; ShutDown(ShutdownCallback); return; } else if (NeedsQuickShutdown.IsCancellationRequested) { CurThread = Thread.CurrentThread; ShutDownQuickly(); return; } lock (TickLock) { Tick(TargetDelta); } TotalDelta -= TargetDelta; } // The tick is done, stop measuring it Counter.Stop(); // Only sleep for target milliseconds/tick minus how long the tick took... this is imprecise but that's okay targettime = (int)((1000d / TARGETFPS) - Counter.ElapsedMilliseconds); // Only sleep at all if we're not lagging if (targettime > 0) { // Try to sleep for the target time - very imprecise, thus we deal with precision inside the tick code Thread.Sleep(targettime); } } } catch (ThreadAbortException) { return; } }
public void InitialStartup() { RecipeRegistry.RegisterRecipe(this.WoodPlankRecipe); }
public RecipeRegistryEventArgs(RecipeRegistry recipeRegistry) { _funcRegisterRecipe = recipeRegistry.RegisterRecipe; }
private void GameRegistry() { _blockRegistry = new BlockRegistry(); _itemRegistry = new ItemRegistry(); _recipeRegistry = new RecipeRegistry(); for (int i = 1; i < 6; i++) { //SoundEngine.RegisterSound($"block/grass/walk{i}"); } //register materails Material.RegisterMaterial(new Material("air", true)); Material.RegisterMaterial(new Material("tallgrass", true)); Material.RegisterMaterial(new Material("grass", false)); Material.RegisterMaterial(new Material("dirt", false)); Material.RegisterMaterial(new Material("stone", false)); Material.RegisterMaterial(new Material("wood", false)); _blockRegistry.Put(new BlockAir()); _blockRegistry.Put(new BlockStone()); _blockRegistry.Put(new BlockGrass()); _blockRegistry.Put(new BlockDirt()); _blockRegistry.Put(new BlockCobbleStone()); _blockRegistry.Put(new BlockPlanks()); _blockRegistry.Put(new BlockBedrock()); _blockRegistry.Put(new BlockLog()); _blockRegistry.Put(new BlockLeaves()); _blockRegistry.Put(new BlockGlass()); _blockRegistry.Put(new BlockCraftingTable()); _blockRegistry.Put(new BlockFurnace()); //_blockRegistry.Put(new BlockSlab()); _blockRegistry.Put(new BlockRare()); _blockRegistry.Put(new BlockLadder()); _blockRegistry.Put(new BlockTallGrass()); _blockRegistry.Put(new BlockTulipRed()); _blockRegistry.Put(new BlockTulipOrange()); _blockRegistry.Put(new BlockTNT()); //POST - MOD Blocks and Items //foreach (ModMain mod in _installedMods) //{ //mod.OnItemsAndBlocksRegistry(new RegistryEventArgs(_blockRegistry, _itemRegistry, _recipeRegistry)); //} foreach (var block in BlockRegistry.AllBlocks()) { _itemRegistry.Put(new ItemBlock(block)); } Item stick = new ItemStick(); _itemRegistry.Put(new ItemPickaxe("wood")); _itemRegistry.Put(new ItemPickaxe("stone")); _itemRegistry.Put(new ItemPickaxe("rare")); _itemRegistry.Put(stick); var log = ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockLog>()); var wood = ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockPlanks>()); var cobble = ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockCobbleStone>()); var rare = ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockRare>()); Item[] recipe = { cobble, cobble, cobble, null, stick, null, null, stick, null }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem("sharpcraft", "pick_stone")); recipe = new[] { rare, rare, rare, null, stick, null, null, stick, null }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem("sharpcraft", "pick_rare")); recipe = new[] { wood, wood, wood, null, stick, null, null, stick, null }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem("sharpcraft", "pick_wood")); recipe = new[] { cobble, cobble, cobble, cobble, null, cobble, cobble, cobble, cobble }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockFurnace>())); recipe = new[] { wood, wood, null, wood, wood, null, null, null, null }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem(BlockRegistry.GetBlock <BlockCraftingTable>())); recipe = new[] { log, null, null, null, null, null, null, null, null }; _recipeRegistry.RegisterRecipe(recipe, new ItemStack(wood, 4), true); recipe = new[] { wood, null, null, wood, null, null, null, null, null }; _recipeRegistry.RegisterRecipe(recipe, new ItemStack(stick, 4)); recipe = new[] { wood, wood, wood, null, wood, null, wood, wood, wood }; _recipeRegistry.RegisterRecipe(recipe, ItemRegistry.GetItem("sharpcraft", "ladder")); //foreach (ModMain mod in _installedMods) //{ //mod.OnRecipeRegistry(new RecipeRegistryEventArgs(_recipeRegistry)); //} //LangUtil.LoadLang(SettingsManager.GetString("lang"));//TODO - find a proper placement for this line }
public override void InitRecipes(RecipeRegistry registry) { Recipes recipes = new Recipes(); recipes.InjectAll(); }
public override void InitRecipes(RecipeRegistry registry) { }
public RegistryEventArgs(BlockRegistry blockRegistry, ItemRegistry itemRegistry, RecipeRegistry recipeRegistry) { _funcRegisterBlock = blockRegistry.Put; _funcRegisterItem = itemRegistry.Put; _funcRegisterRecipe = recipeRegistry.RegisterRecipe; }
public abstract void InitRecipes(RecipeRegistry registry);