protected override void CreateJoints() { StructureBlock sb = GetClosestStructureBlockToPos(transform.position); if (Equals(sb, null)) { Destroy(gameObject); return; } UIController.Instance.tutorialPart(4); sb.placeSound.play(); GameController.instance.removeGold(cost); sb.disableTurretAttachPoint(); HingeJoint2D fj = gameObject.AddComponent <HingeJoint2D>(); fj.connectedBody = sb.GetComponent <Rigidbody2D>(); transform.parent = sb.transform; }
protected void CreateJoints() { for (int i = 0; i < AttachPoints.Length; i++) { StructureBlock sb = GetClosestStructureBlockToPos(AttachPoints[i].transform.position); if (Equals(sb, null)) { continue; } FixedJoint2D fj = gameObject.AddComponent <FixedJoint2D>(); fj.connectedBody = sb.GetComponent <Rigidbody2D>(); Vector2 anchor = fj.connectedAnchor; anchor.x = Mathf.Round(anchor.x * 100) / 100; anchor.y = Mathf.Round(anchor.y * 100) / 100; fj.autoConfigureConnectedAnchor = false; fj.connectedAnchor = anchor; fj.dampingRatio = 1; fj.breakTorque = jointBreakTorque; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Terrain") { flying = false; } if (collision.gameObject.tag == "StructureBlock" && !impacted) { if (collision.gameObject.GetComponent <Core>() != null) { Core core = collision.gameObject.GetComponent <Core>(); if (core.isDead()) { UIController.Instance.LoseWave(); Destroy(core); } core.doDamage(damage); } else if (collision.gameObject.GetComponent <StructureBlock>() != null) { StructureBlock structure = collision.gameObject.GetComponent <StructureBlock>(); if (structure.isDead()) { Destroy(structure); } structure.doDamage(damage); } } Rigidbody2D rb = collision.gameObject.GetComponent <Rigidbody2D>(); if (rb != null) { CreateJoint(rb); } Destroy(gameObject, deathDelay); impacted = true; }
public static void MountJail(ref Jail jail) { HashSet <Block> bloks = new HashSet <Block>(); HashSet <StructureBlock> structureBlocks = new HashSet <StructureBlock>(); StructureBlock structureBlock = new StructureBlock(); Character character; character = FactoryCharacters.CreateCharacter("Jose", "JZ", EnumCharacters.Thief); structureBlock = FactoryStructureBlock.CreateStructureBlock(EnumStructureBlocks.Hall); structureBlock.Characters.Add(character); structureBlocks.Add(structureBlock); structureBlocks.Add(FactoryStructureBlock.CreateStructureBlock(EnumStructureBlocks.Saddle)); structureBlocks.Add(FactoryStructureBlock.CreateStructureBlock(EnumStructureBlocks.Saddle)); structureBlocks.Add(FactoryStructureBlock.CreateStructureBlock(EnumStructureBlocks.Saddle)); structureBlocks.Add(FactoryStructureBlock.CreateStructureBlock(EnumStructureBlocks.Saddle)); bloks.Add(CreateBloks(1, structureBlocks)); jail = new Jail("hell", 10, "são tomé e príncipe", bloks); }
public void DisplaySelection(bool forceDisplay = false, bool forceHide = false) { if (!forceDisplay && _structureBlockBlockEntity != null && (forceHide || _structureBlockBlockEntity.ShowBoundingBox != ShowSelection)) { bool showBoundingBox = !forceHide && ShowSelection; if (_structureBlockBlockEntity.ShowBoundingBox == showBoundingBox) { return; } _structureBlockBlockEntity.ShowBoundingBox = showBoundingBox; var nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, UseVarInt = true, RootTag = _structureBlockBlockEntity.GetCompound() } }; var entityData = McpeBlockEntityData.CreateObject(); entityData.namedtag = nbt; entityData.coordinates = _structureBlockBlockEntity.Coordinates; Player.SendPacket(entityData); } if (forceHide) { return; } if (!forceDisplay && !ShowSelection) { return; // don't render at all } if (forceDisplay && ShowSelection) { return; // Will be rendered on regular tick instead } if (!Monitor.TryEnter(_sync)) { return; } try { BoundingBox box = GetSelection().GetAdjustedBoundingBox(); if (!forceDisplay && box == _currentDisplayedSelection) { return; } _currentDisplayedSelection = box; int minX = (int)Math.Min(box.Min.X, box.Max.X); int maxX = (int)(Math.Max(box.Min.X, box.Max.X) + 1); int minY = (int)Math.Max(0, Math.Min(box.Min.Y, box.Max.Y)); int maxY = (int)(Math.Min(255, Math.Max(box.Min.Y, box.Max.Y)) + 1); int minZ = (int)Math.Min(box.Min.Z, box.Max.Z); int maxZ = (int)(Math.Max(box.Min.Z, box.Max.Z) + 1); int width = maxX - minX; int height = maxY - minY; int depth = maxZ - minZ; if (_structureBlock != null) { { var block = Player.Level.GetBlock(_structureBlock.Coordinates); var updateBlock = McpeUpdateBlock.CreateObject(); updateBlock.blockRuntimeId = (uint)block.GetRuntimeId(); updateBlock.coordinates = _structureBlock.Coordinates; updateBlock.blockPriority = 0xb; Player.SendPacket(updateBlock); } _structureBlock = null; _structureBlockBlockEntity = null; } _structureBlock = new StructureBlock { StructureBlockType = "save", Coordinates = new BlockCoordinates(minX, 255, minZ), }; { var updateBlock = McpeUpdateBlock.CreateObject(); updateBlock.blockRuntimeId = (uint)_structureBlock.GetRuntimeId(); updateBlock.coordinates = _structureBlock.Coordinates; updateBlock.blockPriority = 0xb; Player.SendPacket(updateBlock); } _structureBlockBlockEntity = new StructureBlockBlockEntity { ShowBoundingBox = true, Coordinates = _structureBlock.Coordinates, Offset = new BlockCoordinates(0, minY - _structureBlock.Coordinates.Y, 0), Size = new BlockCoordinates(width, height, depth) }; { Log.Debug($"Structure:\n{box}\n{_structureBlockBlockEntity.GetCompound()}"); var nbt = new Nbt { NbtFile = new NbtFile { BigEndian = false, UseVarInt = true, RootTag = _structureBlockBlockEntity.GetCompound() } }; var entityData = McpeBlockEntityData.CreateObject(); entityData.namedtag = nbt; entityData.coordinates = _structureBlockBlockEntity.Coordinates; Player.SendPacket(entityData); } return; } catch (Exception e) { Log.Error("Display selection", e); } finally { Monitor.Exit(_sync); } }
static void FindTreeType(Vector3Int minMid, Dictionary <ushort, int> spawnedTypesBuffer) { ThreadManager.AssertIsMainThread(); if (countableTypes == null) { countableTypes = ItemTypes._TypeByUShort.Values .Where(val => val.HasBehaviour("log")) .Concat(ItemTypes._TypeByUShort.Values.Where(val => val.HasBehaviour("leaves"))) .Select(type => type.ItemIndex) .ToList(); } spawnedTypesBuffer.Clear(); spawnedTypesBuffer[BuiltinBlocks.Indices.logtemperate] = 3; spawnedTypesBuffer[BuiltinBlocks.Indices.leavestemperate] = 10; if (!(ServerManager.TerrainGenerator is TerrainGenerator terrainGen)) { return; } var gen = terrainGen.StructureGenerator; while (gen != null && !(gen is TerrainGenerator.DefaultTreeStructureGenerator)) { gen = gen.InnerGenerator; } if (gen == null) { return; } var treeGen = (TerrainGenerator.DefaultTreeStructureGenerator)gen; terrainGen.QueryTempPrecip(minMid.x, minMid.z, out float temp, out float precip); TerrainGenerator.MetaBiomeLocation metaBiomeLocation = terrainGen.MetaBiomeProvider.GetChunkMetaBiomeLocation(minMid.x, minMid.z); int max = treeGen.ItemIndices.Length - 1; for (int itemIndex = treeGen.ItemIndices[Math.Clamp((int)(temp - TerrainGenerator.MinimumTemperature), 0, max)]; itemIndex < treeGen.ItemsLocations.Length; itemIndex++) { TerrainGenerator.BiomeConfigLocation location = treeGen.ItemsLocations[itemIndex]; if (!location.IsValid(temp, precip)) { continue; } if (temp + 1f < location.MinTemperature) { return; } if (!treeGen.RequiresMetaBiome[itemIndex].Contains(metaBiomeLocation)) { continue; } TerrainGenerator.DefaultTreeStructureGenerator.ItemPointerData items = treeGen.ItemsGrid[itemIndex]; if (items.Pointers == null) { return; } for (int pointerIndex = 0; pointerIndex < items.Pointers.Length; pointerIndex++) { TerrainGenerator.DefaultTreeStructureGenerator.ItemPointer item = items.Pointers[pointerIndex]; StructureBlock[] blocks = treeGen.ItemBlocks[item.Index].Blocks; if (blocks == null || blocks.Length == 0) { continue; } for (int blockIndex = 0; blockIndex < blocks.Length; blockIndex++) { StructureBlock block = blocks[blockIndex]; if (countableTypes.Contains(block.Type)) { if (spawnedTypesBuffer.TryGetValue(block.Type, out int val)) { spawnedTypesBuffer[block.Type] = val + 1; } else { spawnedTypesBuffer[block.Type] = 1; } } } } } }