public override void OnRightClick() { bool isUpper = (WireFrameHelper.data & 0b1000) > 0; int direction = 0; bool isOpen = false; if (isUpper) { NBTHelper.GetBlockData(WireFrameHelper.pos.x, WireFrameHelper.pos.y - 1, WireFrameHelper.pos.z, out byte belowType, out byte belowData); if (belowType == 64) { isOpen = (belowData & 0b0100) > 0; direction = belowData & 0b0011; } byte newData = (byte)(belowData ^ 0b0100); NBTHelper.SetBlockData(WireFrameHelper.pos + Vector3Int.down, WireFrameHelper.type, newData); } else { isOpen = (WireFrameHelper.data & 0b0100) > 0; byte newData = (byte)(WireFrameHelper.data ^ 0b0100); NBTHelper.SetBlockData(WireFrameHelper.pos, WireFrameHelper.type, newData); } SoundManager.Play2DSound(isOpen ? "Player_Door_Close" : "Player_Door_Open"); NBTChunk chunk = NBTHelper.GetChunk(WireFrameHelper.pos); chunk.RebuildMesh(UpdateFlags.Collidable); }
public override void OnAddBlock(RaycastHit hit) { Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage; if (hit.normal == Vector3.up || hit.normal == Vector3.down) { data |= 0b0000; } else if (hit.normal == Vector3.left || hit.normal == Vector3.right) { data |= 0b0100; } else if (hit.normal == Vector3.back || hit.normal == Vector3.forward) { data |= 0b1000; } NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
public virtual void OnAddBlock(RaycastHit hit) { Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage; NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
public override void OnAddBlock(RaycastHit hit) { Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); byte targetType = NBTHelper.GetBlockByte(pos); bool canAdd = false; byte type = NBTGeneratorManager.id2type[id]; byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage; Vector3Int finalPos = pos; if (targetType == 126) { canAdd = true; type = 125; } if (WireFrameHelper.generator is NBTWoodenSlab && (WireFrameHelper.data < 8 && hit.normal == Vector3.up) || (WireFrameHelper.data >= 8 && hit.normal == Vector3.down)) { canAdd = true; type = 125; finalPos = WireFrameHelper.pos; } if (targetType == 0 && CanAddBlock(pos)) { canAdd = true; if (WireFrameHelper.hitPos.y - pos.y > 0) { data += 8; } } if (canAdd) { PlayerController.instance.PlayHandAnimation(); NBTHelper.SetBlockData(finalPos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
// 0 = south // 1 = west // 2 = north // 3 = east public override void OnAddBlock(RaycastHit hit) { if (hit.normal == Vector3.down) { return; } Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte data = CalcBlockDirection(pos, 0, 1, 2, 3); NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
public override void OnAddBlock(RaycastHit hit) { if (hit.normal.y != 0) { return; } Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte data = 0; if (hit.normal == Vector3.back) { data = 2; } else if (hit.normal == Vector3.forward) { data = 3; } else if (hit.normal == Vector3.left) { data = 4; } else if (hit.normal == Vector3.right) { data = 5; } NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
void OnRightClick() { string id = InventorySystem.items[ItemSelectPanel.curIndex].id; if (WireFrameHelper.render && id != null) { Vector3Int pos = WireFrameHelper.pos; pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { handAnimator.SetTrigger("interactTrigger"); byte type = NBTGeneratorManager.id2type[id]; byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage; NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } } }
public override void OnAddBlock(RaycastHit hit) { Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); if (CanAddBlock(pos)) { PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte data = 0; Vector3 playerPos = PlayerController.instance.position; Vector2 dir = (new Vector2(playerPos.x, playerPos.z) - new Vector2(pos.x, pos.z)).normalized; if (dir.x > 0) { if (dir.y > 0) { if (dir.y > dir.x) { // positive z data = 3; } else { // positive x data = 1; } } else { if (-dir.y > dir.x) { // negative z data = 2; } else { // positive x data = 1; } } } else { if (dir.y > 0) { if (dir.y > -dir.x) { // positive z data = 3; } else { // negative x data = 0; } } else { if (-dir.y > -dir.x) { // negative z data = 2; } else { // negative x data = 0; } } } if (hit.point.y - pos.y > 0) { data += 4; } NBTHelper.SetBlockData(pos, type, data); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); } }
public override void OnAddBlock(RaycastHit hit) { if (hit.normal != Vector3.up) { return; } Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal); byte upperType = NBTHelper.GetBlockByte(pos + Vector3Int.up); byte lowerType = NBTHelper.GetBlockByte(pos); if (upperType != 0 || lowerType != 0) { return; } PlayerController.instance.PlayHandAnimation(); byte type = NBTGeneratorManager.id2type[id]; byte upperData = 0b1000; byte lowerData = 0b0000; Vector3 playerPos = PlayerController.instance.position; Vector2 dir = (new Vector2(playerPos.x, playerPos.z) - new Vector2(pos.x, pos.z)).normalized; Vector3 diff = WireFrameHelper.hitPos - pos; if (dir.x > 0) { if (dir.y > 0) { if (dir.y > dir.x) { // positive z lowerData = 3; if (diff.x > 0) { upperData |= 0b0001; } } else { // positive x lowerData = 2; if (diff.z < 0) { upperData |= 0b0001; } } } else { if (-dir.y > dir.x) { // negative z lowerData = 1; if (diff.x < 0) { upperData |= 0b0001; } } else { // positive x lowerData = 2; if (diff.z < 0) { upperData |= 0b0001; } } } } else { if (dir.y > 0) { if (dir.y > -dir.x) { // positive z lowerData = 3; if (diff.x > 0) { upperData |= 0b0001; } } else { // negative x lowerData = 0; if (diff.z > 0) { upperData |= 0b0001; } } } else { if (-dir.y > -dir.x) { // negative z lowerData = 1; if (diff.x < 0) { upperData |= 0b0001; } } else { // negative x lowerData = 0; if (diff.z > 0) { upperData |= 0b0001; } } } } NBTHelper.SetBlockData(pos + Vector3Int.up, type, upperData); NBTHelper.SetBlockData(pos, type, lowerData); InventorySystem.DecrementCurrent(); ItemSelectPanel.instance.RefreshUI(); }