protected override void ActivateSlotLeftClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op) { IWorldAccessor world = inventory.Api.World; BlockBucket bucketblock = sourceSlot.Itemstack?.Block as BlockBucket; if (bucketblock != null) { ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack); bool stackable = !Empty && itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes); if ((Empty || stackable) && bucketContents != null) { ItemStack bucketStack = sourceSlot.Itemstack; ItemStack takenContent = bucketblock.TryTakeContent(world, bucketStack, 1); sourceSlot.Itemstack = bucketStack; takenContent.StackSize += StackSize; this.itemstack = takenContent; MarkDirty(); return; } return; } base.ActivateSlotLeftClick(sourceSlot, ref op); }
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; } BlockBucket blockbucket = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockBucket; string contents = BowlContents(); if (blockbucket != null) { if (contents == null) { ItemStack stack = blockbucket.GetContent(byEntity.World, blockSel.Position); if (stack?.Collectible.Code.Path == "honeyportion") { InsertHoney(slot, byEntity); blockbucket.TryTakeContent(byEntity.World, blockSel.Position, 1); } } else { ItemStack stack = blockbucket.GetContent(byEntity.World, blockSel.Position); if (stack == null || stack.Collectible.Code.Path == "honeyportion") { Item honeyitem = byEntity.World.GetItem(new AssetLocation("honeyportion")); if (blockbucket.TryAddContent(byEntity.World, blockSel.Position, new ItemStack(honeyitem), 1) > 0) { TakeoutHoney(slot, byEntity); } } } handHandling = EnumHandHandling.PreventDefaultAction; return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handHandling); }
protected override void ActivateSlotRightClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op) { IWorldAccessor world = inventory.Api.World; BlockBucket bucketblock = sourceSlot.Itemstack?.Block as BlockBucket; if (bucketblock != null) { if (Empty) { return; } ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack); if (bucketContents == null) { TakeOut(bucketblock.TryAddContent(world, sourceSlot.Itemstack, Itemstack, 1)); MarkDirty(); } else { if (itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes)) { TakeOut(bucketblock.TryAddContent(world, sourceSlot.Itemstack, bucketblock.GetContent(world, sourceSlot.Itemstack), 1)); MarkDirty(); return; } } return; } base.ActivateSlotRightClick(sourceSlot, ref op); }
protected override void ActivateSlotRightClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op) { IWorldAccessor world = inventory.Api.World; BlockBucket bucketblock = sourceSlot.Itemstack?.Block as BlockBucket; if (bucketblock != null) { if (Empty) { return; } ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack); if (bucketContents == null) { TakeOut(bucketblock.TryPutContent(world, sourceSlot.Itemstack, Itemstack, 1)); MarkDirty(); } else { if (itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes)) { TakeOut(bucketblock.TryPutContent(world, sourceSlot.Itemstack, bucketblock.GetContent(world, sourceSlot.Itemstack), 1)); MarkDirty(); return; } } return; } if (itemstack != null && sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true) { string outBlockCode = sourceSlot.Itemstack.ItemAttributes["contentItem2BlockCodes"][itemstack.Collectible.Code.ToShortString()].AsString(); if (outBlockCode != null) { ItemStack outBlockStack = new ItemStack(world.GetBlock(AssetLocation.Create(outBlockCode, sourceSlot.Itemstack.Collectible.Code.Domain))); if (sourceSlot.StackSize == 1) { sourceSlot.Itemstack = outBlockStack; } else { sourceSlot.Itemstack.StackSize--; if (!op.ActingPlayer.InventoryManager.TryGiveItemstack(outBlockStack)) { world.SpawnItemEntity(outBlockStack, op.ActingPlayer.Entity.Pos.XYZ); } } sourceSlot.MarkDirty(); TakeOut(1); } return; } if (sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true || sourceSlot.Itemstack?.ItemAttributes?["contentItemCode"].AsString() != null) { return; } base.ActivateSlotRightClick(sourceSlot, ref op); }
protected override void ActivateSlotLeftClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op) { IWorldAccessor world = inventory.Api.World; BlockBucket bucketblock = sourceSlot.Itemstack?.Block as BlockBucket; if (bucketblock != null) { ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack); bool stackable = !Empty && itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes); if ((Empty || stackable) && bucketContents != null) { ItemStack bucketStack = sourceSlot.Itemstack; ItemStack takenContent = bucketblock.TryTakeContent(world, bucketStack, op.ActingPlayer?.Entity?.Controls.Sneak == true ? 10 : 1); sourceSlot.Itemstack = bucketStack; takenContent.StackSize += StackSize; this.itemstack = takenContent; MarkDirty(); return; } return; } string contentItemCode = sourceSlot.Itemstack?.ItemAttributes?["contentItemCode"].AsString(); if (contentItemCode != null) { ItemStack contentStack = new ItemStack(world.GetItem(AssetLocation.Create(contentItemCode, sourceSlot.Itemstack.Collectible.Code.Domain))); bool stackable = !Empty && itemstack.Equals(world, contentStack, GlobalConstants.IgnoredStackAttributes); if ((Empty || stackable) && contentStack != null) { if (stackable) { this.itemstack.StackSize++; } else { this.itemstack = contentStack; } MarkDirty(); ItemStack bowlStack = new ItemStack(world.GetBlock(AssetLocation.Create(sourceSlot.Itemstack.ItemAttributes["emptiedBlockCode"].AsString(), sourceSlot.Itemstack.Collectible.Code.Domain))); if (sourceSlot.StackSize == 1) { sourceSlot.Itemstack = bowlStack; } else { sourceSlot.Itemstack.StackSize--; if (!op.ActingPlayer.InventoryManager.TryGiveItemstack(bowlStack)) { world.SpawnItemEntity(bowlStack, op.ActingPlayer.Entity.Pos.XYZ); } } sourceSlot.MarkDirty(); } return; } if (sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true) { return; } base.ActivateSlotLeftClick(sourceSlot, ref op); }
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; }