public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Log.Warn("Player " + player.Username + " should be banned for hacking!"); var block = world.GetBlock(blockCoordinates); if (block is Tnt) { world.SetBlock(new Air() {Coordinates = block.Coordinates}); new PrimedTnt(world) { KnownPosition = new PlayerLocation(blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z), Fuse = (byte) (new Random().Next(0, 20) + 10) }.SpawnEntity(); } else if (block.IsSolid) { var affectedBlock = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Up)); if (affectedBlock.Id == 0) { var fire = new Fire { Coordinates = affectedBlock.Coordinates }; world.SetBlock(fire); } } }
public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face) { Metadata = (byte) (Metadata | (0x8)); world.SetBlock(this); world.ScheduleBlockTick(this, TickRate); return true; }
public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords) { //if (player.GameMode != GameMode.Creative) //{ // Item itemStackInHand = player.Inventory.GetItemInHand(); // itemStackInHand.Count--; // if (itemStackInHand.Count <= 0) // { // // set empty // player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemAir(); // } //} _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face); _block.Metadata = (byte) Metadata; if ((player.GetBoundingBox() - 0.01f).Intersects(_block.GetBoundingBox())) { Log.Debug("Can't build where you are standing: " + _block.GetBoundingBox()); return; } if (!_block.CanPlace(world, face)) return; if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled world.SetBlock(_block); }
private void SetDoubleSlab(Level world, BlockCoordinates coordinates) { Block slab = BlockFactory.GetBlockById((byte) (Id - 1)); slab.Coordinates = coordinates; slab.Metadata = (byte) Metadata; world.SetBlock(slab); }
public override void BreakBlock(Level level) { BlockCoordinates direction = new BlockCoordinates(); switch (Metadata & 0x07) { case 0: direction = Level.East; break; // West case 1: direction = Level.North; break; // North case 2: direction = Level.West; break; // East case 3: direction = Level.South; break; // South } // Remove bed if ((Metadata & 0x08) != 0x08) { direction = direction*-1; } level.SetBlock(new Air {Coordinates = Coordinates + direction}); level.SetBlock(new Air {Coordinates = Coordinates}); }
public override void Release(Level world, Player player, BlockCoordinates blockCoordinates, long timeUsed) { float force = CalculateForce(timeUsed); if (force <= 0) return; Arrow arrow = new Arrow(player, world); arrow.KnownPosition = (PlayerLocation) player.KnownPosition.Clone(); arrow.KnownPosition.Y += 1.62f; float yaw = arrow.KnownPosition.Yaw; float pitch = arrow.KnownPosition.Pitch; var vx = -Math.Sin(yaw/180f*Math.PI)*Math.Cos(pitch/180f*Math.PI); var vy = -Math.Sin(pitch/180f*Math.PI); var vz = Math.Cos(yaw/180f*Math.PI)*Math.Cos(pitch/180f*Math.PI); arrow.Velocity = new Vector3(vx, vy, vz)*(force*2.0f*1.5f); var k = Math.Sqrt((arrow.Velocity.X*arrow.Velocity.X) + (arrow.Velocity.Z*arrow.Velocity.Z)); arrow.KnownPosition.Yaw = (float) (Math.Atan2(arrow.Velocity.X, arrow.Velocity.Z)*180f/Math.PI); arrow.KnownPosition.Pitch = (float) (Math.Atan2(arrow.Velocity.Y, k)*180f/Math.PI); //Arrow arrow2 = new Arrow(player, world) //{ // KnownPosition = (PlayerLocation)arrow.KnownPosition.Clone(), // Velocity = arrow.Velocity, // BroadcastMovement = true //}; ////arrow2.HealthManager.Ignite(); //arrow2.SpawnEntity(); arrow.BroadcastMovement = false; arrow.DespawnOnImpact = true; arrow.SpawnEntity(); }
public override void Release(Level world, Player player, BlockCoordinates blockCoordinates, long timeUsed) { float force = CalculateForce(timeUsed); if (force <= 0) return; Arrow arrow = new Arrow(player, world); arrow.KnownPosition = (PlayerLocation) player.KnownPosition.Clone(); arrow.KnownPosition.Y += 1.62f; arrow.Velocity = arrow.KnownPosition.GetDirection()*(force*2.0f*1.5f); arrow.KnownPosition.Yaw = (float) arrow.Velocity.GetYaw(); arrow.KnownPosition.Pitch = (float) arrow.Velocity.GetPitch(); //Arrow arrow2 = new Arrow(player, world) //{ // KnownPosition = (PlayerLocation)arrow.KnownPosition.Clone(), // Velocity = arrow.Velocity, // BroadcastMovement = true //}; ////arrow2.HealthManager.Ignite(); //arrow2.SpawnEntity(); arrow.BroadcastMovement = false; arrow.DespawnOnImpact = true; arrow.SpawnEntity(); }
public override bool Interact(Level currentLevel, Player player, BlockCoordinates blockCoordinates, BlockFace face) { Sign signEntity = currentLevel.GetBlockEntity(blockCoordinates) as Sign; if (signEntity == null) return false; string world = signEntity.Text1; if (player.Level.LevelId.Equals(world)) return true; if (!Worlds.ContainsKey(player.Level.LevelId)) { Worlds.Add(player.Level.LevelId, player.Level); } if (!Worlds.ContainsKey(world)) { var mobHuntLevel = new MobHuntLevel(world, new FlatlandWorldProvider()); mobHuntLevel.Initialize(); Worlds.Add(world, mobHuntLevel); } Level level = Worlds[world]; player.SpawnLevel(level); level.BroadcastTextMessage(string.Format("{0} teleported to world <{1}>.", player.Username, level.LevelId)); return true; }
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Metadata = (byte) face; world.SetBlock(this); return true; }
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { byte direction = player.GetDirection(); switch (face) { case BlockFace.South: // ok Metadata = 0; break; case BlockFace.North: Metadata = 1; break; case BlockFace.West: Metadata = 2; break; case BlockFace.East: // ok Metadata = 3; break; } Log.Warn($"Direction={direction}, face={face}, metadata={Metadata}"); world.SetBlock(this); return true; }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { var coor = GetNewCoordinatesFromFace(blockCoordinates, face); if (face == BlockFace.Up) // On top of block { Block skull = new Block(144); skull.Coordinates = coor; skull.Metadata = 1; // Skull on floor, rotation in block entity world.SetBlock(skull); } else if (face == BlockFace.Down) // At the bottom of block { // Doesn't work, ignore if that happen. return; } else { Block skull = new Block(144); skull.Coordinates = coor; skull.Metadata = (byte) face; // Skull on floor, rotation in block entity world.SetBlock(skull); } // Then we create and set the sign block entity that has all the intersting data var skullBlockEntity = new SkullBlockEntity { Coordinates = coor, Rotation = (byte)((int)(Math.Floor(((player.KnownPosition.Yaw)) * 16 / 360) + 0.5) & 0x0f), SkullType = (byte) Metadata }; world.SetBlockEntity(skullBlockEntity); }
// 000 001 010 011 100 public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { byte direction = player.GetDirection(); byte upper = (byte) ((faceCoords.Y > 0.5 && face != BlockFace.Up) || face == BlockFace.Down ? 0x04 : 0x00); switch (direction) { case 0: Metadata = (byte) (0 | upper); break; case 1: Metadata = (byte) (2 | upper); break; case 2: Metadata = (byte) (1 | upper); break; case 3: Metadata = (byte) (3 | upper); break; } world.SetBlock(this); return true; }
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { if (face == BlockFace.Down) return true; switch (face) { case BlockFace.Up: Metadata = 5; break; case BlockFace.East: Metadata = 4; break; case BlockFace.West: Metadata = 3; break; case BlockFace.North: Metadata = 2; break; case BlockFace.South: Metadata = 1; break; } world.SetBlock(this); return true; }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { var coor = GetNewCoordinatesFromFace(blockCoordinates, face); if (face == BlockFace.Up) // On top of block { // Standing Sign var sign = new StandingSign(); sign.Coordinates = coor; // metadata for sign is a value 0-15 that signify the orientation of the sign. Same as PC metadata. sign.Metadata = (byte) ((int) (Math.Floor((player.KnownPosition.Yaw + 180)*16/360) + 0.5) & 0x0f); world.SetBlock(sign); } else if (face == BlockFace.North) // At the bottom of block { // Doesn't work, ignore if that happen. return; } else { // Wall sign var sign = new WallSign(); sign.Coordinates = coor; sign.Metadata = (byte) face; world.SetBlock(sign); } // Then we create and set the sign block entity that has all the intersting data var signBlockEntity = new Sign { Coordinates = coor }; world.SetBlockEntity(signBlockEntity); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { if (player.GameMode != GameMode.Creative) { ItemStack itemStackInHand = player.Inventory.GetItemInHand(); itemStackInHand.Count--; if (itemStackInHand.Count <= 0) { // set empty player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemStack(); } } var coor = GetNewCoordinatesFromFace(blockCoordinates, face); EnchantingTable table = new EnchantingTable { Coordinates = coor, Metadata = (byte) Metadata }; if (!table.CanPlace(world, face)) return; table.PlaceBlock(world, player, coor, face, faceCoords); // Then we create and set the sign block entity that has all the intersting data EnchantingTableBlockEntity tableBlockEntity = new EnchantingTableBlockEntity { Coordinates = coor }; world.SetBlockEntity(tableBlockEntity); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { if (player.GameMode != GameMode.Creative) { Item itemStackInHand = player.Inventory.GetItemInHand(); itemStackInHand.Count--; if (itemStackInHand.Count <= 0) { // set empty player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemAir(); } } var coor = GetNewCoordinatesFromFace(blockCoordinates, face); Chest chest = new Chest { Coordinates = coor, }; if (!chest.CanPlace(world, face)) return; chest.PlaceBlock(world, player, coor, face, faceCoords); // Then we create and set the sign block entity that has all the intersting data ChestBlockEntity chestBlockEntity = new ChestBlockEntity { Coordinates = coor }; world.SetBlockEntity(chestBlockEntity); }
/// <summary> /// Use this for Explosion an explosion only! /// </summary> /// <param name="world"></param> /// <param name="centerCoordinates"></param> /// <param name="size"></param> /// <param name="fire"></param> public Explosion(Level world, BlockCoordinates centerCoordinates, float size, bool fire = false) { _size = size; _centerCoordinates = centerCoordinates; _world = world; CoordsSet = true; Fire = fire; }
public SpawnCoordinates(int teamId, BlockCoordinates v) : this() { TeamId = teamId; X = v.X; Y = v.Y; Z = v.Z; }
public override void FromStream(BinaryReader stream) { Value = new BlockCoordinates { X = stream.ReadInt32(), Y = stream.ReadInt32(), Z = stream.ReadInt32(), }; }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates) { MapEntity mapEntity = new MapEntity(world); mapEntity.SpawnEntity(); // Initialize a new map and add it. ItemMap itemMap = new ItemMap(mapEntity.EntityId); player.Inventory.SetFirstEmptySlot(itemMap, true, false); }
public Inventory GetInventory(BlockCoordinates inventoryCoord) { lock (_cache) { if (_cache.ContainsKey(inventoryCoord)) { Inventory cachedInventory = _cache[inventoryCoord]; if (cachedInventory != null) return cachedInventory; } BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord); if (blockEntity == null) return null; NbtCompound comp = blockEntity.GetCompound(); Inventory inventory; if (blockEntity is ChestBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList) comp["Items"]) { Type = 0, WindowsId = 10, }; } else if (blockEntity is EnchantingTableBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"]) { Type = 4, WindowsId = 12, }; } else if (blockEntity is FurnaceBlockEntity) { inventory = new Inventory(GetInventoryId(), blockEntity, 3, (NbtList) comp["Items"]) { Type = 2, WindowsId = 11, }; FurnaceBlockEntity furnace = (FurnaceBlockEntity) blockEntity; furnace.Inventory = inventory; } else { return null; } _cache[inventoryCoord] = inventory; return inventory; } }
public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords) { _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face); _block.Metadata = (byte) Metadata; if (!_block.CanPlace(world)) return; if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled world.SetBlock(_block); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face); Mob entity = new Mob(Metadata, world) { KnownPosition = new PlayerLocation(coordinates.X, coordinates.Y, coordinates.Z), //Data = -(blockId | 0 << 0x10) }; entity.SpawnEntity(); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates) { float force = 1.5f; Snowball snowBall = new Snowball(player, world) { KnownPosition = (PlayerLocation) player.KnownPosition.Clone(), Velocity = new Vector3(blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z).Normalize()*force }; snowBall.KnownPosition.Y += 1.62f; snowBall.SpawnEntity(); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Block block = world.GetBlock(blockCoordinates); if (block is Grass) { GrassPath grassPath = new GrassPath { Coordinates = blockCoordinates, }; world.SetBlock(grassPath); } }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates) { float force = 1.5f; Snowball snowBall = new Snowball(null, world); snowBall.KnownPosition = (PlayerLocation) player.KnownPosition.Clone(); snowBall.KnownPosition.Y += 1.62f; snowBall.Velocity = snowBall.KnownPosition.GetDirection() * (force); snowBall.BroadcastMovement = false; snowBall.DespawnOnImpact = true; snowBall.SpawnEntity(); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates) { float force = 1.5f; Egg egg = new Egg(player, world); egg.KnownPosition = (PlayerLocation) player.KnownPosition.Clone(); egg.KnownPosition.Y += 1.62f; egg.Velocity = egg.KnownPosition.GetDirection()*(force); egg.BroadcastMovement = false; egg.DespawnOnImpact = true; egg.SpawnEntity(); }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face); Mob entity = new Mob(Metadata, world) { KnownPosition = new PlayerLocation(coordinates.X, coordinates.Y, coordinates.Z), //Data = -(blockId | 0 << 0x10) }; entity.SpawnEntity(); world.BroadcastTextMessage(string.Format("Player {0} spawned Mob #{1}.", player.Username, Metadata)); }
public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Item itemInHande = player.Inventory.GetItemInHand(); ItemFrameBlockEntity blockEntity = world.GetBlockEntity(blockCoordinates) as ItemFrameBlockEntity; if (blockEntity != null) { blockEntity.SetItem(itemInHande); world.SetBlockEntity(blockEntity); } return true; }
public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Block block = world.GetBlock(blockCoordinates); if (block is Grass || block is Dirt || block is GrassPath) { Farmland farmland = new Farmland { Coordinates = blockCoordinates, Metadata = 0 }; world.SetBlock(farmland); } }
public override void BlockPlaced(BlockCoordinates position, API.Blocks.BlockFace face, int hand, int slot, Vector3 cursorPosition, Entity p) { }
public override void UseItem(Item item, int hand, ItemUseAction useAction, BlockCoordinates position, API.Blocks.BlockFace face, Vector3 cursorPosition) { }
public bool CanPlace(Level world, BlockCoordinates targetCoordinates, BlockFace face) { return(CanPlace(world, Coordinates, targetCoordinates, face)); }
protected virtual bool CanPlace(Level world, BlockCoordinates blockCoordinates, BlockCoordinates targetCoordinates, BlockFace face) { return(world.GetBlock(blockCoordinates).IsReplacible); }
public virtual bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords) { // No default placement. Return unhandled. return(false); }
public virtual bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord) { // No default interaction. Return unhandled. return(false); }
public virtual void BlockUpdate(Level level, BlockCoordinates blockCoordinates) { }
private void CalculateModel(IBlockAccess world, BlockCoordinates blockCoordinates, ChunkData chunkBuilder, Vector3 position, Block baseBlock, BlockStateModel blockStateModel, ResourcePackModelBase model, Biome biome) { var positionOffset = baseBlock.GetOffset(NoiseGenerator, position); //bsModel.Y = Math.Abs(180 - bsModel.Y); //if (Resources.BlockModelRegistry.TryGet(blockStateModel.ModelName, out var registryEntry)) { //var model = registryEntry.Value; var baseColor = baseBlock.BlockMaterial.TintColor; for (var index = 0; index < model.Elements.Length; index++) { var element = model.Elements[index]; element.To *= Scale; element.From *= Scale; var faces = element.Faces.ToArray(); foreach (var face in faces) { var facing = face.Key; var cullFace = face.Value.CullFace ?? face.Key; if (blockStateModel.X > 0f) { var offset = blockStateModel.X / 90; cullFace = RotateDirection(cullFace, offset, FACE_ROTATION_X, INVALID_FACE_ROTATION_X); facing = RotateDirection(facing, offset, FACE_ROTATION_X, INVALID_FACE_ROTATION_X); } if (blockStateModel.Y > 0f) { var offset = blockStateModel.Y / 90; cullFace = RotateDirection(cullFace, offset, FACE_ROTATION, INVALID_FACE_ROTATION); facing = RotateDirection(facing, offset, FACE_ROTATION, INVALID_FACE_ROTATION); } float minX = float.MaxValue, minY = float.MaxValue, minZ = float.MaxValue; float maxX = float.MinValue, maxY = float.MinValue, maxZ = float.MinValue; if (!ShouldRenderFace(world, facing, position, baseBlock)) { continue; } var uv = face.Value.UV; float x1 = 0, x2 = 0, y1 = 0, y2 = 0; if (uv == null) { switch (face.Key) { case BlockFace.North: case BlockFace.South: x1 = element.From.X; x2 = element.To.X; y1 = 16f - element.To.Y; y2 = 16f - element.From.Y; break; case BlockFace.West: case BlockFace.East: x1 = element.From.Z; x2 = element.To.Z; y1 = 16f - element.To.Y; y2 = 16f - element.From.Y; break; case BlockFace.Down: case BlockFace.Up: x1 = element.From.X; x2 = element.To.X; y1 = 16f - element.To.Z; y2 = 16f - element.From.Z; break; } } else { x1 = uv.X1; x2 = uv.X2; y1 = uv.Y1; y2 = uv.Y2; } var faceColor = baseColor; bool hasTint = (face.Value.TintIndex.HasValue && face.Value.TintIndex == 0); if (hasTint) { switch (baseBlock.BlockMaterial.TintType) { case TintType.Default: faceColor = Color.White; break; case TintType.Color: faceColor = baseBlock.BlockMaterial.TintColor; break; case TintType.Grass: if (SmoothLighting) { var bx = (int)position.X; var y = (int)position.Y; var bz = (int)position.Z; faceColor = CombineColors( GetGrassBiomeColor(world, bx, y, bz), GetGrassBiomeColor(world, bx - 1, y, bz), GetGrassBiomeColor(world, bx, y, bz - 1), GetGrassBiomeColor(world, bx + 1, y, bz), GetGrassBiomeColor(world, bx, y, bz + 1), GetGrassBiomeColor(world, bx + 1, y, bz - 1)); } else { faceColor = Resources.GetGrassColor( biome.Temperature, biome.Downfall, (int)position.Y); } break; case TintType.Foliage: if (face.Value.TintIndex.HasValue && face.Value.TintIndex == 0) { faceColor = Resources.GetFoliageColor( biome.Temperature, biome.Downfall, (int)position.Y); } break; default: throw new ArgumentOutOfRangeException(); } } faceColor = AdjustColor(faceColor, facing, element.Shade); BlockTextureData uvMap = GetTextureUVMap( Resources, face.Value.Texture, x1, x2, y1, y2, face.Value.Rotation, faceColor); var vertices = GetFaceVertices(face.Key, element.From, element.To, uvMap); vertices = ProcessVertices(vertices, blockStateModel, element, uvMap, facing, face.Value); RenderStage targetState = RenderStage.OpaqueFullCube; if (baseBlock.BlockMaterial.IsLiquid) { targetState = RenderStage.Liquid; } else if (uvMap.IsAnimated) { targetState = RenderStage.Animated; } else if (baseBlock.Transparent) { if (baseBlock.BlockMaterial.IsOpaque) { if (!Block.FancyGraphics && baseBlock.IsFullCube) { targetState = RenderStage.OpaqueFullCube; } else { targetState = RenderStage.Transparent; } } else { targetState = RenderStage.Translucent; } } else if (!baseBlock.IsFullCube) { targetState = RenderStage.Opaque; } for (int i = 0; i < vertices.Length; i++) { var vertex = vertices[i]; BlockModel.GetLight( world, vertex.Position + position + vertex.Face.GetVector3(), out var blockLight, out var skyLight, true); chunkBuilder.AddVertex( blockCoordinates, vertex.Position + position + positionOffset, vertex.TexCoords, vertex.Color, blockLight, skyLight, targetState); } } } } }
public override void GetVertices(IBlockAccess world, ChunkData chunkBuilder, BlockCoordinates blockCoordinates, Vector3 position, BlockState baseBlock) { var biome = world == null?BiomeUtils.GetBiomeById(0) : world.GetBiome(position); if (baseBlock.ModelData == null) { return; } if (baseBlock.VariantMapper.IsMultiPart) { foreach (var model in baseBlock.ModelData) { if (Resources.BlockModelRegistry.TryGet(model.ModelName, out var registryEntry)) { CalculateModel( world, blockCoordinates, chunkBuilder, position, baseBlock.Block, model, registryEntry.Value, biome); } } return; } // if (UseRandomizer) { BlockStateModel selectedModel = null; if (baseBlock.ModelData.Count > 1) { var weightSum = baseBlock.ModelData.Sum(x => x.Weight); var rnd = ((baseBlock.ModelData.Count == 1) ? 1f : MathF.Abs( NoiseGenerator.GetValue(position.X * position.Y, position.Z * position.X))) * weightSum; //for (var index = 0; index < Models.Length; index++) foreach (var model in baseBlock.ModelData) { // var model = Models[index]; rnd -= model.Weight; if (rnd < 0) { selectedModel = model; break; } } } else { selectedModel = baseBlock.ModelData.FirstOrDefault(); } if (selectedModel == null) { return; } if (Resources.BlockModelRegistry.TryGet(selectedModel.ModelName, out var registryEntry)) { CalculateModel( world, blockCoordinates, chunkBuilder, position, baseBlock.Block, selectedModel, registryEntry.Value, biome); } // CalculateModel(world, blockCoordinates, chunkBuilder, position, baseBlock, selectedModel.BlockStateModel, selectedModel.BlockModel, biome); } //else //{ //for (var bsModelIndex = 0; bsModelIndex < Models.Length; bsModelIndex++) //{ //var bsModel = Models[bsModelIndex]; // if (string.IsNullOrWhiteSpace(bsModel.ModelName)) continue; //} //} }
//[Authorize(Permission = UserPermission.Op)] public void Video2X(Player player, int numberOfFrames, bool color) { Task.Run(delegate { try { Dictionary <Tuple <int, int>, List <MapEntity> > entities = new Dictionary <Tuple <int, int>, List <MapEntity> >(); int width = 6; int height = 3; int frameCount = numberOfFrames; //int frameOffset = 0; int frameOffset = 120; var frameTicker = new FrameTicker(frameCount); // 768x384 for (int frame = frameOffset; frame < frameCount + frameOffset; frame++) { Log.Info($"Generating frame {frame}"); string file = Path.Combine(@"D:\Development\Other\Smash Heroes 3x6 (128)\Smash Heroes 3x6 (128)", $"Smash Heroes Trailer{frame:D4}.bmp"); //string file = Path.Combine(@"D:\Development\Other\2 by 1 PE test app ad for Gurun-2\exported frames 2", $"pe app ad{frame:D2}.bmp"); if (!File.Exists(file)) { continue; } Bitmap image = new Bitmap((Bitmap)Image.FromFile(file), width * 128, height * 128); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var key = new Tuple <int, int>(x, y); if (!entities.ContainsKey(key)) { entities.Add(key, new List <MapEntity>()); } List <MapEntity> frames = entities[key]; var croppedImage = CropImage(image, new Rectangle(new Point(x * 128, y * 128), new Size(128, 128))); byte[] bitmapToBytes = BitmapToBytes(croppedImage, color); if (bitmapToBytes.Length != 128 * 128 * 4) { return; } MapEntity entity = new MapEntity(player.Level); entity.ImageProvider = new MapImageProvider { Batch = CreateCachedPacket(entity.EntityId, bitmapToBytes) }; entity.SpawnEntity(); frames.Add(entity); } } } int i = 0; player.Inventory.Slots[i++] = new ItemBlock(new Planks(), 0) { Count = 64 }; foreach (var entites in entities.Values) { player.Inventory.Slots[i++] = new CustomItemItemFrame(entites, frameTicker) { Count = 64 }; } player.SendPlayerInventory(); player.SendMessage("Done generating video.", MessageType.Raw); BlockCoordinates center = player.KnownPosition.GetCoordinates3D(); var level = player.Level; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var key = new Tuple <int, int>(x, y); List <MapEntity> frames = entities[key]; BlockCoordinates bc = new BlockCoordinates(center.X - x, center.Y + height - y - 1, center.Z + 2); var wood = new Planks { Coordinates = bc }; level.SetBlock(wood); BlockCoordinates frambc = new BlockCoordinates(center.X - x, center.Y + height - y - 1, center.Z + 1); ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity { Coordinates = frambc }; var itemFrame = new CustomItemFrame(frames, itemFrameBlockEntity, level, frameTicker) { Coordinates = frambc, Metadata = 3 }; level.SetBlock(itemFrame); level.SetBlockEntity(itemFrameBlockEntity); } } } catch (Exception e) { Log.Error("Aborted video generation", e); } }); player.SendMessage("Generating video...", MessageType.Raw); }
public virtual void Release(Level world, Player player, BlockCoordinates blockCoordinates, long timeUsed) { }
public virtual void UseItem(Level world, Player player, BlockCoordinates blockCoordinates) { }
public override void WorldInteraction(Entity player, BlockCoordinates position, API.Blocks.BlockFace face, int hand, int slot, Vector3 cursorPosition) { }
protected override bool CanPlace(Level world, Player player, BlockCoordinates blockCoordinates, BlockCoordinates targetCoordinates, BlockFace face) { if (base.CanPlace(world, player, blockCoordinates, targetCoordinates, face)) { Block under = world.GetBlock(Coordinates + BlockCoordinates.Down); return(under is Grass || under is Dirt); } return(false); }
public override void PlayerDigging(DiggingStatus status, BlockCoordinates position, API.Blocks.BlockFace face, Vector3 cursorPosition) { }