public static void SetBlockByte(int x, int y, int z, byte type) { int chunkX = Mathf.FloorToInt(x / 16f); int chunkZ = Mathf.FloorToInt(z / 16f); int xInChunk = x - chunkX * 16; int zInChunk = z - chunkZ * 16; NBTChunk chunk = GetChunk(chunkX, chunkZ); NBTBlock oldGenerator = NBTGeneratorManager.GetMeshGenerator(chunk.GetBlockByte(xInChunk, y, zInChunk)); UpdateFlags updateFlag = GetUpdateFlags(oldGenerator); if (type == 0) { chunk.GetBlockData(xInChunk, y + 1, zInChunk, out byte topType, out byte topData); NBTBlock topGenerator = NBTGeneratorManager.GetMeshGenerator(topType); if (topGenerator != null && topGenerator is NBTPlant) { BreakBlockEffect.Create(topType, topData, new Vector3(x, y + 1, z)); chunk.SetBlockByte(xInChunk, y + 1, zInChunk, 0); updateFlag |= UpdateFlags.NotCollidable; } } chunk.SetBlockByte(xInChunk, y, zInChunk, type); if (updateFlag.HasFlag(UpdateFlags.Lighting)) { UpdateLighting(x, y, z); } chunk.RebuildMesh(updateFlag); NBTChunk leftChunk = GetChunk(chunkX - 1, chunkZ); if (xInChunk == 0) { leftChunk.RebuildMesh(); } NBTChunk rightChunk = GetChunk(chunkX + 1, chunkZ); if (xInChunk == 15) { rightChunk.RebuildMesh(); } NBTChunk backChunk = GetChunk(chunkX, chunkZ - 1); if (zInChunk == 0) { backChunk.RebuildMesh(); } NBTChunk frontChunk = GetChunk(chunkX, chunkZ + 1); if (zInChunk == 15) { frontChunk.RebuildMesh(); } }
void BreakBlock(Vector3Int pos) { if (Time.time - lastBreakTime < 0.1f) { return; } lastBreakTime = Time.time; breakingTime = 0; HideBreakingEffect(); //DeleteBlockReq(WireFrameHelper.pos); NBTBlock generator = WireFrameHelper.generator; if (generator.hasDropItem) { try { string id = generator.GetDropItemByData(WireFrameHelper.data); byte data = generator.GetDropItemData(WireFrameHelper.data); Item.CreateBlockDropItem(id, data, pos); } catch (System.Exception e) { Debug.LogError("create item error, id=" + generator.GetDropItemByData(WireFrameHelper.data) + ",generator=" + generator); } } generator.OnDestroyBlock(WireFrameHelper.pos, WireFrameHelper.data); if (generator.isTileEntity) { NBTChunk chunk = NBTHelper.GetChunk(WireFrameHelper.pos); chunk.RemoveTileEntity(WireFrameHelper.pos); NBTHelper.SetBlockByteNoUpdate(WireFrameHelper.pos, 0); } else { NBTHelper.SetBlockByte(WireFrameHelper.pos, 0); } //Item.CreateBlockDropItem(type, WireFrameHelper.pos); BreakBlockEffect.Create(WireFrameHelper.type, WireFrameHelper.data, WireFrameHelper.pos); SoundManager.PlayBreakSound(WireFrameHelper.type, instance.gameObject); }
public static void Create(byte type, byte data, Vector3 pos) { GameObject prefab = Resources.Load("Prefabs/BreakBlockEffect") as GameObject; GameObject go = Instantiate(prefab); go.transform.localPosition = pos; Destroy(go, 1); int chunkX = Mathf.FloorToInt(pos.x / 16f); int chunkZ = Mathf.FloorToInt(pos.z / 16f); NBTChunk chunk = NBTHelper.GetChunk(chunkX, chunkZ); BreakBlockEffect effect = go.AddComponent <BreakBlockEffect>(); NBTBlock block = NBTGeneratorManager.GetMeshGenerator(type); effect.texturePath = block.GetBreakEffectTexture(chunk, data); effect.tintColor = block.GetFrontTintColorByData(chunk, data); }
public static void RemoveBlock(int x, int y, int z, bool removeBeDependBlocks = true, bool refreshChunks = true) { Chunk chunk = GetChunk(x, y, z); if (chunk != null) { int xInChunk = chunk.GetXInChunkByGlobalX(x); int zInChunk = chunk.GetZInChunkByGlobalZ(z); CSBlockType type = chunk.GetBlockType(xInChunk, y, zInChunk); chunk.SetBlockType(xInChunk, y, zInChunk, CSBlockType.None); Vector3Int pos = new Vector3Int(x, y, z); RemoveBlockOrientation(pos); RemoveBlockDependence(pos); if (removeBeDependBlocks) { RemoveDependingBlocks(pos); // removes block on top if exists if (chunk.HasNotCollidableBlock(xInChunk, y + 1, zInChunk)) { RemoveBlock(x, y + 1, z, false, false); } } if (refreshChunks) { chunk.RebuildMesh(); // if this block is adjacent to other chunks, refresh nearby chunks foreach (Chunk nearbyChunk in GetNearbyChunks(xInChunk, zInChunk, chunk)) { nearbyChunk.RebuildMesh(); } } Item.CreateBlockDropItem(type, pos); BreakBlockEffect.Create(type, pos); SoundManager.PlayBreakSound(type, PlayerController.instance.gameObject); } }
public override void onConstruct() { base.onConstruct(); this.mainCamera = Camera.main.transform; this.dataHotbar = new ContainerData(9, 1); this.dataInventory = new ContainerData(5, 5); this.contManager = Main.singleton.containerManager; this.containerHotbar = ContainerManager.containerHotbar; this.containerHotbar.onOpen(this.dataHotbar, this); this.playerMover = new PlayerMover(this); this.blockBreakEffect = GameObject.Instantiate(References.list.blockBreakEffect).GetComponent <BreakBlockEffect>(); this.wsTooltip = GameObject.Instantiate(References.list.worldSpaceTooltipPrefab).GetComponent <WorldSpaceToolTip>().setPlayer(this); this.setMaxHealth(100); this.setShadow(0.75f, 0.6f); }
void BreakBlock(Vector3Int pos) { breakTime = 0; handAnimator.SetBool("isBreaking", false); HideBreakingEffect(); //DeleteBlockReq(WireFrameHelper.pos); NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(WireFrameHelper.type); if (generator.hasDropItem) { Item.CreateBlockDropItem(generator.GetDropItemByData(WireFrameHelper.data), WireFrameHelper.data, pos); } NBTHelper.SetBlockByte(WireFrameHelper.pos, 0); //Item.CreateBlockDropItem(type, WireFrameHelper.pos); BreakBlockEffect.Create(WireFrameHelper.type, WireFrameHelper.data, WireFrameHelper.pos); SoundManager.PlayBreakSound(WireFrameHelper.type, instance.gameObject); }
public static void Create(CSBlockType type, Vector3 pos) { GameObject prefab = Resources.Load("Prefabs/BreakBlockEffect") as GameObject; GameObject go = Instantiate(prefab); go.transform.localPosition = pos; Destroy(go, 1); BreakBlockEffect effect = go.AddComponent <BreakBlockEffect>(); Vector2Int uv = Vector2Int.zero; if (type2breakEffect.ContainsKey(type)) { uv = type2breakEffect[type]; } else { uv = ChunkMeshGenerator.type2texcoords[(byte)type].front; } effect.x = uv.x; effect.y = uv.y; }