void ParseSignInfo(TileEntitySign SignEntity, int X, int Y, int Z, ChunkRef Chunk) { // *** Try to create a sign from the entity. NULL will be returned if the sign doesn't map to anything. SignBase Sign = CreateSign(SignEntity.Text1); if (Sign == null) { return; } // *** Pre-set the Location var... Sign.Location = new Point(SignEntity.X, SignEntity.Z); // *** ...and pass control to the sign's validation/setup function. if (!Sign.CreateFrom(SignEntity)) { return; } // *** Now scan for and process any "rider" signs that might add additional information. TileEntity Ent; // *** This is kind of ugly but oh well do { Ent = Chunk.Blocks.SafeGetTileEntity(X, --Y, Z); } while (Y > 0 && Ent is TileEntitySign && Sign.AddSign((TileEntitySign)Ent)); if (Sign.IsValid()) { _ExportableSigns.Add(Sign); } }
public BCMTileEntitySign(Vector3i pos, [NotNull] TileEntitySign te) : base(pos, te) { Owner = te.GetOwner(); Users = te.GetUsers(); HasPassword = te.HasPassword(); IsLocked = te.IsLocked(); Text = te.GetText(); }
public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { if (_blockValue.ischild) { Vector3i parentPos = Block.list[_blockValue.type].multiBlockPos.GetParentPos(_blockPos, _blockValue); BlockValue block = _world.GetBlock(parentPos); return(this.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, parentPos, block, _player)); } TileEntitySign tileEntitySign = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySign; if (tileEntitySign == null) { return(false); } switch (_indexInBlockActivationCommands) { case 0: if (GameManager.Instance.IsEditMode() || !tileEntitySign.IsLocked() || tileEntitySign.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId))) { return(this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player)); } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked"); return(false); case 1: tileEntitySign.SetLocked(true); Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locking"); GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerLocked"); return(true); case 2: tileEntitySign.SetLocked(false); Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking"); GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerUnlocked"); return(true); case 3: XUiC_KeypadWindow.Open(LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal), tileEntitySign); return(true); case 4: LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal); ItemStack itemStack = new ItemStack(_blockValue.ToItemValue(), 1); if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack)) { uiforPlayer.xui.PlayerInventory.DropItem(itemStack); } _world.SetBlockRPC(_cIdx, _blockPos, BlockValue.Air); return(true); default: return(false); } }
static void setBlock(ChunkRef chunk, int x, int y, int z, int color, string text) { if (color < 16) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.WOOL, color)); } else if (color == 16) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.GRASS)); } else if (color == 17) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.WOOD)); } else if (color == 18) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.LEAVES)); } else if (color == 19) { AlphaBlock block = new AlphaBlock(63); TileEntitySign tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x, y, z + 1, block); block = new AlphaBlock(63, 8); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x, y, z - 1, block); block = new AlphaBlock(63, 4); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x - 1, y, z, block); block = new AlphaBlock(63, 12); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x + 1, y, z, block); } else if (color == 20) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.GLASS)); } }
public void SetupAutoPathingBlocks() { if (this.Buffs.HasCustomVar("PathingCode")) { return; } // Check if pathing blocks are defined. List <string> Blocks = EntityUtilities.ConfigureEntityClass(this.entityId, "PathingBlocks"); if (Blocks.Count == 0) { Blocks = new List <string>() { "PathingCube" } } ; //Scan for the blocks in the area List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(this.position, Blocks, this.entityId); if (PathingVectors == null || PathingVectors.Count == 0) { return; } // Find the nearest block, and if its a sign, read its code. Vector3 target = ModGeneralUtilities.FindNearestBlock(this.position, PathingVectors); TileEntitySign tileEntitySign = GameManager.Instance.World.GetTileEntity(0, new Vector3i(target)) as TileEntitySign; if (tileEntitySign == null) { return; } // Since signs can have multiple codes, splite with a ,, parse each one. String text = tileEntitySign.GetText(); float code = 0f; // Defined here as DMT compiler doesn't like inlining it. foreach (String temp in text.Split(',')) { if (StringParsers.TryParseFloat(temp, out code)) { this.Buffs.AddCustomVar("PathingCode", code); return; } } }
public static bool Prefix(TileEntitySign __instance, SmartTextMesh ___smartTextMesh, string _text) { if (GameManager.IsDedicatedServer) { return(true); } if (___smartTextMesh == null) { return(true); } if (_text.StartsWith("http")) { ImageWrapper wrapper = ___smartTextMesh.transform.parent.transform.GetComponent <ImageWrapper>(); if (wrapper == null) { wrapper = ___smartTextMesh.transform.parent.transform.gameObject.AddComponent <ImageWrapper>(); } // Check for supported url, and do some converting if necessary if (!wrapper.ValidURL(ref _text)) { Debug.Log("ImageWrapper: Only supported files: .gif, .gifs, .jpg, and .png"); return(true); } if (wrapper.IsNewURL(_text)) { wrapper.Pause(); wrapper.Init(_text); __instance.SetModified(); } ___smartTextMesh.gameObject.SetActive(false); } else { ImageWrapper wrapper = ___smartTextMesh.transform.parent.transform.GetComponent <ImageWrapper>(); if (wrapper != null) { // wrapper.Reset(); } ___smartTextMesh.gameObject.SetActive(true); } return(true); }
public static void InsertBuilding(BlockManager bmDest, int intBlockStart, int x1dest, int z1dest, Building bldInsert) { for (int x = 0; x < bldInsert.intSize; x++) { for (int z = 0; z < bldInsert.intSize; z++) { for (int y = 45; y <= 80; y++) { if (y != 64 || bmDest.GetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest) == (int)BlockType.AIR) { int intBlockID = bmSource.GetID(x + bldInsert.intSourceX, y, z + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, bmSource.GetData(x + bldInsert.intSourceX, y, z + bldInsert.intSourceZ)); switch (intBlockID) { case (int)BlockType.CHEST: case (int)BlockType.FURNACE: case (int)BlockType.MONSTER_SPAWNER: case (int)BlockType.NOTE_BLOCK: case (int)BlockType.JUKEBOX: case (int)BlockType.TRAPDOOR: bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, bmSource.GetTileEntity(x + bldInsert.intSourceX, y, z + bldInsert.intSourceZ)); break; case (int)BlockType.SIGN_POST: case (int)BlockType.WALL_SIGN: TileEntitySign tes = (TileEntitySign)bmSource.GetTileEntity(x + bldInsert.intSourceX, y, z + bldInsert.intSourceZ); if (tes.Text1.StartsWith("[") && tes.Text1.EndsWith("]")) { string[] strRandomSign = BlockHelper.TextToSign(SignText(tes.Text1)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; } bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, tes); break; } } } } } }
void ProcessChunk(ChunkRef Chunk) { AlphaBlockCollection Blocks = Chunk.Blocks; for (int ChunkX = 0; ChunkX < 16; ChunkX++) { for (int ChunkZ = 0; ChunkZ < 16; ChunkZ++) { for (int ChunkY = 0; ChunkY < 128; ChunkY++) { TileEntity Entity = Blocks.SafeGetTileEntity(ChunkX, ChunkY, ChunkZ); TileEntitySign Sign = Entity as TileEntitySign; if (Sign != null) { ParseSignInfo(Sign, ChunkX, ChunkY, ChunkZ, Chunk); } } } } }
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing) { TileEntitySign tileEntitySign = (TileEntitySign)_world.GetTileEntity(_clrIdx, _blockPos); if (tileEntitySign == null) { return(new BlockActivationCommand[0]); } string @string = GamePrefs.GetString(EnumGamePrefs.PlayerId); PersistentPlayerData playerData = _world.GetGameManager().GetPersistentPlayerList().GetPlayerData(tileEntitySign.GetOwner()); bool flag = !tileEntitySign.IsOwner(@string) && (playerData != null && playerData.ACL != null) && playerData.ACL.Contains(@string); this.cmds[0].enabled = true; this.cmds[1].enabled = (!tileEntitySign.IsLocked() && (tileEntitySign.IsOwner(@string) || flag)); this.cmds[2].enabled = (tileEntitySign.IsLocked() && tileEntitySign.IsOwner(@string)); this.cmds[3].enabled = ((!tileEntitySign.IsUserAllowed(@string) && tileEntitySign.HasPassword() && tileEntitySign.IsLocked()) || tileEntitySign.IsOwner(@string)); this.cmds[4].enabled = ((!tileEntitySign.IsUserAllowed(@string) && tileEntitySign.HasPassword() && tileEntitySign.IsLocked()) || tileEntitySign.IsOwner(@string)); return(this.cmds); }
public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart, int x1dest, int z1dest, Building bldInsert) { lstInstanceSigns.Clear(); int intHighestSourceY = 0; int intSourceX = 0, intSourceZ = 0; int intRotate = -1; for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++) { for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSize; intCheck++) { if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1) { intRotate = 0; } else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1) { intRotate = 1; } else if (CheckArea(intArea, x1dest + bldInsert.intSize + intDistance, z1dest + intCheck) == 1) { intRotate = 2; } else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSize + intDistance) == 1) { intRotate = 3; } } } if (intRotate == -1) { intRotate = RandomHelper.Next(4); } for (int x = 0; x < bldInsert.intSize; x++) { for (int z = 0; z < bldInsert.intSize; z++) { switch (intRotate) { case 0: intSourceX = x; intSourceZ = z; break; case 1: intSourceX = (bldInsert.intSize - 1) - z; intSourceZ = x; break; case 2: intSourceX = z; intSourceZ = (bldInsert.intSize - 1) - x; break; case 3: intSourceX = (bldInsert.intSize - 1) - x; intSourceZ = (bldInsert.intSize - 1) - z; break; } int intSourceEndY; for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--) { if (bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY, intSourceZ + bldInsert.intSourceZ) != (int)BlockType.AIR) { break; } } if (intSourceEndY > intHighestSourceY) { intHighestSourceY = intSourceEndY; } for (int y = bldInsert.intSourceStartY; y <= intSourceEndY; y++) { if (y != 64 || bmDest.GetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest) == (int)BlockType.AIR) { int intBlockID = bmSource.GetID(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); int intBlockData = bmSource.GetData(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, intBlockData); foreach (EntityPainting entPainting in AllEntityPainting) { if (entPainting.TileX == intSourceX + bldInsert.intSourceX && entPainting.TileY == y && entPainting.TileZ == intSourceZ + bldInsert.intSourceZ) { EntityPainting entNewPainting = (EntityPainting)entPainting.Copy(); entNewPainting.TileX = intBlockStart + x + x1dest; entNewPainting.TileY = y; entNewPainting.TileZ = intBlockStart + z + z1dest; entNewPainting.Position.X = entNewPainting.TileX; entNewPainting.Position.Z = entNewPainting.TileZ; entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction, intRotate); ChunkRef chunkBuilding = cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16, (intBlockStart + z + z1dest) / 16); chunkBuilding.Entities.Add(entNewPainting); cmDest.Save(); } } #region Rotation if (intRotate > 0) { switch (intBlockID) { case (int)BlockType.SIGN_POST: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateSignPost(intBlockData, intRotate)); break; case (int)BlockType.STONE_BUTTON: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateButton(intBlockData, intRotate)); break; case (int)BlockType.PUMPKIN: case (int)BlockType.JACK_O_LANTERN: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotatePumpkin(intBlockData, intRotate)); break; case (int)BlockType.IRON_DOOR: case (int)BlockType.WOOD_DOOR: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateDoor(intBlockData, intRotate)); break; case (int)BlockType.TRAPDOOR: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateTrapdoor(intBlockData, intRotate)); break; case (int)BlockType.BED: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateBed(intBlockData, intRotate)); break; case (int)BlockType.REDSTONE_TORCH_OFF: case (int)BlockType.REDSTONE_TORCH_ON: case (int)BlockType.TORCH: case (int)BlockType.LEVER: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateTorchOrLever(intBlockData, intRotate)); break; case (int)BlockType.WALL_SIGN: case (int)BlockType.LADDER: case (int)BlockType.DISPENSER: case (int)BlockType.FURNACE: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser(intBlockData, intRotate)); break; case (int)BlockType.COBBLESTONE_STAIRS: case (int)BlockType.WOOD_STAIRS: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateStairs(intBlockData, intRotate)); break; } } #endregion #region Handle entities switch (intBlockID) { case (int)BlockType.CHEST: TileEntityChest tec = (TileEntityChest)bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); if (tec.Items[0] != null) { if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 3) { tec = MakeHouseChest(); } } bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, tec); break; case (int)BlockType.FURNACE: case (int)BlockType.MONSTER_SPAWNER: case (int)BlockType.NOTE_BLOCK: case (int)BlockType.JUKEBOX: case (int)BlockType.TRAPDOOR: bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ)); break; case (int)BlockType.SIGN_POST: case (int)BlockType.WALL_SIGN: #region Determine sign text int intUniqueType = 0; TileEntitySign tes = (TileEntitySign)bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4; switch (strSourceSign.Substring(0, 1)) { case "2": case "1": case "0": intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1)); strSourceSign = strSourceSign.Remove(0, 1); break; default: intUniqueType = 0; break; } if (strSourceSign.Contains("[")) { string strSignText; bool booDuplicate; int intFail = 0; do { strSignText = SignText(strSourceSign); booDuplicate = false; switch (intUniqueType) { case 1: // unique by instance booDuplicate = lstInstanceSigns.Contains(strSignText); break; case 2: // unique by city booDuplicate = lstCitySigns.Contains(strSignText); break; } intFail++; if (intFail > 100) { Debug.WriteLine("Could not make a unique sign for " + strSourceSign); booDuplicate = false; } } while (booDuplicate); lstCitySigns.Add(strSignText); lstInstanceSigns.Add(strSignText); string[] strRandomSign = BlockHelper.TextToSign(ConvertToSignText(strSignText)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; } bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, tes); break; #endregion } #endregion } } } } }
// The method will scan a distance of MaxDistance around the entity, finding the nearest block that matches in the list. public static List <Vector3> ScanForBlockInListHelper(Vector3 centerPosition, List <String> lstBlocks, int MaxDistance, int EntityID = -1) { if (lstBlocks.Count == 0) { return(null); } List <Vector3> localLists = new List <Vector3>(); Vector3i TargetBlockPosition = new Vector3i(); if (EntityID < 0) { return(null); } EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(null); } // Check if the entity has a PathingCode already. If it doesn't, use a default of 0. float code = 0; if (myEntity.Buffs.HasCustomVar("PathingCode")) { code = EntityUtilities.GetCVarValue(EntityID, "PathingCode"); } else { myEntity.Buffs.AddCustomVar("PathingCode", 0f); } for (var x = (int)centerPosition.x - MaxDistance; x <= centerPosition.x + MaxDistance; x++) { for (var z = (int)centerPosition.z - MaxDistance; z <= centerPosition.z + MaxDistance; z++) { for (var y = (int)centerPosition.y - MaxDistance; y <= centerPosition.y + MaxDistance; y++) { TargetBlockPosition.x = x; TargetBlockPosition.y = y; TargetBlockPosition.z = z; BlockValue block = GameManager.Instance.World.GetBlock(TargetBlockPosition); if (block.ischild) { continue; } // if its not a listed block, then keep searching. if (!lstBlocks.Contains(block.Block.GetBlockName())) { continue; } TileEntitySign tileEntitySign = GameManager.Instance.World.GetTileEntity(0, TargetBlockPosition) as TileEntitySign; if (tileEntitySign != null) { // If the sign is empty and the code is 0, then accept it as a path String text = tileEntitySign.GetText(); if (String.IsNullOrEmpty(text) && code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); continue; } foreach (String temp in text.Split(',')) { if (code.ToString() == temp || code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); break; } } continue; } localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); } } } return(localLists); }
// The method will scan a distance of MaxDistance around the entity, finding the nearest block that matches in the list. public static List <Vector3> ScanForTileEntityInChunksListHelper(Vector3 centerPosition, List <String> lstBlocks, int EntityID = -1) { if (lstBlocks == null || lstBlocks.Count == 0) { lstBlocks = new List <string>() { "PathingCube" } } ; if (EntityID < 0) { return(null); } EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(null); } // Check if the entity has a PathingCode already. If it doesn't, use a default of 0. float code = 0f; if (myEntity.Buffs.HasCustomVar("PathingCode")) { code = EntityUtilities.GetCVarValue(EntityID, "PathingCode"); } else { myEntity.Buffs.AddCustomVar("PathingCode", 0f); } List <Vector3> localLists = new List <Vector3>(); Vector3i TargetBlockPosition; Vector3i blockPosition = new Vector3i(centerPosition); int num = World.toChunkXZ(blockPosition.x); int num2 = World.toChunkXZ(blockPosition.z); for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkSync(num + j, num2 + i); if (chunk != null) { DictionaryList <Vector3i, TileEntity> tileEntities = chunk.GetTileEntities(); for (int k = 0; k < tileEntities.list.Count; k++) { TileEntity tileEntity = tileEntities.list[k]; TargetBlockPosition = tileEntity.ToWorldPos(); // If it's a sign, check to see if there's a code on it. TileEntitySign tileEntitySign = tileEntity as TileEntitySign; if (tileEntitySign != null) { // If the sign is empty and the code is 0, then accept it as a path String text = tileEntitySign.GetText(); if (String.IsNullOrEmpty(text) && code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); continue; } foreach (String temp in text.Split(',')) { if (code.ToString() == temp || code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); break; } } continue; } BlockValue block = GameManager.Instance.World.GetBlock(TargetBlockPosition); if (block.ischild) { continue; } // if its not a listed block, then keep searching. if (!lstBlocks.Contains(block.Block.GetBlockName())) { continue; } localLists.Add(TargetBlockPosition.ToVector3()); } } } } return(localLists); }
/// <summary> /// Given a subsequent sign after creation, determine if the sign is a valid member of the struct. /// </summary> /// <param name="Sign"> /// The TileEntity of the sign /// </param> /// <returns> /// True if the sign data is valid and this object should continue reading signs from the world /// False if the sign is not valid and this object's setup should be completed. /// </returns> abstract protected internal bool AddSign(TileEntitySign Sign);
/// <summary> /// Given a sign, create an object of this sign type. Return False if the sign does not meet creation requirements /// </summary> /// <param name="BaseEntity"> /// The TileEntity of the base sign /// </param> /// <returns> /// True if the sign can be created, False if it cannot /// </returns> /// <remarks> /// This function should not perform extensive validation, as it is possible for multiple signs to be included via AddSign(). /// </remarks> abstract protected internal bool CreateFrom(TileEntitySign BaseEntity);
public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart, int x1dest, int z1dest, Building bldInsert, int y1dest) { List <Spawner> lstSpawners = new List <Spawner>(); _lstInstanceSigns.Clear(); int intRandomWoolColour = RandomHelper.Next(16); int intSourceX = 0, intSourceZ = 0; int intRotate = -1; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intRotate = 0; } else { for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++) { for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSizeX; intCheck++) { if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1) { intRotate = 0; } else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1) { intRotate = 1; } else if (CheckArea(intArea, x1dest + bldInsert.intSizeX + intDistance, z1dest + intCheck) == 1) { intRotate = 2; } else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSizeZ + intDistance) == 1) { intRotate = 3; } } } } if (intRotate == -1) { intRotate = RandomHelper.Next(4); } for (int x = 0; x < bldInsert.intSizeX; x++) { for (int z = 0; z < bldInsert.intSizeZ; z++) { switch (intRotate) { case 0: intSourceX = x; intSourceZ = z; break; case 1: intSourceX = (bldInsert.intSizeX - 1) - z; intSourceZ = x; break; case 2: intSourceX = z; intSourceZ = (bldInsert.intSizeZ - 1) - x; break; case 3: intSourceX = (bldInsert.intSizeX - 1) - x; intSourceZ = (bldInsert.intSizeZ - 1) - z; break; default: Debug.Fail("Invalid switch result"); break; } int intSourceEndY; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intSourceEndY = bldInsert.intSourceStartY + 4; } else { for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--) { if (_bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY, intSourceZ + bldInsert.intSourceZ) != BlockType.AIR) { break; } } } for (int ySource = bldInsert.intSourceStartY; ySource <= intSourceEndY; ySource++) { int yDest = ySource; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { yDest = y1dest + (ySource - bldInsert.intSourceStartY); } if (bldInsert.btThis == BuildingTypes.MineshaftSection || ((yDest != 64 || bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) == BlockType.AIR) && bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) != BlockType.WOOD_PLANK)) { int intBlockID = _bmSource.GetID(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); int intBlockData = _bmSource.GetData(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockData); #region import paintings // todo: test for mineshaft features foreach (EntityPainting entPainting in _AllEntityPainting) { if (entPainting.TileX == intSourceX + bldInsert.intSourceX && entPainting.TileY == ySource && entPainting.TileZ == intSourceZ + bldInsert.intSourceZ) { EntityPainting entNewPainting = (EntityPainting)entPainting.Copy(); entNewPainting.TileX = intBlockStart + x + x1dest; entNewPainting.TileY = yDest; entNewPainting.TileZ = intBlockStart + z + z1dest; entNewPainting.Position.X = entNewPainting.TileX; entNewPainting.Position.Z = entNewPainting.TileZ; entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction, intRotate); ChunkRef chunkBuilding = _cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16, (intBlockStart + z + z1dest) / 16); chunkBuilding.Entities.Add(entNewPainting); _cmDest.Save(); } } #endregion #region Rotation if (intRotate > 0) { switch (intBlockID) { case BlockType.PORTAL: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePortal(intBlockData, intRotate)); break; case BlockType.SIGN_POST: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateSignPost(intBlockData, intRotate)); break; case BlockType.STONE_BUTTON: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateButton(intBlockData, intRotate)); break; case BlockType.PUMPKIN: case BlockType.JACK_O_LANTERN: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePumpkin(intBlockData, intRotate)); break; case BlockType.IRON_DOOR: case BlockType.WOOD_DOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateDoor(intBlockData, intRotate)); break; case BlockType.TRAPDOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTrapdoor(intBlockData, intRotate)); break; case BlockType.BED: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateBed(intBlockData, intRotate)); break; case BlockType.REDSTONE_TORCH_OFF: case BlockType.REDSTONE_TORCH_ON: case BlockType.TORCH: case BlockType.LEVER: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTorchOrLever(intBlockData, intRotate)); break; case BlockType.WALL_SIGN: case BlockType.LADDER: case BlockType.DISPENSER: case BlockType.FURNACE: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser( intBlockData, intRotate)); break; case BlockType.COBBLESTONE_STAIRS: case BlockType.WOOD_STAIRS: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateStairs(intBlockData, intRotate)); break; // no need for a default - all other blocks are okay } } #endregion #region Handle entities switch (intBlockID) { case BlockType.SPONGE: bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.WOOL); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intRandomWoolColour); break; case BlockType.CHEST: TileEntityChest tec = (TileEntityChest)_bmSource.GetTileEntity( intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); if (_booIncludeItemsInChests) { if (tec.Items[0] != null) { if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 3) { tec = MakeHouseChest(); } if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 4) { tec = MakeTreasureChest(); } } } else { tec.Items.ClearAllItems(); } bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tec); break; case BlockType.FURNACE: case BlockType.MONSTER_SPAWNER: case BlockType.NOTE_BLOCK: bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, _bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ)); break; case BlockType.SIGN_POST: case BlockType.WALL_SIGN: #region Determine sign text int intUniqueType = 0; TileEntitySign tes = (TileEntitySign)_bmSource. GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4; switch (strSourceSign.Substring(0, 1)) { case "2": case "1": case "0": intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1)); strSourceSign = strSourceSign.Remove(0, 1); break; default: intUniqueType = 0; break; } if (tes.Text1.ToLower() == "commentsign" || tes.Text1.ToLower() == "comment sign") { // these exist to give advice to people in the resource world. // so we just remove them from the real world bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } if (tes.Text1.ToLower() == "spawner" || tes.Text1.ToLower() == "gspawner") { if (!tes.Text2.ToLower().StartsWith("g") || tes.Text2.ToLower() == "[randomenemy]" || _booIncludeGhostdancerSpawners) { Spawner spawnerCurrent = new Spawner(); if (tes.Text2.ToLower() == "[randomenemy]") { if (_booIncludeGhostdancerSpawners) { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie", "GGeist", "GGrim"); } else { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie"); } } else { spawnerCurrent.strEntityID = tes.Text2; } if (tes.Text3.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.sy = yDest + Convert.ToInt32(tes.Text3.Split(' ')[1]); spawnerCurrent.sx = 0; spawnerCurrent.sz = 0; switch (intRotate) { case 0: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); break; case 1: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 2: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 3: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); break; } } else { spawnerCurrent.sx = intBlockStart + x + x1dest; spawnerCurrent.sy = yDest - 2; spawnerCurrent.sz = intBlockStart + z + z1dest; } if (tes.Text4.ToLower() == "no") { spawnerCurrent.booGrass = false; } else if (tes.Text4.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.gy = yDest + Convert.ToInt32(tes.Text4.Split(' ')[1]); switch (intRotate) { case 0: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); break; case 1: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 2: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 3: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); break; } spawnerCurrent.booGrass = true; } else { spawnerCurrent.gx = intBlockStart + x + x1dest; spawnerCurrent.gy = yDest - 1; spawnerCurrent.gz = intBlockStart + z + z1dest; spawnerCurrent.booGrass = true; } lstSpawners.Add(spawnerCurrent); } bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } else if (strSourceSign.Contains("[")) { string strSignText; bool booDuplicate; int intFail = 0; do { strSignText = SignText(strSourceSign); booDuplicate = false; switch (intUniqueType) { case 1: // unique by instance booDuplicate = _lstInstanceSigns.Contains(strSignText); break; case 2: // unique by city booDuplicate = _lstCitySigns.Contains(strSignText); break; } if (++intFail > 100) { Debug.WriteLine("Could not make a unique sign for " + strSourceSign); booDuplicate = false; } } while (booDuplicate); _lstCitySigns.Add(strSignText); _lstInstanceSigns.Add(strSignText); string[] strRandomSign = Utils.TextToSign(Utils.ConvertStringToSignText(strSignText)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } else { bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } break; #endregion // no need for a default - all the other blocks are okay } #endregion } } } } foreach (Spawner spnAdd in lstSpawners) { bmDest.SetID(spnAdd.sx, spnAdd.sy, spnAdd.sz, BlockType.MONSTER_SPAWNER); TileEntityMobSpawner tems = new TileEntityMobSpawner(); tems.EntityID = spnAdd.strEntityID; bmDest.SetTileEntity(spnAdd.sx, spnAdd.sy, spnAdd.sz, tems); if (spnAdd.booGrass) { bmDest.SetID(spnAdd.gx, spnAdd.gy, spnAdd.gz, BlockType.GRASS); } } }
/// <summary> /// Callback for item usage. If the item does something special on right clicking, he will have one of those. Return /// True if something happen and false if it don't. This is for ITEMS, not BLOCKS ! /// </summary> public override bool OnItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7) { if (par7 == 0) { return(false); } if (!par3World.GetBlockMaterial(par4, par5, par6).IsSolid()) { return(false); } if (par7 == 1) { par5++; } if (par7 == 2) { par6--; } if (par7 == 3) { par6++; } if (par7 == 4) { par4--; } if (par7 == 5) { par4++; } if (!par2EntityPlayer.CanPlayerEdit(par4, par5, par6)) { return(false); } if (!Block.SignPost.CanPlaceBlockAt(par3World, par4, par5, par6)) { return(false); } if (par7 == 1) { int i = MathHelper2.Floor_double((double)(((par2EntityPlayer.RotationYaw + 180F) * 16F) / 360F) + 0.5D) & 0xf; par3World.SetBlockAndMetadataWithNotify(par4, par5, par6, Block.SignPost.BlockID, i); } else { par3World.SetBlockAndMetadataWithNotify(par4, par5, par6, Block.SignWall.BlockID, par7); } par1ItemStack.StackSize--; TileEntitySign tileentitysign = (TileEntitySign)par3World.GetBlockTileEntity(par4, par5, par6); if (tileentitysign != null) { par2EntityPlayer.DisplayGUIEditSign(tileentitysign); } return(true); }