public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { if (notplucking && itemslot.Empty) { notplucking = false; ItemStack feather = new ItemStack(entity.World.GetItem(new AssetLocation("game:feather")), 1); feather.StackSize = entity.World.Rand.Next(1, 2); source.sourcePos = hitPosition; source.SourceEntity = byEntity; entity.ReceiveDamage(source, (float)((entity.World.Rand.NextDouble() * 0.25) / 2)); if (byEntity.World.Side.IsServer()) { if (!byEntity.TryGiveItemStack(feather)) { entity.World.SpawnItemEntity(feather, entity.Pos.XYZ); } } entity.World.RegisterCallback(dt => { notplucking = true; }, 2000); } }
public static void GiveOrDrop(EntityAgent eagent, ItemStack stack, int quantity) { if (stack == null) { return; } while (quantity > 0) { int stacksize = Math.Min(quantity, stack.Collectible.MaxStackSize); if (stacksize <= 0) { return; } ItemStack stackPart = stack.Clone(); stackPart.StackSize = stacksize; if (!eagent.TryGiveItemStack(stackPart)) { eagent.World.SpawnItemEntity(stackPart, eagent.Pos.XYZ); } quantity -= stacksize; } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { var clothids = ClothIds; if (clothids == null || clothids.value.Length == 0) { return; } int clothid = ClothIds.value[0]; ClothIds.RemoveInt(clothid); var sys = byEntity.World.Api.ModLoader.GetModSystem <ClothManager>().GetClothSystem(clothid); if (sys != null) { Detach(sys); var ends = sys.Ends; Vec3d lpos = new Vec3d(0, byEntity.LocalEyePos.Y - 0.25f, 0); Vec3d aheadPos = lpos.AheadCopy(0.25f, byEntity.SidedPos.Pitch, byEntity.SidedPos.Yaw); (ends[0].Pinned ? ends[1] : ends[0]).PinTo(byEntity, aheadPos.ToVec3f()); ItemStack stack = new ItemStack(entity.World.GetItem(new AssetLocation("rope"))); stack.Attributes.SetInt("clothId", sys.ClothId); if (!byEntity.TryGiveItemStack(stack)) { entity.World.SpawnItemEntity(stack, byEntity.Pos.XYZ); } } }
public void TryGiveItem(ItemStack stack, ItemSlot slot, EntityAgent byEntity, WaterTightContainableProps props, BlockPos pos) { slot.TakeOut(1); if (!byEntity.TryGiveItemStack(stack)) { api.World.SpawnItemEntity(stack, pos.ToVec3d()); } api.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel != null) { BlockEntityBarrel beba = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel; var liqslot = beba?.Inventory[1]; if (beba != null && !liqslot.Empty) { if (liqslot.Itemstack.Item?.Code?.Path == "cottagecheeseportion") { var props = BlockLiquidContainerBase.GetContainableProps(liqslot.Itemstack); float curLitres = liqslot.Itemstack.StackSize / props.ItemsPerLitre; if (curLitres < 25) { (api as ICoreClientAPI)?.TriggerIngameError(this, "notenough", Lang.Get("Need at least 25 litres to create a roll of cheese")); handHandling = EnumHandHandling.PreventDefault; return; } if (api.World.Side == EnumAppSide.Server) { ItemStack ccStack = beba.Inventory[1].TakeOut((int)(25 * props.ItemsPerLitre)); BlockCheeseCurdsBundle block = api.World.GetBlock(new AssetLocation("curdbundle")) as BlockCheeseCurdsBundle; ItemStack bundleStack = new ItemStack(block); block.SetContents(bundleStack, ccStack); slot.TakeOut(1); slot.MarkDirty(); beba.MarkDirty(true); if (!byEntity.TryGiveItemStack(bundleStack)) { api.World.SpawnItemEntity(bundleStack, byEntity.Pos.XYZ.AddCopy(0, 0.5, 0)); } } handHandling = EnumHandHandling.PreventDefault; return; } } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { if (itemslot.Itemstack == null) { return; } if (itemslot.Itemstack.Block is BlockBucket) { handled = EnumHandling.PreventDefault; ItemStack milkstack = new ItemStack(milk, RemainingLiters); BlockBucket bucket = itemslot.Itemstack.Block as BlockBucket; ItemStack contents = bucket.GetContent(byEntity.World, itemslot.Itemstack); if ((contents == null || contents.Item == milk) && RemainingLiters > 0) { if (contents?.StackSize != null && contents.StackSize / milkProps.ItemsPerLitre >= bucket.CapacityLitres) { return; } DummySlot slot = new DummySlot(itemslot.TakeOut(1)); int taken = bucket.TryPutContent(byEntity.World, slot.Itemstack, milkstack, 1); if (taken > 0) { RemainingLiters -= taken; if (byEntity.World.Side == EnumAppSide.Client) { byEntity.World.SpawnCubeParticles(entity.Pos.XYZ + new Vec3d(0, 0.5, 0), milkstack, 0.3f, 4, 0.5f, (byEntity as EntityPlayer)?.Player); } if (id == 0 && RemainingLiters < defaultvalue) { if (NextTimeMilkable == 0) { NextTimeMilkable = GetNextTimeMilkable(); } id = entity.World.RegisterGameTickListener(MilkListener, 1000); } byEntity.TryGiveItemStack(slot.Itemstack); itemslot.MarkDirty(); } } } base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled); }
public void MilkingComplete(ItemSlot slot, EntityAgent byEntity) { lastMilkedTotalHours = entity.World.Calendar.TotalHours; entity.WatchedAttributes.SetFloat("lastMilkedTotalHours", (float)lastMilkedTotalHours); BlockLiquidContainerBase lcblock = slot.Itemstack.Collectible as BlockLiquidContainerBase; if (lcblock == null) { return; } if (entity.World.Side == EnumAppSide.Server) { ItemStack contentStack = new ItemStack(byEntity.World.GetItem(new AssetLocation("milkportion"))); contentStack.StackSize = 999999; if (slot.Itemstack.StackSize == 1) { lcblock.TryPutLiquid(slot.Itemstack, contentStack, yieldLitres); } else { ItemStack containerStack = slot.TakeOut(1); lcblock.TryPutLiquid(containerStack, contentStack, yieldLitres); if (!byEntity.TryGiveItemStack(containerStack)) { byEntity.World.SpawnItemEntity(containerStack, byEntity.Pos.XYZ.Add(0, 0.5, 0)); } } slot.MarkDirty(); } milkSound?.Stop(); milkSound?.Dispose(); }
public override void OnInteract(EntityAgent byEntity, IItemSlot slot, Vec3d hitPosition, int mode) { if (!Alive || World.Side == EnumAppSide.Client || mode == 0) { base.OnInteract(byEntity, slot, hitPosition, mode); } string owneruid = WatchedAttributes.GetString("ownerUid", null); string agentUid = (byEntity as EntityPlayer)?.PlayerUID; if (agentUid != null && (owneruid == null || owneruid == "" || owneruid == agentUid) && byEntity.Controls.Sneak) { ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation("strawdummy"))); if (!byEntity.TryGiveItemStack(stack)) { byEntity.World.SpawnItemEntity(stack, ServerPos.XYZ); } Die(); return; } base.OnInteract(byEntity, slot, hitPosition, mode); }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { IPlayer plr = (byEntity as EntityPlayer)?.Player; if (plr != null && !byEntity.World.Claims.TryAccess(plr, Pos.AsBlockPos, EnumBlockAccessFlags.Use)) { plr.InventoryManager.ActiveHotbarSlot.MarkDirty(); WatchedAttributes.MarkAllDirty(); return; } if (mode == EnumInteractMode.Interact && byEntity.RightHandItemSlot != null) { ItemSlot handslot = byEntity.RightHandItemSlot; if (handslot.Empty) { // Start from armor slot because it can't wear clothes atm for (int i = 0; i < GearInventory.Count; i++) { ItemSlot gslot = GearInventory[i]; if (gslot.Empty) { continue; } if (gslot.TryPutInto(byEntity.World, handslot) > 0) { return; } } } else { if (!ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorBody) && !ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorHead) && !ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorLegs)) { (byEntity.World.Api as ICoreClientAPI)?.TriggerIngameError(this, "cantplace", "Cannot place dresses on armor stands"); return; } } WeightedSlot sinkslot = GearInventory.GetBestSuitedSlot(handslot); if (sinkslot.weight > 0 && sinkslot.slot != null) { handslot.TryPutInto(byEntity.World, sinkslot.slot); return; } bool empty = true; for (int i = 0; i < GearInventory.Count; i++) { ItemSlot gslot = GearInventory[i]; empty &= gslot.Empty; } if (empty && byEntity.Controls.Sneak) { ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation("armorstand"))); if (!byEntity.TryGiveItemStack(stack)) { byEntity.World.SpawnItemEntity(stack, ServerPos.XYZ); } Die(); return; } } if (!Alive || World.Side == EnumAppSide.Client || mode == 0) { //base.OnInteract(byEntity, slot, hitPosition, mode); return; } base.OnInteract(byEntity, slot, hitPosition, mode); }