public void Cut(Player player, int leaveId = 0, int leaveData = 0) { RegionSelector selector = RegionSelector.GetSelector(player); Clipboard clipboard = new Clipboard(player.Level); clipboard.OriginPosition1 = selector.Position1; clipboard.OriginPosition2 = selector.Position2; clipboard.SourceMask = new AnyBlockMask(); clipboard.SourceFuncion = coordinates => { var block = BlockFactory.GetBlockById((byte)leaveId); block.Metadata = (byte)leaveData; block.Coordinates = coordinates; EditSession.SetBlock(block); return(true); }; clipboard.Origin = (BlockCoordinates)player.KnownPosition; clipboard.Fill(selector.GetSelectedBlocks()); selector.Clipboard = clipboard; //Task.Run(() => //{ // SkyLightCalculations.Calculate(player.Level); // player.CleanCache(); // player.ForcedSendChunks(() => // { // player.SendMessage("Calculated skylights and resent chunks."); // }); //}); }
public void GenerateDiamond(int x, int y, int z) { if (StandardWorldProvider.GetRandomNumber(0, 130) == 1) { chunke.SetBlock(x, y, z, BlockFactory.GetBlockById(56)); } }
public void GenerateGold(int x, int y, int z) { if (StandardWorldProvider.GetRandomNumber(0, 80) == 1) { _chunke.SetBlock(x, y, z, BlockFactory.GetBlockById(14)); } }
protected void GenerateLeaves(Level world, int x, int y, int z, float size, float width, byte leafBlockId, byte leafMeta, byte woodId, byte woodMeta) { float dist; int i, j, k, s = (int)(size - 1f), w = (int)((size - 1f) * width); for (i = -w; i <= w; i++) { for (j = -s; j <= s; j++) { for (k = -w; k <= w; k++) { dist = Math.Abs((float)i / width) + (float)Math.Abs(j) + Math.Abs((float)k / width); if (dist <= size - 0.5f || (dist <= size && Rnd.NextDouble() < 0.5)) { if (dist < 0.6f) { Block block = BlockFactory.GetBlockById(woodId); block.Metadata = woodMeta; block.Coordinates = new BlockCoordinates(x + i, y + j, z + k); world.SetBlock(block); } if (world.IsAir(new BlockCoordinates(x + i, y + j, z + k))) { Block block = BlockFactory.GetBlockById(leafBlockId); block.Metadata = leafMeta; block.Coordinates = new BlockCoordinates(x + i, y + j, z + k); world.SetBlock(block); } } } } } }
protected override void OnEnable() { Log.Info($"Enabled Alex test plugin."); Context.LevelManager.LevelCreated += LevelManagerOnLevelCreated; Context.Server.PlayerFactory.PlayerCreated += OnPlayerCreated; Context.PluginManager.LoadCommands(new CommandHandler(this)); Context.LevelManager.Levels.Add(new Level(Context.LevelManager, "w2", new AnvilWorldProvider() { MissingChunkProvider = new SuperflatGenerator(Dimension.Overworld) { BlockLayers = new List <Block>() { BlockFactory.GetBlockById(7), BlockFactory.GetBlockById(3), BlockFactory.GetBlockById(3), BlockFactory.GetBlockById(12) } } }, new EntityManager(), GameMode.Creative, Difficulty.Easy)); // Context.LevelManager.GetLevel(null, "") foreach (var level in Context.LevelManager.Levels) { LinkLevelEvents(level); } LevelManager = Context.LevelManager; }
public override void PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { if (Metadata == 8 || Metadata == 10) //Prevent some kind of cheating... { var itemBlock = new ItemBlock(BlockFactory.GetBlockById((byte)Metadata)); itemBlock.PlaceBlock(world, player, blockCoordinates, face, faceCoords); } else if (Metadata == 0) // Empty bucket { // Pick up water/lava var block = world.GetBlock(blockCoordinates); switch (block) { case Stationary fluid: { if (fluid.LiquidDepth == 0) // Only source blocks { world.SetAir(blockCoordinates); } break; } case Flowing fluid: { if (fluid.LiquidDepth == 0) // Only source blocks { world.SetAir(blockCoordinates); } break; } } } FuelEfficiency = (short)(Metadata == 10 ? 1000 : 0); }
public void Distribution(Player player, bool separateByData = false) { var selector = RegionSelector.GetSelector(player); var selection = selector.GetSelectedBlocks().Select(coord => player.Level.GetBlock(coord)).ToArray(); Dictionary <Tuple <byte, int>, int> dist = new Dictionary <Tuple <byte, int>, int>(); foreach (var block in selection) { Tuple <byte, int> tuple = Tuple.Create(block.Id, separateByData ? block.Metadata : 0); if (dist.ContainsKey(tuple)) { dist[tuple] = dist[tuple] + 1; } else { dist.Add(tuple, 1); } } player.SendMessage($"# total blocks {selection.Length}"); dist = dist.OrderByDescending(kvp => kvp.Value).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); foreach (var kvp in dist) { Block block = BlockFactory.GetBlockById(kvp.Key.Item1); double pct = ((float)kvp.Value) / selection.Length * 100f; player.SendMessage($"{kvp.Value}, ({pct :F3}%), {block.GetType().Name} Id={kvp.Key.Item1}, Metadata={kvp.Key.Item2}"); } }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face); if (Metadata == 8 || Metadata == 10) //Prevent some kind of cheating... { Block block = BlockFactory.GetBlockById((byte)Metadata); block.Coordinates = coordinates; if (!block.CanPlace(world, blockCoordinates, face)) { return; } world.SetBlock(block); block.PlaceBlock(world, player, block.Coordinates, face, faceCoords); } else if (Metadata == 0) // Empty bucket { // Pick up water/lava var block = world.GetBlock(blockCoordinates); if (block is Stationary || block is Flowing) { if (block.Metadata == 0) // Only source blocks { world.SetAir(blockCoordinates); } } } FuelEfficiency = (short)(Metadata == 10 ? 1000 : 0); }
public void GenerateIron(int x, int y, int z) { if (StandardWorldProvider.GetRandomNumber(0, 65) == 1) { chunke.SetBlock(x, y, z, BlockFactory.GetBlockById(15)); } }
public override void OnTick(Entity[] entities) { PositionCheck(); if (KnownPosition.Y > -1 && _checkPosition) { Velocity -= new Vector3(0, (float)Gravity, 0); Velocity *= (float)(1.0f - Drag); } else { McpeUpdateBlockSynced updateBlock = McpeUpdateBlockSynced.CreateObject(); updateBlock.coordinates = new BlockCoordinates(KnownPosition); updateBlock.blockRuntimeId = _original.GetRuntimeId(); updateBlock.blockPriority = 3; updateBlock.dataLayerId = 0; updateBlock.unknown0 = EntityId; updateBlock.unknown1 = 2; Level.RelayBroadcast(updateBlock); DespawnEntity(); var block = BlockFactory.GetBlockById(_original.Id); block.Metadata = _original.Metadata; block.Coordinates = new BlockCoordinates(KnownPosition); Level.SetBlock(block, false); } }
public override void PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { if (face == BlockFace.Down) // At the bottom of block { // Doesn't work, ignore if that happen. return; } if (face == BlockFace.Up) { if (!(BlockFactory.GetBlockById(176) is StandingBanner banner)) { return; } banner.ExtraData = ExtraData; banner.Base = Metadata; Block = banner; } else { if (!(BlockFactory.GetBlockById(176) is WallBanner banner)) { return; } banner.ExtraData = ExtraData; banner.Base = Metadata; Block = banner; } base.PlaceBlock(world, player, blockCoordinates, face, faceCoords); }
protected void GenerateVanillaCircle(Level chunk, Vector3 location, int radius, byte id, byte meta, double corner = 0) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int)Math.Sqrt((I * I) + (j * j)); if (max <= radius) { if (I.Equals(-radius) && j.Equals(-radius) || I.Equals(-radius) && j.Equals(radius) || I.Equals(radius) && j.Equals(-radius) || I.Equals(radius) && j.Equals(radius)) { if (corner + radius * 0.2 < 0.4 || corner + radius * 0.2 > 0.7 || corner.Equals(0)) { continue; } } var x = location.X + I; var z = location.Z + j; if (chunk.IsAir(new BlockCoordinates((int)x, (int)location.Y, (int)z))) { var block = BlockFactory.GetBlockById(id); block.Metadata = meta; block.Coordinates = new BlockCoordinates((int)x, (int)location.Y, (int)z); chunk.SetBlock(block); //chunk.SetBlock((int)x, (int)location.Y, (int)z, id); //chunk.SetMetadata((int)x, (int)location.Y, (int)z, meta); } } } } }
protected void GenerateBranch(Level world, float x, float y, float z, double horDir, float verDir, float length, float speed, byte blockId, byte meta) { if (verDir < 0f) { verDir = -verDir; } float c = 0f; float velY = 1f - verDir; if (verDir > 1f) { verDir = 1f - (verDir - 1f); } float velX = (float)Math.Cos(horDir * Math.PI / 180D) * verDir; float velZ = (float)Math.Sin(horDir * Math.PI / 180D) * verDir; while (c < length) { Block block = BlockFactory.GetBlockById(blockId); block.Metadata = meta; block.Coordinates = new BlockCoordinates((int)x, (int)y, (int)z); world.SetBlock(block); x += velX; y += velY; z += velZ; c += speed; } }
protected void GenerateCircle(Level chunk, Vector3 location, int radius, byte id, byte meta) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int)Math.Sqrt((I * I) + (j * j)); if (max <= radius) { var X = location.X + I; var Z = location.Z + j; if (X < 0 || X >= 16 || Z < 0 || Z >= 256) { continue; } var x = (int)X; var y = (int)location.Y; var z = (int)Z; if (chunk.IsAir(new BlockCoordinates(x, y, z))) { Block block = BlockFactory.GetBlockById(id); block.Metadata = meta; block.Coordinates = new BlockCoordinates(x, y, z); chunk.SetBlock(block); } } } } }
public Block GetBlock(BlockCoordinates blockCoordinates) { ChunkColumn chunk = _worldProvider.GenerateChunkColumn(new ChunkCoordinates(blockCoordinates.X >> 4, blockCoordinates.Z >> 4)); if (chunk == null) { return new Air() { Coordinates = blockCoordinates, SkyLight = 15 } } ; byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte metadata = chunk.GetMetadata(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte blockLight = chunk.GetBlocklight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte skyLight = chunk.GetSkylight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); Block block = BlockFactory.GetBlockById(bid); block.Coordinates = blockCoordinates; block.Metadata = metadata; block.BlockLight = blockLight; block.SkyLight = skyLight; return(block); }
public void SetAir(int x, int y, int z, bool broadcast = true) { Block air = BlockFactory.GetBlockById(0); air.Metadata = 0; air.Coordinates = new BlockCoordinates(x, y, z); SetBlock(air, broadcast, applyPhysics: true); }
private void SetDoubleSlab(Level world, BlockCoordinates coordinates) { Block slab = BlockFactory.GetBlockById((byte)(Id - 1)); slab.Coordinates = coordinates; slab.Metadata = (byte)Metadata; world.SetBlock(slab); }
private void PopulateChunk(ChunkColumn chunk) { var bottom = new SimplexOctaveGenerator(Globals.Seed.GetHashCode(), 8); var top = new SimplexOctaveGenerator(Globals.Seed.GetHashCode(), 8); bottom.SetScale(1 / Groundscale); top.SetScale(1 / Topscale); for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { float ox = x + chunk.X * 16; float oz = z + chunk.Z * 16; var bottomHeight = (int)((bottom.Noise(ox, oz, BottomsFrequency, BottomsAmplitude) * BottomsMagnitude) + BottomOffset); var topHeight = (int)((top.Noise(ox, oz, TopFrequency, TopAmplitude) * TopMagnitude) + TopOffset); for (var y = 0; y < 256; y++) { if (y == 0 || y == 255) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7)); continue; } if (y < bottomHeight) { chunk.SetBlock(x, y, z, new BlockNetherrack()); } if (y < topHeight) { chunk.SetBlock(x, 256 - y, z, new BlockNetherrack()); if (GetRandomNumber(1, 50) == 25) { chunk.SetBlock(x, 256 - (y + 1), z, new Block(89)); } } } //Turn the blocks ontop into the correct material for (var y = bottomHeight; y < 254; y++) { if (chunk.GetBlock(x, y + 1, z) == 0 && chunk.GetBlock(x, y, z) == 1) { chunk.SetBlock(x, y, z, new BlockNetherrack()); chunk.SetBlock(x, y - 1, z, new BlockNetherrack()); chunk.SetBlock(x, y - 2, z, new BlockNetherrack()); } } } } new NetherLavaDecorator().Decorate(chunk, new PlainsBiome()); }
private void UpdateHandItems() { var s = GetSlot(CurrentSlot + 36); Hand1 = s.ItemId > 255 ? ItemFactory.GetItemById(s.ItemId, s.MetaData) : BlockFactory.GetBlockById((ushort)s.ItemId, s.MetaData); s = GetSlot(45); Hand2 = s.ItemId > 255 ? ItemFactory.GetItemById(s.ItemId, s.MetaData) : BlockFactory.GetBlockById((ushort)s.ItemId, s.MetaData); }
public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { //var blockbiome = chunk.BiomeId[x*16 + z]; //if (BiomeManager.GetBiomeById(blockbiome).Temperature < 2.0f) //If the temperature is below 2.0F create lakes. //{ //Check for temperature. for (var y = 0; y < StandardWorldProvider.WaterLevel; y++) { //Lake generation if (y < StandardWorldProvider.WaterLevel) { if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3) //Grass or Dirt? { if (StandardWorldProvider.GetRandomNumber(1, 40) == 1 && y < StandardWorldProvider.WaterLevel - 4) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(82)); //Clay } else { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(12)); //Sand chunk.BiomeId[x * 16 + z] = 16; //Beach } } if (chunk.GetBlock(x, y + 1, z) == 0) { if (y < StandardWorldProvider.WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, BlockFactory.GetBlockById(8)); //Water chunk.BiomeId[x * 16 + z] = 0; //Ocean } } } } //} /*else //Fill up with sand * { * for (var y = 0; y < ExperimentalV2Generator.WaterLevel; y++) * { * if (y < ExperimentalV2Generator.WaterLevel) * { * if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3 || chunk.GetBlock(x,y,z) == 0) //Grass or Dirt? * { * chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(12)); //Sand * //chunk.BiomeId[x * 16 + z] = 16; //Beach * } * } * } * }*/ } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { for (var y = 1; y < 6; y++) { if (StandardWorldProvider.GetRandomNumber(0, 5) == 1) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7)); } } }
public static void GenerateColumn(Level chunk, Vector3 location, int height, byte id, byte meta) { for (var o = 0; o < height; o++) { var block = BlockFactory.GetBlockById(id); block.Metadata = meta; block.Coordinates = new BlockCoordinates((int)location.X, (int)location.Y + o, (int)location.Z); chunk.SetBlock(block); } }
public Block Next(BlockCoordinates position) { var blockEntry = GetRandomBlock(_random, _blockList); Block block = BlockFactory.GetBlockById(blockEntry.Id); block.Metadata = blockEntry.Metadata; block.Coordinates = position; return(block); }
public Block GetBlock(BlockCoordinates blockCoordinates) { ChunkColumn chunk = _worldProvider.GenerateChunkColumn(new ChunkCoordinates(blockCoordinates.X >> 4, blockCoordinates.Z >> 4)); byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0x7f, blockCoordinates.Z & 0x0f); byte metadata = chunk.GetMetadata(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0x7f, blockCoordinates.Z & 0x0f); Block block = BlockFactory.GetBlockById(bid); block.Coordinates = blockCoordinates; block.Metadata = metadata; return(block); }
public virtual void Create(Level level, int x, int y, int z) { if (level.IsAir(new BlockCoordinates(x, y + MaxHeight, z))) { foreach (Block b in Blocks) { Block clone = BlockFactory.GetBlockById(b.Id); clone.Metadata = b.Metadata; clone.Coordinates = new BlockCoordinates(x + b.Coordinates.X, y + b.Coordinates.Y, z + b.Coordinates.Z); level.SetBlock(clone); } } }
public void GetItemFromBlockStateTest() { // Picked block minecraft:cobblestone_wall from blockstate 3313 int runtimeId = 3313; BlockStateContainer blocStateFromPick = BlockFactory.BlockPalette[runtimeId]; var block = BlockFactory.GetBlockById(blocStateFromPick.Id) as CobblestoneWall; Assert.IsNotNull(block); block.SetState(blocStateFromPick.States); Item item = block.GetItem(); Assert.AreEqual("minecraft:cobblestone_wall", item.Name); Assert.AreEqual(139, item.Id); Assert.AreEqual(12, item.Metadata); }
public static Block ConvertBlock(int blockId, byte metadata = 0) { if (ConvertMap.ContainsKey(blockId)) { Func <int, byte, byte> dataConverter = ConvertMap[blockId].Item2; blockId = ConvertMap[blockId].Item1; metadata = dataConverter(blockId, metadata); } Block block = BlockFactory.GetBlockById((byte)blockId); block.Metadata = metadata; return(block); }
public void GetItemFromBlockStateTest() { // Picked block minecraft:chain from blockstate 917 int runtimeId = 917; BlockStateContainer blocStateFromPick = BlockFactory.BlockPalette[runtimeId]; var block = BlockFactory.GetBlockById(blocStateFromPick.Id) as Chain; Assert.IsNotNull(block); block.SetState(blocStateFromPick.States); Item item = block.GetItem(); Assert.AreEqual("minecraft:chain", item.Name); Assert.AreEqual(758, item.Id); Assert.AreEqual(0, item.Metadata); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { // 8 = 1000 byte upperBit = 0x08; // 7 = 0111 byte materialMask = 0x07; Block existingBlock = world.GetBlock(blockCoordinates); var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face); Block newBlock = world.GetBlock(coordinates); if (face == BlockFace.Up && faceCoords.Y == 0.5 && existingBlock.Id == Id && (existingBlock.Metadata & materialMask) == Metadata) { // Replace with double block SetDoubleSlab(world, blockCoordinates); return; } if (face == BlockFace.Down && faceCoords.Y == 0.5 && (existingBlock.Metadata & materialMask) == Metadata) { // Replace with double block SetDoubleSlab(world, blockCoordinates); return; } if (newBlock.Id != Id || (newBlock.Metadata & materialMask) != Metadata) { Block slab = BlockFactory.GetBlockById((byte)(Id)); slab.Coordinates = coordinates; slab.Metadata = (byte)Metadata; if (face != BlockFace.Up && faceCoords.Y > 0.5 || (face == BlockFace.Down && faceCoords.Y == 0.0)) { slab.Metadata |= upperBit; } world.SetBlock(slab); return; } // Same material in existing block, make double slab { // Create double slab, replace existing SetDoubleSlab(world, coordinates); } }
public Block GetBlockObject(int bx, int @by, int bz) { if (_runtimeIds.Count == 0) { return(new Air()); } int index = _blocks[GetIndex(bx, by, bz)]; int runtimeId = _runtimeIds[index]; var blockState = BlockFactory.BlockPalette[runtimeId]; var block = BlockFactory.GetBlockById(blockState.Id); block.SetState(blockState.States); block.Metadata = (byte)blockState.Data; //TODO: REMOVE metadata. Not needed. return(block); }