public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer, ref EnumHandling handled)
 {
     if (!block.Code.Path.Contains("log-grown-pine-"))
     {
         return(null);
     }
     return(interactions);
 }
Exemple #2
0
 public virtual void DidAttack(DamageSource source, EntityAgent targetEntity, ref EnumHandling handled)
 {
     handled = EnumHandling.PassThrough;
 }
        public override void OnNeighourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos, ref EnumHandling handled)
        {
            handled = EnumHandling.NotHandled;

            if (IsSurroundedByNonSolid(world, pos))
            {
                world.BlockAccessor.BreakBlock(pos, null);
            }
            base.OnNeighourBlockChange(world, pos, neibpos, ref handled);
        }
Exemple #4
0
 /// <summary>
 /// The event fired when the entity is interacted with by the player.
 /// </summary>
 /// <param name="byEntity">The entity it was interacted with.</param>
 /// <param name="itemslot">The item slot involved (if any)</param>
 /// <param name="hitPosition">The hit position of the entity.</param>
 /// <param name="mode">The interaction mode for the entity.</param>
 /// <param name="handled">How this event is handled.</param>
 public virtual void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
 {
 }
Exemple #5
0
 /// <summary>
 /// The event fired when the client receives a packet.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="packetid"></param>
 /// <param name="data"></param>
 /// <param name="handled"></param>
 public virtual void OnReceivedServerPacket(int packetid, byte[] data, ref EnumHandling handled)
 {
 }
 public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handled)
 {
     handled = EnumHandling.PreventSubsequent;
     return(false);
 }
Exemple #7
0
        /// <summary>
        /// gets the drops for this specific entity.
        /// </summary>
        /// <param name="world">The world of this entity</param>
        /// <param name="pos">The block position of the entity.</param>
        /// <param name="byPlayer">The player this entity was killed by.</param>
        /// <param name="handling">How this event was handled.</param>
        /// <returns>the items dropped from this entity</returns>
        public virtual ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            handling = EnumHandling.PassThrough;

            return(null);
        }
 public override void OnStateChanged(EnumEntityState beforeState, ref EnumHandling handled)
 {
     taskManager.OnStateChanged(beforeState);
 }
        public override void OnTryIgniteBlockOver(EntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            if (IsExtinct)
            {
                handling = EnumHandling.PreventDefault;
                AssetLocation loc   = new AssetLocation(FirstCodePart() + "-" + Variant["orientation"]);
                Block         block = api.World.BlockAccessor.GetBlock(loc);
                if (block != null)
                {
                    api.World.BlockAccessor.SetBlock(block.Id, pos);
                }

                return;
            }
        }
Exemple #10
0
        public override void OnNeighbourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;
            if (pos.Y == neibpos.Y - 1 || pos.Y == neibpos.Y + 1 || IsLantern(world, neibpos))
            {
                return;
            }

            world.BlockAccessor.ExchangeBlock(world.BlockAccessor.GetBlock(block.CodeWithParts(getCode(world, pos))).BlockId, pos);
        }
Exemple #11
0
        public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropChanceMultiplier, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;
            Block block = world.BlockAccessor.GetBlock(this.block.CodeWithParts("e"));

            return(new ItemStack[] { new ItemStack(block) });
        }
Exemple #12
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
        {
            handling = EnumHandling.PreventDefault;
            if (!world.BlockAccessor.GetBlock(blockSel.Position).IsReplacableBy(block))
            {
                return(false);
            }

            var code = getCode(world, blockSel.Position);

            world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(block.CodeWithParts(code)).BlockId, blockSel.Position);
            return(true);
        }
Exemple #13
0
 public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
 {
     handling    = EnumHandling.PreventSubsequent;
     failureCode = "__ignore__";
     return(false);
 }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
            {
                return(false);
            }

            if (!block.Code.Path.Contains("log-grown-pine-"))
            {
                return(false);
            }

            handling = EnumHandling.PreventDefault;

            world.PlaySoundAt(scoringSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            return(true);
        }
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos, ref EnumHandling handled)
        {
            handled = EnumHandling.PreventDefault;

            return(new ItemStack(world.BlockAccessor.GetBlock(block.CodeWithParts(dropBlockFace))));
        }
Exemple #16
0
        /// <summary>Creates a <see cref="JsonObjectTypeDescription"/> from a <see cref="Type"/>. </summary>
        /// <param name="type">The type. </param>
        /// <param name="parentAttributes">The parent's attributes (i.e. parameter or property attributes).</param>
        /// <param name="defaultEnumHandling">The default enum handling.</param>
        /// <returns>The <see cref="JsonObjectTypeDescription"/>. </returns>
        public static JsonObjectTypeDescription FromType(Type type, IEnumerable <Attribute> parentAttributes, EnumHandling defaultEnumHandling)
        {
            if (type.GetTypeInfo().IsEnum)
            {
                var isStringEnum =
                    HasStringEnumConverter(type.GetTypeInfo().GetCustomAttributes()) ||
                    (parentAttributes != null && HasStringEnumConverter(parentAttributes)) ||
                    defaultEnumHandling == EnumHandling.String;

                return(new JsonObjectTypeDescription(isStringEnum ? JsonObjectType.String : JsonObjectType.Integer, true)
                {
                    IsEnum = true
                });
            }

            if (type == typeof(int) || type == typeof(short) || type == typeof(uint) || type == typeof(ushort))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Integer, true));
            }

            if ((type == typeof(long)) || (type == typeof(ulong)))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Integer, true, false, JsonFormatStrings.Long));
            }

            if (type == typeof(double) || type == typeof(float))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Number, true, false, JsonFormatStrings.Double));
            }

            if (type == typeof(decimal))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Number, true, false, JsonFormatStrings.Decimal));
            }

            if (type == typeof(bool))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Boolean, true));
            }

            if (type == typeof(string) || type == typeof(Type))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, false));
            }

            if (type == typeof(char))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, true));
            }

            if (type == typeof(Guid))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, true, false, JsonFormatStrings.Guid));
            }

            if (type == typeof(DateTime) || type == typeof(DateTimeOffset))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, true, false, JsonFormatStrings.DateTime));
            }

            if (type == typeof(TimeSpan))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, true, false, JsonFormatStrings.TimeSpan));
            }

            if (type == typeof(Uri))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, true, false, JsonFormatStrings.Uri));
            }

            if (type == typeof(byte))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Integer, true, false, JsonFormatStrings.Byte));
            }

            if (type == typeof(byte[]))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.String, false, false, JsonFormatStrings.Byte));
            }

            if (type == typeof(JObject) || type == typeof(object))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Object, false, true));
            }

            if (IsFileType(type))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.File, false));
            }

            if (IsDictionaryType(type))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Object, false, true));
            }

            if (IsArrayType(type))
            {
                return(new JsonObjectTypeDescription(JsonObjectType.Array, false));
            }

            if (type.Name == "Nullable`1")
            {
                var typeDescription = FromType(type.GenericTypeArguments[0], parentAttributes, defaultEnumHandling);
                typeDescription.IsAlwaysRequired = false;
                return(typeDescription);
            }

            var jsonSchemaAttribute = type.GetTypeInfo().GetCustomAttribute <JsonSchemaAttribute>();

            if (jsonSchemaAttribute != null)
            {
                var classType = jsonSchemaAttribute.Type != JsonObjectType.None ? jsonSchemaAttribute.Type : JsonObjectType.Object;
                var format    = !string.IsNullOrEmpty(jsonSchemaAttribute.Format) ? jsonSchemaAttribute.Format : null;
                return(new JsonObjectTypeDescription(classType, false, false, format));
            }

            return(new JsonObjectTypeDescription(JsonObjectType.Object, false));
        }
Exemple #17
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            if (byPlayer == null)
            {
                return;                    // Fast return path for no player (although normally OnBlockBroken will specify a player)
            }
            ModSystemBlockReinforcement modBre;

            modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
            BlockReinforcement bre = modBre.GetReinforcment(pos);

            if (bre != null && bre.Strength > 0)
            {
                handling = EnumHandling.PreventDefault;   // This prevents the block from breaking normally, while it any amount of reinforcement left

                world.PlaySoundAt(new AssetLocation("sounds/tool/breakreinforced"), pos.X, pos.Y, pos.Z, byPlayer);

                if (!byPlayer.HasPrivilege("denybreakreinforced"))
                {
                    modBre.ConsumeStrength(pos, 1);

                    world.BlockAccessor.MarkBlockDirty(pos);
                }
            }
        }
        public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
        {
            bool inRange = (byEntity.World.Side == EnumAppSide.Client && byEntity.Pos.SquareDistanceTo(entity.Pos) <= 5) || (byEntity.World.Side == EnumAppSide.Server && byEntity.Pos.SquareDistanceTo(entity.Pos) <= 14);

            if (!IsHarvested || !inRange)
            {
                return;
            }

            EntityPlayer entityplr = byEntity as EntityPlayer;
            IPlayer      player    = entity.World.PlayerByUid(entityplr.PlayerUID);

            player.InventoryManager.OpenInventory(inv);



            if (entity.World.Side == EnumAppSide.Client && dlg == null)
            {
                dlg = new GuiDialogCarcassContents(inv, entity as EntityAgent, entity.Api as ICoreClientAPI);
                if (dlg.TryOpen())
                {
                    (entity.World.Api as ICoreClientAPI).Network.SendPacketClient(inv.Open(player));
                }

                dlg.OnClosed += () => dlg = null;
            }
        }
Exemple #19
0
 /// <summary>
 /// The event fired when the server position is changed.
 /// </summary>
 /// <param name="isTeleport">Whether or not this entity was teleported.</param>
 /// <param name="handled">How this event is handled.</param>
 public virtual void OnReceivedServerPos(bool isTeleport, ref EnumHandling handled)
 {
 }
        public override void OnReceivedClientPacket(IServerPlayer player, int packetid, byte[] data, ref EnumHandling handled)
        {
            if (packetid < 1000)
            {
                inv.InvNetworkUtil.HandleClientPacket(player, packetid, data);
                handled = EnumHandling.PreventSubsequent;
                return;
            }

            if (packetid == 1012)
            {
                if (!IsHarvested)
                {
                    entity.WatchedAttributes.MarkPathDirty("harvested");
                }
                else
                {
                    player.InventoryManager.OpenInventory(inv);
                }
            }
        }
Exemple #21
0
 /// <summary>
 /// The event fired when the state of the entity is changed.
 /// </summary>
 /// <param name="beforeState">The previous state.</param>
 /// <param name="handling">How this event was handled.</param>
 public virtual void OnStateChanged(EnumEntityState beforeState, ref EnumHandling handling)
 {
 }
        public override WorldInteraction[] GetInteractionHelp(IClientWorldAccessor world, EntitySelection es, IClientPlayer player, ref EnumHandling handled)
        {
            interactions = ObjectCacheUtil.GetOrCreate(world.Api, "harvestableEntityInteractions", () =>
            {
                List <ItemStack> knifeStacklist = new List <ItemStack>();

                foreach (Item item in world.Items)
                {
                    if (item.Code == null)
                    {
                        continue;
                    }

                    if (item.Tool == EnumTool.Knife)
                    {
                        knifeStacklist.Add(new ItemStack(item));
                    }
                }

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-creature-harvest",
                        MouseButton = EnumMouseButton.Right,
                        HotKeyCode = "sneak",
                        Itemstacks = knifeStacklist.ToArray()
                    }
                });
            });

            return(!entity.Alive && !IsHarvested ? interactions : null);
        }
Exemple #23
0
 /// <summary>
 /// The event fired when the server receives a packet.
 /// </summary>
 /// <param name="player">The server player.</param>
 /// <param name="packetid">the packet id.</param>
 /// <param name="data">The data contents.</param>
 /// <param name="handled">How this event is handled.</param>
 public virtual void OnReceivedClientPacket(IServerPlayer player, int packetid, byte[] data, ref EnumHandling handled)
 {
 }
        public override void OnNeighourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos, ref EnumHandling handling)
        {
            if (!HasSupport(block, world.BlockAccessor, pos))
            {
                handling = EnumHandling.PreventSubsequent;
                world.BlockAccessor.BreakBlock(pos, null);
                world.BlockAccessor.TriggerNeighbourBlockUpdate(pos);
                return;
            }

            base.OnNeighourBlockChange(world, pos, neibpos, ref handling);
        }
Exemple #25
0
 /// <summary>
 /// Called when a player looks at the entity with interaction help enabled
 /// </summary>
 /// <param name="world"></param>
 /// <param name="es"></param>
 /// <param name="player"></param>
 /// <param name="handled"></param>
 public virtual WorldInteraction[] GetInteractionHelp(IClientWorldAccessor world, EntitySelection es, IClientPlayer player, ref EnumHandling handled)
 {
     handled = EnumHandling.PassThrough;
     return(null);
 }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;
            BlockPos pos        = blockSel.Position;
            Block    blockAtPos = world.BlockAccessor.GetBlock(pos);

            BlockPos aimedAtPos   = blockSel.DidOffset ? pos.AddCopy(blockSel.Face.GetOpposite()) : blockSel.Position;
            Block    aimedAtBlock = blockSel.DidOffset ? world.BlockAccessor.GetBlock(pos.AddCopy(blockSel.Face.GetOpposite())) : blockAtPos;

            BlockFacing[] horVer    = Block.SuggestedHVOrientation(byPlayer, blockSel);
            AssetLocation blockCode = block.CodeWithParts(horVer[0].Code);


            // Has ladder above at aimed position?
            Block aboveBlock = world.BlockAccessor.GetBlock(pos.X, pos.Y + 1, pos.Z);

            if (aboveBlock.FirstCodePart() == ownFirstCodePart && HasSupport(aboveBlock, world.BlockAccessor, pos) && aboveBlock.IsSuitablePosition(world, pos))
            {
                aboveBlock.DoPlaceBlock(world, pos, blockSel.Face, itemstack);
                return(true);
            }

            // Has ladder below  at aimed position?
            Block belowBlock = world.BlockAccessor.GetBlock(pos.X, pos.Y - 1, pos.Z);

            if (belowBlock.FirstCodePart() == ownFirstCodePart && HasSupport(belowBlock, world.BlockAccessor, pos) && belowBlock.IsSuitablePosition(world, pos))
            {
                belowBlock.DoPlaceBlock(world, pos, blockSel.Face, itemstack);
                return(true);
            }


            // Can I put ladder below aimed position?
            if (blockSel.HitPosition.Y < 0.5)
            {
                if (TryStackDown(byPlayer, world, aimedAtPos, blockSel.Face, itemstack))
                {
                    return(true);
                }
            }


            // Can I put ladder above aimed position?
            if (TryStackUp(byPlayer, world, aimedAtPos, blockSel.Face, itemstack))
            {
                return(true);
            }

            // Can I put ladder below aimed position?
            if (TryStackDown(byPlayer, world, aimedAtPos, blockSel.Face, itemstack))
            {
                return(true);
            }



            Block orientedBlock = world.BlockAccessor.GetBlock(blockCode);

            // Otherwise place if we have support for it
            if (HasSupport(orientedBlock, world.BlockAccessor, pos) && orientedBlock.IsSuitablePosition(world, pos))
            {
                orientedBlock.DoPlaceBlock(world, pos, blockSel.Face, itemstack);
                return(true);
            }


            // Otherwise maybe on the other side?
            blockCode     = block.CodeWithParts(blockSel.Face.GetOpposite().Code);
            orientedBlock = world.BlockAccessor.GetBlock(blockCode);
            if (orientedBlock != null && HasSupport(orientedBlock, world.BlockAccessor, pos) && orientedBlock.IsSuitablePosition(world, pos))
            {
                orientedBlock.DoPlaceBlock(world, pos, blockSel.Face, itemstack);
                return(true);
            }


            return(false);
        }
Exemple #27
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                handling    = EnumHandling.PreventDefault;
                failureCode = "onlywhensneaking";
                return(false);
            }

            return(base.TryPlaceBlock(world, byPlayer, itemstack, blockSel, ref handling, ref failureCode));
        }
 public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier, ref EnumHandling handled)
 {
     handled = EnumHandling.PreventDefault;
     return(new ItemStack[] { new ItemStack(world.BlockAccessor.GetBlock(block.CodeWithParts(dropBlockFace))) });
 }
 public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier, ref EnumHandling handled)
 {
     if (IsSurroundedByNonSolid(world, pos))
     {
         handled = EnumHandling.PreventSubsequent;
         return(new ItemStack[] { new ItemStack(block) });
     }
     else
     {
         handled = EnumHandling.NotHandled;
         return(null);
     }
 }
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handled)
        {
            handled = EnumHandling.PreventDefault;


            if (secondsUsed > scoreTime - 0.05f && world.Side == EnumAppSide.Server)
            {
                if (scoredBlock != null)
                {
                    world.BlockAccessor.SetBlock(scoredBlock.BlockId, blockSel.Position);
                }

                world.PlaySoundAt(scoringSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            }
        }