public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (byEntity.Api.Side == EnumAppSide.Server) { IServerPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID) as IServerPlayer; // player.SendMessage(GlobalConstants.GeneralChatGroup, "OnHeldInteractStart on Server", EnumChatType.Notification); } else { ICoreClientAPI capi = byEntity.Api as ICoreClientAPI; // capi.ShowChatMessage("OnHeldInteractStart on Client"); capi.ModLoader.GetModSystem <TailorMod>().OpenTailoringDialog(); } handling = EnumHandHandling.Handled; }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling, ref EnumHandling handling) { EntityBehaviorMilkable bh; if (entitySel != null && (bh = entitySel.Entity.GetBehavior <EntityBehaviorMilkable>()) != null) { if (lcblock.GetContent(slot.Itemstack) != null) { if (api is ICoreClientAPI capi) { capi.TriggerIngameError(this, "useemptybucket", Lang.Get("Use an empty bucket for milking")); } return; } bh.TryBeginMilking(); handling = EnumHandling.PreventDefault; handHandling = EnumHandHandling.PreventDefault; } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel == null) { return; } Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (block.BlockMaterial != EnumBlockMaterial.Wood) { return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel?.BlockEntity(api) is BlockEntityChisel) { handling = EnumHandHandling.PreventDefault; BlockEntityChisel entityChisel = ((BlockEntityChisel)blockSel.BlockEntity(api)); ITreeAttribute blueprintTree = slot?.Itemstack?.Attributes; ITreeAttribute dummy = blueprintTree.Clone(); entityChisel.ToTreeAttributes(dummy); blueprintTree["materials"] = dummy["materials"]; if (byEntity.Controls.Sneak) { blueprintTree["cuboids"] = new IntArrayAttribute(); entityChisel.ToTreeAttributes(blueprintTree); slot.MarkDirty(); } else if (blueprintTree["cuboids"] != null) { entityChisel.FromTreeAtributes(blueprintTree, api.World); } if (api.Side.IsClient()) { entityChisel.RegenMesh(); } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
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 (byEntity.Controls.Sneak && blockSel != null) { IWorldAccessor world = byEntity.World; Block knappingBlock = world.GetBlock(new AssetLocation("knappingsurface")); if (knappingBlock == null) { return; } //world.Logger.Debug("Flint interact start: Test attach"); Block block = world.BlockAccessor.GetBlock(blockSel.Position); if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, knappingBlock, blockSel.Position, BlockFacing.UP)) { if (api.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", Lang.Get("Cannot place a knapping surface here")); } return; } //world.Logger.Debug("Flint interact start: Can place"); BlockPos pos = blockSel.Position.AddCopy(blockSel.Face); if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(knappingBlock)) { return; } BlockSelection placeSel = blockSel.Clone(); placeSel.Position = pos; placeSel.DidOffset = true; string error = ""; //world.Logger.Debug("Flint interact start: Try place"); if (!knappingBlock.TryPlaceBlock(world, byPlayer, slot.Itemstack, placeSel, ref error)) { (api as ICoreClientAPI)?.TriggerIngameError(this, "cantplace", error); return; } world.BlockAccessor.TriggerNeighbourBlockUpdate(pos); if (knappingBlock.Sounds != null) { world.PlaySoundAt(knappingBlock.Sounds.Place, pos.X, pos.Y, pos.Z); } //world.Logger.Debug("Flint interact start: Could place"); BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface; if (bec != null) { bec.BaseMaterial = slot.Itemstack.Clone(); bec.BaseMaterial.StackSize = 1; if (byEntity.World is IClientWorldAccessor) { bec.OpenDialog(world as IClientWorldAccessor, pos, slot.Itemstack); } } //world.Logger.Debug("Flint interact start: Dlg opened"); slot.TakeOut(1); handling = EnumHandHandling.PreventDefaultAction; return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } IWorldAccessor world = byEntity.World; Block firepitBlock = world.GetBlock(new AssetLocation("firepit-construct1")); if (firepitBlock == null) { return; } BlockPos onPos = blockSel.DidOffset ? blockSel.Position : blockSel.Position.AddCopy(blockSel.Face); IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID); if (!byEntity.World.Claims.TryAccess(byPlayer, onPos, EnumBlockAccessFlags.BuildOrBreak)) { return; } Block block = world.BlockAccessor.GetBlock(onPos.DownCopy()); Block atBlock = world.BlockAccessor.GetBlock(onPos); string useless = ""; if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, firepitBlock, onPos.DownCopy(), BlockFacing.UP)) { return; } if (!firepitBlock.CanPlaceBlock(world, byPlayer, new BlockSelection() { Position = onPos, Face = BlockFacing.UP }, ref useless)) { return; } world.BlockAccessor.SetBlock(firepitBlock.BlockId, onPos); if (firepitBlock.Sounds != null) { world.PlaySoundAt(firepitBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer); } itemslot.Itemstack.StackSize--; handHandling = EnumHandHandling.PreventDefaultAction; }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel == null) { return; } IPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID); if (!byEntity.World.Claims.TryAccess(player, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { slot.MarkDirty(); return; } if (!(byEntity is EntityPlayer) || player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(1); slot.MarkDirty(); } EntityProperties type = byEntity.World.GetEntityType(new AssetLocation("armorstand")); Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); if (entity != null) { entity.ServerPos.X = blockSel.Position.X + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.X) + 0.5f; entity.ServerPos.Y = blockSel.Position.Y + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Y); entity.ServerPos.Z = blockSel.Position.Z + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Z) + 0.5f; entity.ServerPos.Yaw = byEntity.SidedPos.Yaw + GameMath.PI; if (player?.PlayerUID != null) { entity.WatchedAttributes.SetString("ownerUid", player.PlayerUID); } entity.Pos.SetFrom(entity.ServerPos); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/torch"), entity, player); byEntity.World.SpawnEntity(entity); handling = EnumHandHandling.PreventDefaultAction; } }
public static void Interact(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling, ref EnumHandling handling) { IWorldAccessor world = byEntity?.World; if (blockSel == null || world == null || !byEntity.Controls.Sneak) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { itemslot.MarkDirty(); return; } BlockGroundStorage blockgs = world.GetBlock(new AssetLocation("groundstorage")) as BlockGroundStorage; if (blockgs == null) { return; } BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position); BlockEntity beAbove = world.BlockAccessor.GetBlockEntity(blockSel.Position.UpCopy()); if (be is BlockEntityGroundStorage || beAbove is BlockEntityGroundStorage) { if (((be as BlockEntityGroundStorage) ?? (beAbove as BlockEntityGroundStorage)).OnPlayerInteractStart(byPlayer, blockSel)) { handHandling = EnumHandHandling.PreventDefault; } return; } // Must be aiming at the up face if (blockSel.Face != BlockFacing.UP) { return; } Block onBlock = world.BlockAccessor.GetBlock(blockSel.Position); // Must have a support below if (!onBlock.CanAttachBlockAt(world.BlockAccessor, blockgs, blockSel.Position, BlockFacing.UP)) { return; } // Must have empty space above BlockPos pos = blockSel.Position.AddCopy(blockSel.Face); if (world.BlockAccessor.GetBlock(pos).Replaceable < 6000) { return; } if (blockgs.CreateStorage(byEntity.World, blockSel, byPlayer)) { handHandling = EnumHandHandling.PreventDefault; } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink; if (be != null) { handHandling = EnumHandHandling.PreventDefault; } if (be != null && be.CanReceiveAny) { KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack); if (contents.Key == null) { string emptiedCode = Attributes["emptiedBlockCode"].AsString(); slot.Itemstack = new ItemStack(byEntity.World.GetBlock(AssetLocation.Create(emptiedCode, Code.Domain))); slot.MarkDirty(); handHandling = EnumHandHandling.PreventDefault; return; } if (HasSolidifed(slot.Itemstack, contents.Key, byEntity.World)) { handHandling = EnumHandHandling.NotHandled; return; } if (contents.Value <= 0) { return; } if (!be.CanReceive(contents.Key)) { return; } be.BeginFill(blockSel.HitPosition); byEntity.World.RegisterCallback((world, pos, dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract) { IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } world.PlaySoundAt(new AssetLocation("sounds/hotmetal"), byEntity, byPlayer); } }, blockSel.Position, 666); handHandling = EnumHandHandling.PreventDefault; } }
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); }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (block is BlockSkep && block.FirstCodePart(1).Equals("populated")) { handling = EnumHandHandling.PreventDefaultAction; } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (!IsPileable) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); return; } if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } BlockPos onBlockPos = blockSel.Position; IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos); if (be is BlockEntityLabeledChest || be is BlockEntitySignPost || be is BlockEntitySign || be is BlockEntityBloomery || be is BlockEntityFirepit || be is BlockEntityForge) { return; } if (be is IBlockEntityItemPile) { IBlockEntityItemPile pile = (IBlockEntityItemPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos.AddCopy(blockSel.Face)); if (be is IBlockEntityItemPile) { IBlockEntityItemPile pile = (IBlockEntityItemPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } } Block block = byEntity.World.GetBlock(PileBlockCode); if (block == null) { return; } BlockPos pos = onBlockPos.Copy(); if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000) { pos.Add(blockSel.Face); } bool ok = ((IBlockItemPile)block).Construct(slot, byEntity.World, pos, byPlayer); Cuboidf[] collisionBoxes = byEntity.World.BlockAccessor.GetBlock(pos).GetCollisionBoxes(byEntity.World.BlockAccessor, pos); if (collisionBoxes != null && collisionBoxes.Length > 0 && CollisionTester.AabbIntersect(collisionBoxes[0], pos.X, pos.Y, pos.Z, byPlayer.Entity.CollisionBox, byPlayer.Entity.SidedPos.XYZ)) { byPlayer.Entity.SidedPos.Y += collisionBoxes[0].Y2 - (byPlayer.Entity.SidedPos.Y - (int)byPlayer.Entity.SidedPos.Y); } if (ok) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling); if (blockSel != null) { int swapRate = slot.Itemstack.Collectible.Attributes["swapRate"].AsInt(0); Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); BlockPos pos = blockSel.Position; if (!swapMapping.TryGetValue(block.Code, out AssetLocation toCode)) { return; } if (slot.Itemstack.StackSize >= swapRate) { if (swapRate > 0) { slot.TakeOut(swapRate); } api.World.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z); api.World.BlockAccessor.SetBlock(api.World.GetBlock(toCode).BlockId, pos); } } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } BlockPos onBlockPos = blockSel.Position; Block block = byEntity.World.BlockAccessor.GetBlock(onBlockPos); if (block is BlockFirepit || block is BlockPitkiln || block is BlockClayOven) { // Prevent placing firewoodpiles when trying to construct firepits return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel != null) { Block selectedBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (selectedBlock?.Attributes?.IsTrue("mealContainer") == true) { ServeIntoBowl(selectedBlock, blockSel.Position, slot, byEntity.World); handHandling = EnumHandHandling.PreventDefault; return; } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { handHandling = EnumHandHandling.PreventDefault; if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { itemslot.MarkDirty(); return; } BlockPeatPile block = byEntity.World.GetBlock(new AssetLocation("peatpile")) as BlockPeatPile; if (block == null) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityPeatPile) { BlockEntityPeatPile pile = (BlockEntityPeatPile)be; pile.OnPlayerInteract(byPlayer); return; } if (be is BlockEntityFirepit) { handHandling = EnumHandHandling.NotHandled; return; } if (be is BlockEntityAnvil) { return; } BlockPos pos = blockSel.Position.AddCopy(blockSel.Face); if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000) { return; } be = byEntity.World.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityPeatPile) { BlockEntityPeatPile pile = (BlockEntityPeatPile)be; pile.OnPlayerInteract(byPlayer); return; } if (!block.Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer)) { handHandling = EnumHandHandling.NotHandled; } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (((ItemCage)slot.Itemstack.Item).IsCase) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); return; } if (byEntity.Controls.Sneak && ((ItemCage)slot.Itemstack.Item).IsEmpty) { IPlayer player = (byEntity as EntityPlayer).Player; InventoryCage inventory = new InventoryCage(player, slot); player.InventoryManager.OpenInventory(inventory); byEntity.Attributes.SetInt("opengui", 1); handling = EnumHandHandling.Handled; return; } byEntity.Attributes.SetInt("opengui", 0); byEntity.Attributes.SetInt("aiming", 1); byEntity.Attributes.SetInt("aimingCancel", 0); byEntity.StartAnimation("aim"); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { handling = EnumHandHandling.PreventDefault; if (!firstEvent) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (byPlayer == null) { return; } if (blockSel != null && !byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } string blockMatCode = GetBlockMaterialCode(slot.Itemstack); if (!byEntity.FeetInLiquid && api.Side == EnumAppSide.Client && blockMatCode != null) { (api as ICoreClientAPI).TriggerIngameError(this, "notinwater", Lang.Get("ingameerror-panning-notinwater")); return; } if (blockMatCode == null && blockSel != null) { TryTakeMaterial(slot, byEntity, blockSel.Position); slot.Itemstack.TempAttributes.SetBool("canpan", false); return; } if (blockMatCode != null) { slot.Itemstack.TempAttributes.SetBool("canpan", true); } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } if (byEntity.Controls.Sneak) { return; } slot.Itemstack.TempAttributes.SetFloat("secondsUsed", 0); IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byEntity.World.BlockAccessor.GetBlock(blockSel.Position).LiquidCode == "water") { BlockPos pos = blockSel.Position; SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds); slot.Itemstack.TempAttributes.SetInt("refilled", 1); slot.MarkDirty(); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer); handHandling = EnumHandHandling.PreventDefault; return; } BlockBucket bucket = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockBucket; if (bucket != null && bucket.GetContent(byEntity.World, blockSel.Position)?.Block?.LiquidCode == "water") { BlockPos pos = blockSel.Position; ItemStack takenWater = bucket.TryTakeContent(byEntity.World, blockSel.Position, 5); SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds * takenWater.StackSize / 5f); slot.Itemstack.TempAttributes.SetInt("refilled", 1); slot.MarkDirty(); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer); handHandling = EnumHandHandling.PreventDefault; } slot.Itemstack.TempAttributes.SetInt("refilled", 0); float remainingwater = GetRemainingWateringSeconds(slot.Itemstack); if (remainingwater <= 0) { return; } if (byEntity.World.Side == EnumAppSide.Client) { byEntity.World.RegisterCallback(After350ms, 350); } handHandling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); return; } bool waterBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)).LiquidCode == "water"; Block block; if (this.Code.Path.Contains("papyrus")) { block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "tallplant-papyrus-water-harvested-free" : "tallplant-papyrus-land-harvested-free")); } else { block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "tallplant-coopersreed-water-harvested-free" : "tallplant-coopersreed-land-harvested-free")); } if (block == null) { base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } blockSel = blockSel.Clone(); blockSel.Position.Add(blockSel.Face); string useless = ""; bool ok = block.TryPlaceBlock(byEntity.World, byPlayer, itemslot.Itemstack, blockSel, ref useless); if (ok) { byEntity.World.PlaySoundAt(block.Sounds.GetBreakSound(byPlayer), blockSel.Position.X + 0.5, blockSel.Position.Y + 0.5, blockSel.Position.Z + 0.5, byPlayer); itemslot.TakeOut(1); itemslot.MarkDirty(); handHandling = EnumHandHandling.PreventDefaultAction; } }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockKnappingSurface)) { return; } BlockEntityKnappingSurface bea = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityKnappingSurface; if (bea == null) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { return; } bea.OnBeginUse(byPlayer, blockSel); handling = EnumHandHandling.PreventDefaultAction; }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract) { IPlayer player = null; if (byEntity is IEntityPlayer) { player = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/poultice"), byEntity, player); } }, 200); JsonObject attr = slot.Itemstack.Collectible.Attributes; if (attr != null && attr["health"].Exists) { handling = EnumHandHandling.PreventDefault; return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } BlockPos onBlockPos = blockSel.Position; Block block = byEntity.World.BlockAccessor.GetBlock(onBlockPos); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } if (block is BlockFirepit) { // Prevent placing firewoodpiles when trying to construct firepits return; } else { BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos); if (be is BlockEntityFirewoodPile) { BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos.AddCopy(blockSel.Face)); if (be is BlockEntityFirewoodPile) { BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } block = byEntity.World.GetBlock(new AssetLocation("firewoodpile")); if (block == null) { return; } BlockPos pos = onBlockPos.AddCopy(blockSel.Face); bool ok = ((BlockFirewoodPile)block).Construct(slot, byEntity.World, pos, byPlayer); Cuboidf[] collisionBoxes = byEntity.World.BlockAccessor.GetBlock(pos).GetCollisionBoxes(byEntity.World.BlockAccessor, pos); if (collisionBoxes != null && collisionBoxes.Length > 0 && CollisionTester.AabbIntersect(collisionBoxes[0], pos.X, pos.Y, pos.Z, byPlayer.Entity.CollisionBox, byPlayer.Entity.LocalPos.XYZ)) { byPlayer.Entity.LocalPos.Y += collisionBoxes[0].Y2 - (byPlayer.Entity.LocalPos.Y - (int)byPlayer.Entity.LocalPos.Y); } if (ok) { handling = EnumHandHandling.PreventDefault; } } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } IPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID); if (!byEntity.World.Claims.TryAccess(player, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } if (!(byEntity is EntityPlayer) || player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(1); slot.MarkDirty(); } AssetLocation location = new AssetLocation(Code.Domain, CodeEndWithoutParts(1)); EntityProperties type = byEntity.World.GetEntityType(location); if (type == null) { byEntity.World.Logger.Error("ItemCreature: No such entity - {0}", location); if (api.World.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "nosuchentity", "No such entity '{0}' loaded."); } return; } Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); if (entity != null) { entity.ServerPos.X = blockSel.Position.X + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.X) + 0.5f; entity.ServerPos.Y = blockSel.Position.Y + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Y); entity.ServerPos.Z = blockSel.Position.Z + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Z) + 0.5f; entity.ServerPos.Yaw = (float)byEntity.World.Rand.NextDouble() * 2 * GameMath.PI; entity.Pos.SetFrom(entity.ServerPos); entity.PositionBeforeFalling.Set(entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z); entity.Attributes.SetString("origin", "playerplaced"); //entity.WatchedAttributes.SetInt("generation", 10); byEntity.World.SpawnEntity(entity); handHandling = EnumHandHandling.PreventDefaultAction; } }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handHandling); return; } ITreeAttribute tree = slot.Itemstack.Attributes; string domain = tree.GetString("domain"); string path = tree.GetString("path"); ITreeAttribute beotree = tree.GetTreeAttribute("attributes"); handHandling = EnumHandHandling.PreventDefault; }
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 void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { byEntity.Attributes.SetInt("didattack", 0); byEntity.World.RegisterCallback((dt) => { IPlayer byPlayer = (byEntity as EntityPlayer).Player; if (byPlayer == null) { return; } if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/player/strike"), byPlayer.Entity, byPlayer, 0.9f + (float)api.World.Rand.NextDouble() * 0.2f, 16, 0.5f); } }, 464); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } if (byEntity.World is IClientWorldAccessor) { IClientWorldAccessor world = byEntity.World as IClientWorldAccessor; ILoadedSound sound; byEntity.World.Api.ObjectCache["temporalGearSound"] = sound = world.LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/gears.ogg"), ShouldLoop = true, Position = blockSel.Position.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f, Pitch = 0.7f }); sound?.Start(); byEntity.World.RegisterCallback((dt) => { // Make sure the sound is stopped if (byEntity.Controls.HandUse == EnumHandInteract.None) { sound?.Stop(); sound?.Dispose(); } }, 3600); byEntity.World.RegisterCallback((dt) => { // Make sure the sound is stopped if (byEntity.Controls.HandUse == EnumHandInteract.None) { sound?.Stop(); sound?.Dispose(); } }, 20); } handHandling = EnumHandHandling.PreventDefault; }