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);
        }
Exemple #2
0
        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 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 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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        public override bool OnTryIgniteBlock(IEntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            BlockEntityForge bea = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityForge;

            handling = EnumHandling.PreventDefault;

            if (bea == null || !bea.CanIgnite)
            {
                return(false);
            }

            if (secondsIgniting > 0.25f && (int)(30 * secondsIgniting) % 9 == 1)
            {
                Random rand = byEntity.World.Rand;
                Vec3d  dpos = new Vec3d(pos.X + 2 / 8f + 4 / 8f * rand.NextDouble(), pos.Y + 7 / 8f, pos.Z + 2 / 8f + 4 / 8f * rand.NextDouble());

                Block blockFire = byEntity.World.GetBlock(new AssetLocation("fire"));

                AdvancedParticleProperties props = blockFire.ParticleProperties[blockFire.ParticleProperties.Length - 1];
                props.basePos      = dpos;
                props.Quantity.avg = 1;

                IPlayer byPlayer = null;
                if (byEntity is IEntityPlayer)
                {
                    byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
                }

                byEntity.World.SpawnParticles(props, byPlayer);

                props.Quantity.avg = 0;
            }

            return(secondsIgniting < 2f);
        }
Exemple #7
0
        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 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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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;
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
            });
        }
Exemple #14
0
        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;
        }
Exemple #15
0
        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);
                }
            }
        }
Exemple #16
0
 public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
 {
     if (secondsUsed < 1.9)
     {
         return;
     }
 }
Exemple #17
0
        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);
        }
Exemple #18
0
        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;
        }
Exemple #19
0
        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 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;
                }
            }
        }
Exemple #21
0
        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();
        }
Exemple #23
0
        public override bool OnTryIgniteBlock(IEntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            BlockEntityBomb bebomb = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityBomb;

            handling = EnumHandling.PreventDefault;

            return((bebomb == null || bebomb.IsLit) ? false : secondsIgniting < 0.75f);
        }
Exemple #24
0
        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;
        }
Exemple #25
0
        public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                slot.Itemstack.TempAttributes.SetInt("renderVariant", GameMath.Clamp((int)Math.Ceiling(secondsUsed * 4), 0, 3));
            }


            return(true);
        }
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block.BlockMaterial != EnumBlockMaterial.Wood)
            {
                return;
            }
            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling);
        }
Exemple #27
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            if (blockSel == null)
            {
                handling = EnumHandHandling.PreventDefault;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling);
        }
Exemple #28
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            if (be != null && be.CanReceiveAny)
            {
                KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack);

                if (contents.Key == null)
                {
                    slot.Itemstack = new ItemStack(byEntity.World.GetBlock(new AssetLocation("crucible-burned")));
                    slot.MarkDirty();
                    handHandling = EnumHandHandling.PreventDefault;
                    return;
                }


                if (HasSolidifed(slot.Itemstack, contents.Key, byEntity.World))
                {
                    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 IEntityPlayer)
                        {
                            byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
                        }

                        world.PlaySoundAt(new AssetLocation("sounds/hotmetal"), byEntity, byPlayer);
                    }
                }, blockSel.Position, 666);

                handHandling = EnumHandHandling.PreventDefault;
            }
        }
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Attributes.GetInt("aiming") == 0)
            {
                return;
            }

            byEntity.Attributes.SetInt("aiming", 0);
            byEntity.StopAnimation("aim");

            if (secondsUsed < 0.35f)
            {
                return;
            }

            float  damage   = 0.5f;
            string rockType = slot.Itemstack.Collectible.FirstCodePart(1);

            ItemStack stack = slot.TakeOut(1);

            slot.MarkDirty();

            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }
            byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/throw"), byEntity, byPlayer, false, 8);

            EntityProperties type   = byEntity.World.GetEntityType(new AssetLocation("thrownbeenade"));
            Entity           entity = byEntity.World.ClassRegistry.CreateEntity(type);

            ((EntityThrownBeenade)entity).FiredBy         = byEntity;
            ((EntityThrownBeenade)entity).Damage          = damage;
            ((EntityThrownBeenade)entity).ProjectileStack = stack;

            float  acc      = (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0));
            double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75;
            double rndyaw   = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75;

            Vec3d pos      = byEntity.ServerPos.XYZ.Add(0, byEntity.EyeHeight - 0.2, 0);
            Vec3d aheadPos = pos.AheadCopy(1, byEntity.ServerPos.Pitch + rndpitch, byEntity.ServerPos.Yaw + rndyaw);
            Vec3d velocity = (aheadPos - pos) * 0.5;

            entity.ServerPos.SetPos(byEntity.ServerPos.BehindCopy(0.21).XYZ.Add(0, byEntity.EyeHeight - 0.2, 0).Ahead(0.25, 0, byEntity.ServerPos.Yaw + GameMath.PIHALF));
            entity.ServerPos.Motion.Set(velocity);

            entity.Pos.SetFrom(entity.ServerPos);
            entity.World = byEntity.World;

            byEntity.World.SpawnEntity(entity);
            byEntity.StartAnimation("throw");
        }
Exemple #30
0
        public override bool OnHeldInteractCancel(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
        {
            byEntity.Attributes.SetInt("aiming", 0);
            byEntity.StopAnimation("aim");

            if (cancelReason != EnumItemUseCancelReason.ReleasedMouse)
            {
                byEntity.Attributes.SetInt("aimingCancel", 1);
            }

            return(true);
        }