/// <summary> /// Converts an item to its entity equivalent. /// TODO: Registry / helpers / something / anything! /// </summary> /// <param name="item">The item to convert.</param> /// <returns>An entity.</returns> public PhysicsEntity ItemToEntity(ItemStack item) { if (item.Info is BlockItem) { return(new BlockItemEntity(this, BlockInternal.FromItemDatum(item.Datum), Location.Zero)); } if (item.Info is GlowstickItem) { return(new GlowstickEntity(item.DrawColor, this)); } if (item.Info is SmokegrenadeItem) { return(new SmokeGrenadeEntity(item.DrawColor, this, item.GetAttributeI("big_smoke", 0) == 0 ? ParticleEffectNetType.SMOKE : ParticleEffectNetType.BIG_SMOKE) { SmokeLeft = item.GetAttributeI("max_smoke", 300) }); } if (item.Info is ExplosivegrenadeItem) { return(new ExplosiveGrenadeEntity(this)); } if (item.Info is PaintbombItem) { int paint = item.Datum; return(new PaintBombEntity((byte)paint, this)); } return(new ItemEntity(item, this)); }
public override Entity Create(Region tregion, BsonDocument doc) { BlockItemEntity ent = new BlockItemEntity(tregion, BlockInternal.FromItemDatum(doc["bie_bi"].AsInt32), Location.Zero); ent.ApplyPhysicsData(doc); return(ent); }
public override Entity Create(Region tregion, byte[] data) { int itsbyte = Utilities.BytesToInt(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength, 4)); BlockInternal bi = BlockInternal.FromItemDatum(itsbyte); StaticBlockEntity sbe = new StaticBlockEntity(tregion, bi.Material, bi.BlockPaint); sbe.ApplyPhysicsNetworkData(data); return(sbe); }
public override void AltClick(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; Location eye = player.ItemSource(); Location forw = player.ItemDir; RayCastResult rcr; bool h = player.TheRegion.SpecialCaseRayTrace(eye, forw, 5, MaterialSolidity.ANY, player.IgnoreThis, out rcr); if (h) { if (rcr.HitObject != null && rcr.HitObject is EntityCollidable && ((EntityCollidable)rcr.HitObject).Entity != null) { // TODO: ??? } else if (player.Mode.GetDetails().CanPlace&& player.TheRegion.GlobalTickTime - player.LastBlockPlace >= 0.2) { Location block = new Location(rcr.HitData.Location) + new Location(rcr.HitData.Normal).Normalize() * 0.9f; block = block.GetBlockLocation(); Material mat = player.TheRegion.GetBlockMaterial(block); if (player.TheRegion.IsAllowedToPlaceIn(player, block, mat)) { CollisionResult hit = player.TheRegion.Collision.CuboidLineTrace(new Location(0.45, 0.45, 0.45), block + new Location(0.5), block + new Location(0.5, 0.5, 0.501), player.TheRegion.Collision.ShouldCollide); if (!hit.Hit) { BlockInternal bi = BlockInternal.FromItemDatum(item.Datum); MusicBlockEntity mbe = new MusicBlockEntity(player.TheRegion, item, block); // TODO: Vary based on material! player.TheRegion.SpawnEntity(mbe); player.Network.SendPacket(new DefaultSoundPacketOut(block, DefaultSound.PLACE, (byte)((Material)bi.BlockMaterial).Sound())); item.Count = item.Count - 1; if (item.Count <= 0) { player.Items.RemoveItem(player.Items.cItem); } else { player.Items.SetSlot(player.Items.cItem - 1, item); } player.LastBlockPlace = player.TheRegion.GlobalTickTime; } } } } }
public override void SetTextureName(string name) { if (name == null || name.Length == 0) { Tex = null; } else { if (name.Contains(":") && name.Before(":").ToLowerFast() == "render_block") { string[] blockDataToRender = name.After(":").SplitFast(','); if (blockDataToRender[0] == "self") { BlockInternal bi = BlockInternal.FromItemDatum(Datum); RenderedBlock = new BlockItemEntity(TheClient.TheRegion, bi.Material, bi.BlockData, bi.BlockPaint, bi.Damage); RenderedBlock.GenVBO(); } else { Material mat = MaterialHelpers.FromNameOrNumber(blockDataToRender[0]); byte data = (byte)(blockDataToRender.Length < 2 ? 0 : Utilities.StringToInt(blockDataToRender[1])); byte paint = (byte)(blockDataToRender.Length < 3 ? 0 : Colors.ForName(blockDataToRender[2])); BlockDamage damage = blockDataToRender.Length < 4 ? BlockDamage.NONE : (BlockDamage)Enum.Parse(typeof(BlockDamage), blockDataToRender[3], true); RenderedBlock = new BlockItemEntity(TheClient.TheRegion, mat, data, paint, damage); RenderedBlock.GenVBO(); } Tex = null; } if (name.Contains(":") && name.Before(":").ToLowerFast() == "render_model") { string model = name.After(":"); if (model.ToLowerFast() == "self") { model = GetModelName(); } RenderedModel = new ModelEntity(model, TheClient.TheRegion) { Visible = true }; RenderedModel.PreHandleSpawn(); Tex = null; } else { Tex = TheClient.Textures.GetTexture(name); } } }