//TODO - clientside only public WorldClient(string saveName, string levelName, string seed) : base(saveName, levelName, seed) { foreach (var block in BlockRegistry.AllBlocks()) { _worldLut.Put(block.UnlocalizedName); } }
public WorldServer() : base("world", "world", "0") { foreach (var block in BlockRegistry.AllBlocks()) { _worldLut.Put(block.UnlocalizedName); } }
private void RegisterItemsAndBlocks() { 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()); //POST - MOD Blocks and Items foreach (ModMain mod in installedMods) { mod.OnItemsAndBlocksRegistry(new RegistryEventArgs(blockRegistry, itemRegistry)); } foreach (var block in BlockRegistry.AllBlocks()) { itemRegistry.Put(new ItemBlock(block)); } JsonModelLoader loader = new JsonModelLoader(Block.DefaultShader); blockRegistry.RegisterBlocksPost(loader); itemRegistry.RegisterItemsPost(loader); }
public World(string saveName, string levelName, int seed) { _noiseUtil = new NoiseUtil(Seed = seed); _noiseUtil.SetFractalType(NoiseUtil.FractalType.FBM); LevelName = levelName; SaveRoot = $"{SharpCraft.Instance.GameFolderDir}/saves/{saveName}/"; ChunkData = new ChunkDataManager <RegionStaticImpl <ChunkPos>, ChunkPos>( $"{SaveRoot}{_dimension}/region", new RegionInfo <ChunkPos>(new[] { 12, 12 }, 2 * Chunk.ChunkSize * Chunk.ChunkHeight * Chunk.ChunkSize), RegionStaticImpl <ChunkPos> .Ctor, ChunkPos.Ctor); _worldLut = new WorldLut(); foreach (var block in BlockRegistry.AllBlocks()) { _worldLut.Put(block.UnlocalizedName); } }
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 void LoadBlockModels() { string modelsDir = $"{SharpCraft.Instance.GameFolderDir}/assets/sharpcraft/models"; string blockModelsDir = $"{modelsDir}/block"; string blockStatesDir = $"{modelsDir}/block/states"; var listOfBlocks = BlockRegistry.AllBlocks(); var nonDuplicateTextures = new List <string>(); var blockModels = new ConcurrentDictionary <string, List <List <JsonModel> > >(); foreach (var block in listOfBlocks) // for each Block that's been registered { var states = new List <List <JsonModel> >(); //save state models for each block blockModels.TryAdd(block.UnlocalizedName, states); string unlocalizedLast = LangUtil.GetUnlocalizedNameLast(block.UnlocalizedName); List <string> stateFiles = new List <string> { $"{blockModelsDir}/{unlocalizedLast}.json" }; string statesFile = $"{blockStatesDir}/{unlocalizedLast}.json"; if (File.Exists(statesFile)) { try { string json = File.ReadAllText(statesFile); JsonBlockStates jbs = JsonConvert.DeserializeObject <JsonBlockStates>(json); if (jbs.states != null) { foreach (var modelFileName in jbs.states) { var stateFile = $"{modelsDir}/{modelFileName.model}.json"; if (File.Exists(stateFile)) { stateFiles.Add(stateFile); } } } } catch { } } foreach (var stateFile in stateFiles) { //load state var models = LoadModel(stateFile, "particle"); foreach (var jsonModel in models) { if (jsonModel.textures == null) { continue; } foreach (var textureName in jsonModel.textures.Values) //iterating over the textureMap in the Json model { if (!nonDuplicateTextures.Contains(textureName)) { nonDuplicateTextures.Add(textureName); //add the current texture name to a list of all textureMap if isn't already there } } } states.Add(models); } } //each texture name has it's UV values TODO - maybe make a TextureMap class where this could be used var id = Stitch(nonDuplicateTextures.ToArray(), 16, out var textureMapElements); // stitch all textureMap, return the texture ID of the registered texture in VRAM //TODO - if json doesn't contain cube model, assume it's a full cube foreach (var pair in blockModels) //one model per registered item { string blockName = pair.Key; var states = new List <ModelBlock>(); foreach (var state in pair.Value) { List <float> vertexes = new List <float>(); List <float> normals = new List <float>(); List <float> uvs = new List <float>(); List <JsonCube> cubes = new List <JsonCube>(); Dictionary <string, string> textures = new Dictionary <string, string>(); foreach (var jsonModel in state) { foreach (var cube in jsonModel.cubes) { cubes.Add(cube); } if (jsonModel.textures == null) { continue; } foreach (var pairtex in jsonModel.textures) { textures.Remove(pairtex.Key); textures.Add(pairtex.Key, pairtex.Value); } } foreach (var cube in cubes) { CubeModelBuilder.AppendCubeModel(cube, textures, textureMapElements, ref vertexes, ref normals, ref uvs); } if (!textures.TryGetValue("particle", out var particleTexture)) { particleTexture = textures.Values.ToArray()[SharpCraft.Instance.Random.Next(0, textures.Count)]; } if (!textures.TryGetValue("item", out var slotTexture)) { if (cubes.Count > 0 && cubes[0].faces.TryGetValue(Facing.south, out var uv)) { slotTexture = textures[uv.texture]; } } var particleTme = textureMapElements[particleTexture]; var slotTme = textureMapElements.TryGetValue(slotTexture ?? "", out var result) ? result : particleTme; ModelBlock mb = new ModelBlock(slotTme, particleTme, _blockShader, ModelManager.LoadBlockModelToVao(vertexes.ToArray(), normals.ToArray(), uvs.ToArray())); states.Add(mb); } BlockStateModels.TryAdd(blockName, states); } TextureBlocks = id; }
private static int LoadBlocks() { string dir = $"{SharpCraft.Instance.GameFolderDir}\\SharpCraft_Data\\assets\\models\\block"; if (!Directory.Exists(dir)) { return(0); } var listOfBlocks = BlockRegistry.AllBlocks(); List <string> nonDuplicateTextures = new List <string>(); var blockModels = new ConcurrentDictionary <string, JsonBlockModel>(); foreach (var block in listOfBlocks) { string file = $"{dir}\\{block.UnlocalizedName}.json"; if (!File.Exists(file)) { continue; } JsonBlockModel bjm = FixBlockJson(file); string blockName = Path.GetFileNameWithoutExtension(file); blockModels.TryAdd(blockName, bjm); //save what block is using what model foreach (var pair in bjm.textures) //iterating over the textureMap in the Json model { if (!nonDuplicateTextures.Contains(pair.Value)) { nonDuplicateTextures.Add(pair.Value); //add the current texture name to a list of all textureMap if isn't already there } } } var textureMapElements = new Dictionary <string, TextureMapElement>(); //each texture name has it's UV values TODO - maybe make a TextureMap class where this could be used var id = Stitch(nonDuplicateTextures.ToArray(), 16, textureMapElements); // stitch all textureMap, return the texture ID of the registered texture in VRAM //TODO - if json doesn't contain cube model, assume it's a full cube foreach (var pair in blockModels) //one model per registered block { string name = pair.Key; JsonBlockModel model = pair.Value; float[] vertexes = new float[72 * model.cubes.Length]; float[] normals = new float[72 * model.cubes.Length]; float[] uvs = new float[48 * model.cubes.Length]; for (var index = 0; index < model.cubes.Length; index++) { var cube = model.cubes[index]; CubeModelBuilder.AppendCubeModel(cube, model.textures, textureMapElements, ref vertexes, ref normals, ref uvs, index); } string particleTextureName; if (!model.textures.TryGetValue("particle", out particleTextureName)) { particleTextureName = model.textures.Values.ToArray()[SharpCraft.Instance.Random.Next(0, model.textures.Count)]; } var tme = textureMapElements[particleTextureName]; ModelBlock mb = new ModelBlock(tme, _blockShader, ModelManager.LoadBlockModelToVao(vertexes, normals, uvs)); _blockModels.TryAdd(name, mb); } return(id); }