public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face.GetOpposite())); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byPlayer != null && be is BlockEntityToolMold) { BlockEntityToolMold beim = (BlockEntityToolMold)be; if (beim.OnPlayerInteract(byPlayer, blockSel.Face, blockSel.HitPosition)) { handHandling = EnumHandHandling.PreventDefault; } } }
public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { BlockPos position = null; IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); position = this.currentEvents[byPlayer]; } BlockPos temp1 = blockSel.Position; if (blockSel.Position != position || !byEntity.Pos.InRangeOf(position, 4)) { return(false); } if (secondsUsed > 2f) { return(false); } if (secondsUsed > 1 && secondsUsed % 10 < 1.05) { byEntity.World.PlaySoundAt(new AssetLocation("fillthegaps", "sounds/rubbing-stones"), byEntity, byPlayer, false, 8); } return(true); }
public override bool OnHeldAttackStep(float secondsPassed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel) { if (byEntity.World.Side == EnumAppSide.Client) { IClientWorldAccessor world = byEntity.World as IClientWorldAccessor; ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Rotation.X = Math.Min(60, secondsPassed * 360); if (secondsPassed > 0.3) { tf.Translation.Z -= Math.Min(1.5f, 36f * (secondsPassed - 0.3f)); tf.Rotation.X -= Math.Max(-40, secondsPassed * 500); } byEntity.Controls.UsingHeldItemTransformAfter = tf; if (secondsPassed > 0.43f && byEntity.Attributes.GetInt("didattack") == 0) { world.TryAttackEntity(entitySel); byEntity.Attributes.SetInt("didattack", 1); world.ShakeCamera(0.25f); } } return(secondsPassed < 0.9f); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (byPlayer == null) { return; } EnumCharacterDressType dresstype; string strdress = slot.Itemstack.ItemAttributes["clothescategory"].AsString(); if (!Enum.TryParse(strdress, true, out dresstype)) { return; } IInventory inv = byPlayer.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName); if (inv == null) { return; } if (inv.GetSlot((int)dresstype).TryFlipWith(slot)) { handHandling = EnumHandHandling.PreventDefault; } }
public override bool OnHeldAttackStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel) { if (byEntity.World is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); //30 - secondsUsed * 90 * 15 = -110 //-30 + secondsUsed * 90 * 15 = 110 //secondsUsed * 90 * 15 = 110 - 30 //secondsUsed = (110 - 30) / (90*15) float speed = 5 + 20 * Math.Max(0, secondsUsed - 0.25f); float start = secondsUsed * 120; float rotationY = Math.Min(110, Math.Max(0, secondsUsed - 0.25f) * 90 * speed - start); tf.Origin.Set(0, 0, 0.5f); tf.Translation.Set(0, 0, Math.Max(-0.25f, -1.25f * Math.Max(0, secondsUsed - 0.25f))); tf.Rotation.Y = rotationY; byEntity.Controls.UsingHeldItemTransformBefore = tf; } return(secondsUsed < 0.6f); }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { BlockPos position = null; IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); try{ position = this.currentEvents[byPlayer]; } catch { return; } } this.currentEvents.Remove(byPlayer); if (secondsUsed > 1.95f) { string polished = "rockpolished-" + byEntity.World.BlockAccessor.GetBlock(position).CodeEndWithoutParts(1); byEntity.World.BlockAccessor.SetBlock(byEntity.World.GetBlock(new AssetLocation(polished)).BlockId, position); byEntity.World.BlockAccessor.MarkBlockDirty(position); slot.TakeOut(1); slot.MarkDirty(); } }
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); } } }
private void RefillSlotIfEmpty(IItemSlot slot, IEntityAgent byEntity) { if (!slot.Empty) { return; } byEntity.WalkInventory((invslot) => { if (invslot is ItemSlotCreative) { return(true); } if (invslot.Itemstack != null && invslot.Itemstack.Collectible is ItemSpear) { invslot.TryPutInto(byEntity.World, slot); invslot.Inventory.PerformNotifySlot(invslot.Inventory.GetSlotId(invslot)); slot.Inventory.PerformNotifySlot(slot.Inventory.GetSlotId(slot)); return(false); } return(true); }); }
public override void DrawToolModeIcon(IItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection, Context cr, int x, int y, int width, int height, int toolMode, int color) { float[] colordoubles = ColorUtil.ToRGBAFloats(color); switch (toolMode) { case 0: DrawHit(cr, x, y, width, height, colordoubles); break; case 1: DrawUpset(cr, x, y, width, height, colordoubles, 0); break; case 2: DrawUpset(cr, x, y, width, height, colordoubles, GameMath.PI / 2); break; case 3: DrawUpset(cr, x, y, width, height, colordoubles, GameMath.PI); break; case 4: DrawUpset(cr, x, y, width, height, colordoubles, 3 * GameMath.PI / 2); break; case 5: DrawSplit(cr, x, y, width, height, colordoubles); break; } }
/// <summary> /// Intializes a new <see cref="ReplaceitemEntityCommand"/> /// </summary> /// <param name="selector">Selector selecting the entities to replace the item on</param> /// <param name="slot">The slot to put the item into</param> /// <param name="item">The item to put into the block</param> /// <param name="count">The amount of the item</param> public ReplaceitemEntityCommand(BaseSelector selector, IItemSlot slot, Item item, int count) { Selector = selector; Slot = slot; Item = item; Count = count; }
public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null || !(byEntity is EntityPlayer)) { return(false); } FpHandTransform.Rotation.Y = GameMath.Mod(byEntity.World.ElapsedMilliseconds / (50f - secondsUsed * 20), 360); TpHandTransform.Rotation.Y = GameMath.Mod(byEntity.World.ElapsedMilliseconds / (50f - secondsUsed * 20), 360); if (byEntity.World is IClientWorldAccessor) { particlesHeld.minQuantity = 1; Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition); SpawnParticles(byEntity.World, pos, false); (byEntity.World as IClientWorldAccessor).ShakeCamera(0.035f); ILoadedSound sound = byEntity.World.Api.ObjectCache["temporalGearSound"] as ILoadedSound; sound?.SetPitch(0.7f + secondsUsed / 4); } return(secondsUsed < 3.5); }
/// <summary> /// Intializes a new <see cref="ReplaceitemBlockCommand"/> /// </summary> /// <param name="coordinates">The coordinates of the block to put the item into</param> /// <param name="slot">The slot to put the item into</param> /// <param name="item">The item to put into the block</param> /// <param name="count">The amount of the item</param> public ReplaceitemBlockCommand(Vector coordinates, IItemSlot slot, Item item, int count) { Coordinates = coordinates; Slot = slot; Item = item; Count = count; }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (secondsUsed < 1.9) { return; } }
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 override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return; } Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); bool ok = block is BlockSkep && block.FirstCodePart(1).Equals("populated"); if (!ok) { return; } if (secondsUsed < 3.9f) { return; } slot.TakeOut(1); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byPlayer?.InventoryManager.TryGiveItemstack(new ItemStack(byEntity.World.GetItem(new AssetLocation("beenade-closed")))); Block skepemtpyblock = byEntity.World.GetBlock(new AssetLocation("skep-empty-" + block.LastCodePart())); byEntity.World.BlockAccessor.SetBlock(skepemtpyblock.BlockId, blockSel.Position); }
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 DidModifyItemSlot(IItemSlot slot, IItemStack extractedStack = null) { base.DidModifyItemSlot(slot, extractedStack); if (slots[1] == slot) { if (slot.Itemstack == null) { discardCookingSlots(); } else { int storageType = defaultStorageType; if (slot.Itemstack.ItemAttributes?["storageType"] != null) { storageType = slot.Itemstack.ItemAttributes["storageType"].AsInt(defaultStorageType); } for (int i = 0; i < cookingSlots.Length; i++) { cookingSlots[i].StorageType = (EnumItemStorageFlags)storageType; } } } }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { IItemSlot invslot = GetNextArrow(byEntity); if (invslot == null) { return; } if (byEntity.World is IClientWorldAccessor) { slot.Itemstack.TempAttributes.SetInt("renderVariant", 1); } // Not ideal to code the aiming controls this way. Needs an elegant solution - maybe an event bus? byEntity.Attributes.SetInt("aiming", 1); byEntity.Attributes.SetInt("aimingCancel", 0); byEntity.StartAnimation("bowaim"); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byEntity.World.PlaySoundAt(new AssetLocation("sounds/bow-draw"), byEntity, byPlayer, false, 8); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling, ref EnumHandling blockHandling) { if (blockSel == null) { return; } Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (!byEntity.Controls.Sneak) { EnumHandling igniteHandled = EnumHandling.NotHandled; bool handledResult = block.OnTryIgniteBlock(byEntity, blockSel.Position, 0, ref igniteHandled); if (igniteHandled == EnumHandling.NotHandled) { return; } } Block freeBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)); if (freeBlock.BlockId != 0) { return; } blockHandling = EnumHandling.PreventDefault; handHandling = EnumHandHandling.PreventDefault; IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; byEntity.World.PlaySoundAt(new AssetLocation("sounds/torch-ignite"), byEntity, byPlayer, false, 16); }
public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return(false); } if (byEntity.World is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Translation.Set(Math.Min(0.6f, secondsUsed * 2), 0, 0); //-Math.Min(1.1f / 3, secondsUsed * 4 / 3f) tf.Rotation.Y = Math.Min(20, secondsUsed * 90 * 2f); if (secondsUsed > 0.4f) { tf.Translation.X += (float)Math.Sin(secondsUsed * 30) / 10; } byEntity.Controls.UsingHeldItemTransformBefore = tf; } return(secondsUsed < 2f); }
public override void OnHeldAttackStart(IItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (byEntity.World.Side == EnumAppSide.Client) { handling = EnumHandHandling.PreventDefaultAction; return; } if (blockSel == null) { return; } ModSystemBlockReinforcement bre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); IServerPlayer player = (byEntity as EntityPlayer).Player as IServerPlayer; if (player == null) { return; } string errorCode = ""; if (!bre.TryRemoveReinforcement(blockSel.Position, player, ref errorCode)) { player.SendMessage(GlobalConstants.CurrentChatGroup, "Cannot remove reinforcement: " + errorCode, EnumChatType.Notification); return; } BlockPos pos = blockSel.Position; byEntity.World.PlaySoundAt(new AssetLocation("blockreinforcement", "sounds/reinforce"), pos.X, pos.Y, pos.Z, null); handling = EnumHandHandling.PreventDefaultAction; }
public override void OnHeldAttackStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel != null) { return; } 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, byPlayer); } }, 464); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } 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)) { itemslot.MarkDirty(); return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face)); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } Block block = byEntity.World.GetBlock(new AssetLocation("platepile")); if (block == null) { return; } if (((BlockPlatePile)block).Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer)) { handling = EnumHandHandling.PreventDefault; } }
public override void OnHeldAttackStart(IItemSlot slot, IEntityAgent 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 IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } bea.OnBeginUse(byPlayer, blockSel); handling = EnumHandHandling.PreventDefaultAction; }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null || byEntity.Controls.Sneak) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; Block targetedBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (targetedBlock.HasBehavior(typeof(BlockBehaviorLiquidContainer), true)) { if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { return; } BlockBehaviorLiquidContainer bh = targetedBlock.GetBehavior(typeof(BlockBehaviorLiquidContainer), true) as BlockBehaviorLiquidContainer; if (bh.OnInteractWithBucket(itemslot, byEntity, blockSel)) { handHandling = EnumHandHandling.PreventDefaultAction; return; } } if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } ItemStack contentStack = GetContent(byEntity.World, itemslot.Itemstack); bool isEmpty = contentStack == null; if (!TryFillBucketFromBlock(itemslot, byEntity, blockSel.Position)) { BlockBucket targetBucket = targetedBlock as BlockBucket; if (targetBucket != null) { if (targetBucket.TryAddContent(byEntity.World, blockSel.Position, contentStack, 1) > 0) { TryTakeContent(byEntity.World, itemslot.Itemstack, 1); WaterTightContainableProps props = GetContentProps(byEntity.World, itemslot.Itemstack); byEntity.World.PlaySoundAt(props.FillSpillSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer); } } else { SpillContents(itemslot, byEntity, blockSel); } } // Prevent placing on normal use handHandling = EnumHandHandling.PreventDefaultAction; }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { pouringLoop?.Stop(); pouringLoop?.Dispose(); pouringLoop = null; slot.MarkDirty(); }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { // Not ideal to code the aiming controls this way. Needs an elegant solution - maybe an event bus? byEntity.Attributes.SetInt("aiming", 1); byEntity.Attributes.SetInt("aimingCancel", 0); byEntity.StartAnimation("aim"); handling = EnumHandHandling.PreventDefault; }
public virtual void ClearItem(int slotIndex) { IItemSlot slot = GetItem(slotIndex); if (slot is not null) { slot.Reset(); } }
public void GetSelectedItemSlotWithEmptyHotBarTest() { IItemSlot itemSlot = _hotBar.SelectedSlot; Assert.NotNull(itemSlot); Assert.False(itemSlot.HasItem); Assert.Null(itemSlot.ItemId); Assert.Equal(0, itemSlot.ItemCount); }
public virtual bool AddItem(TItem item) { if (!HasItem(item.ID)) { IItemSlot <TItem> slot = FindAnySlot(x => x.CanHoldItem(item)); return(slot != null?AddItem(item, slot) : false); } return(Items[item.ID].Stack()); }