Esempio n. 1
0
        public override void OnHeldAttackStart(ItemSlot 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 modBre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
            IServerPlayer player = (byEntity as EntityPlayer).Player as IServerPlayer;

            if (player == null)
            {
                return;
            }

            BlockReinforcement bre = modBre.GetReinforcment(blockSel.Position);

            string errorCode = "";

            if (!modBre.TryRemoveReinforcement(blockSel.Position, player, ref errorCode))
            {
                if (errorCode == "notownblock")
                {
                    player.SendIngameError("cantremove", "Cannot remove reinforcement. This block does not belong to you");
                }
                else
                {
                    player.SendIngameError("cantremove", "Cannot remove reinforcement. It's not reinforced");
                }

                return;
            }
            else
            {
                if (bre.Locked)
                {
                    ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation(bre.LockedByItemCode)));
                    if (!player.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        byEntity.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ);
                    }
                }
            }

            BlockPos pos = blockSel.Position;

            byEntity.World.PlaySoundAt(new AssetLocation("sounds/tool/reinforce"), pos.X, pos.Y, pos.Z, null);

            handling = EnumHandHandling.PreventDefaultAction;
        }
        public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode)
        {
            EntityPlayer entityPlayer = byEntity as EntityPlayer;

            if (entityPlayer != null)
            {
                IPlayer byPlayer = World.PlayerByUid(entityPlayer.PlayerUID);
                if (byPlayer != null)
                {
                    if (!CanCollect(byPlayer))
                    {
                        IServerPlayer sp = byPlayer as IServerPlayer;
                        if (sp != null)
                        {
                            sp.SendIngameError("", Lang.Get("game:ingameerror-not-corpse-owner"));
                        }
                    }
                    else
                    {
                        if (Api.Side == EnumAppSide.Server)
                        {
                            if (Inventory == null || Inventory.Count == 0)
                            {
                                string format = "{0} at {1} is empty and will be removed immediately, id {3}";
                                string msg    = string.Format(format, GetName(), SidedPos.XYZ.RelativePos(Api), byPlayer.PlayerName, EntityId);
                                Core.ModLogger.Notification(msg);
                                Die();
                            }
                            else if (SecondsPassed > Config.Current.CorpseCollectionTime.Value)
                            {
                                Collect(byPlayer);
                            }
                        }

                        LastInteractPassedMs = World.ElapsedMilliseconds;
                        return;
                    }
                }
            }

            base.OnInteract(byEntity, itemslot, hitPosition, mode);
        }