public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (byEntity.World.Side != EnumAppSide.Server) { handling = EnumHandHandling.PreventDefault; return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (!(byPlayer is IServerPlayer)) { return; } IServerPlayer serverplayer = byPlayer as IServerPlayer; TreeAttribute tree = new TreeAttribute(); tree.SetString("playeruid", byPlayer?.PlayerUID); tree.SetString("category", itemslot.Itemstack.Attributes.GetString("category")); tree.SetItemstack("itemstack", itemslot.Itemstack.Clone()); api.Event.PushEvent("loreDiscovery", tree); itemslot.TakeOut(1); itemslot.MarkDirty(); handling = EnumHandHandling.PreventDefault; }
public void MountableToTreeAttributes(TreeAttribute tree) { tree.SetString("className", "bed"); tree.SetInt("posx", pos.X); tree.SetInt("posy", pos.Y); tree.SetInt("posz", pos.Z); }
public override void ToBytes(BinaryWriter writer, bool forClient) { if (!forClient) { ITreeAttribute ctree = new TreeAttribute(); WatchedAttributes["commandQueue"] = ctree; ITreeAttribute commands = new TreeAttribute(); ctree["commands"] = commands; int i = 0; foreach (var val in Commands) { ITreeAttribute attr = new TreeAttribute(); val.ToAttribute(attr); attr.SetString("type", val.Type); commands["cmd" + i] = attr; i++; } } base.ToBytes(writer, forClient); }
public EntityBehaviorNameTag(Entity entity) : base(entity) { ITreeAttribute nametagTree = entity.WatchedAttributes.GetTreeAttribute("nametag"); if (nametagTree == null) { entity.WatchedAttributes.SetAttribute("nametag", nametagTree = new TreeAttribute()); nametagTree.SetString("name", ""); nametagTree.SetInt("showtagonlywhentargeted", 0); nametagTree.SetInt("renderRange", 999); entity.WatchedAttributes.MarkPathDirty("nametag"); } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { IPlayer byPlayer = (byEntity as EntityPlayer).Player; if (byPlayer == null) { return; } TreeAttribute tree = new TreeAttribute(); tree.SetString("inventoryId", slot.Inventory.InventoryID); tree.SetInt("slotId", slot.Inventory.GetSlotId(slot)); api.Event.PushEvent("OpenLootRandomizerDialog", tree); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (byPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative) { TreeAttribute tree = new TreeAttribute(); tree.SetInt("posX", blockSel.Position.X); tree.SetInt("posY", blockSel.Position.Y); tree.SetInt("posZ", blockSel.Position.Z); tree.SetString("playerUid", byPlayer.PlayerUID); api.Event.PushEvent("configTeleporter", tree); return(true); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
/// <summary> Initialize the helper </summary> public void Initialize() { if (allomancyTree == null) { // The entity doesn't have any allomantic properties registered, so we add them. Entity.WatchedAttributes.SetAttribute("allomancy", allomancyTree = new TreeAttribute()); allomancyTree.SetAttribute("powers", new TreeAttribute()); allomancyTree.SetAttribute("metals", new TreeAttribute()); allomancyTree.SetAttribute("status", new TreeAttribute()); allomancyTree.SetAttribute("toggle", new TreeAttribute()); allomancyTree.SetString("selectedMetal", "none"); allomancyTree.SetFloat("pewterFatigue", 0); // Make the entity a random misting. string chosenPower = MistModSystem.METALS[RNG.Next(0, MistModSystem.METALS.Length)]; AllomanticPowers.SetBool(chosenPower, true); Entity.WatchedAttributes.MarkPathDirty("allomancy"); return; } }
static bool Prefix(BlockTeleporter __instance, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref bool __result) { if (byPlayer.WorldData.CurrentGameMode == EnumGameMode.Survival) { ItemStack heldItem = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack; if (heldItem != null && heldItem.Item is ItemPadlock) { world.BlockAccessor.BreakBlock(blockSel.Position, byPlayer); __result = true; return(false); } TreeAttribute tree = new TreeAttribute(); tree.SetInt("posX", blockSel.Position.X); tree.SetInt("posY", blockSel.Position.Y); tree.SetInt("posZ", blockSel.Position.Z); tree.SetString("playerUid", byPlayer.PlayerUID); world.Api.Event.PushEvent("configTeleporter", tree); __result = true; } return(false); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } TreeAttribute tree = new TreeAttribute(); tree.SetFloat("totalChance", slot.Itemstack.Attributes.GetFloat("totalChance", 1)); tree.SetString("inventoryId", slot.Inventory.InventoryID); tree.SetInt("slotId", slot.Inventory.GetSlotId(slot)); api.Event.PushEvent("OpenStackRandomizerDialog", tree); }
/// <summary> Set the currently selected metal for the entity with this behavior </summary> public void SetSelectedMetal(string metal) { allomancyTree.SetString("selectedMetal", metal); Entity.WatchedAttributes.MarkPathDirty("allomancy"); }