Esempio n. 1
0
        /// <summary> Removes the <see cref="CarriedBlock"/>
        ///           carried by the specified entity in that slot. </summary>
        /// <example cref="ArgumentNullException"> Thrown if entity is null. </exception>
        public static void Remove(Entity entity, CarrySlot slot)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var animation = entity.GetCarried(slot)?.Behavior?.Slots?[slot]?.Animation;

            if (animation != null)
            {
                entity.StopAnimation(animation);
            }

            if (entity is EntityAgent agent)
            {
                agent.Stats.Remove("walkspeed", $"{ CarrySystem.MOD_ID }:{ slot }");

                if (slot == CarrySlot.Hands)
                {
                    LockedItemSlot.Restore(agent.RightHandItemSlot);
                }
                if (slot != CarrySlot.Back)
                {
                    LockedItemSlot.Restore(agent.LeftHandItemSlot);
                }
                CarryHandler.SendLockSlotsMessage(agent as EntityPlayer);
            }

            entity.WatchedAttributes.Remove(ATTRIBUTE_ID, slot.ToString());
            ((SyncedTreeAttribute)entity.WatchedAttributes).MarkPathDirty(ATTRIBUTE_ID);
            entity.Attributes.Remove(ATTRIBUTE_ID, slot.ToString());
        }
Esempio n. 2
0
        /// <summary> Stores the specified stack and blockEntityData (may be null)
        ///           as the <see cref="CarriedBlock"/> of the entity in that slot. </summary>
        /// <example cref="ArgumentNullException"> Thrown if entity is null. </exception>
        public static void Set(Entity entity, CarrySlot slot, ItemStack stack, ITreeAttribute blockEntityData)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            entity.WatchedAttributes.Set(stack, ATTRIBUTE_ID, slot.ToString(), "Stack");
            ((SyncedTreeAttribute)entity.WatchedAttributes).MarkPathDirty(ATTRIBUTE_ID);

            if ((entity.World.Side == EnumAppSide.Server) && (blockEntityData != null))
            {
                entity.Attributes.Set(blockEntityData, ATTRIBUTE_ID, slot.ToString(), "Data");
            }

            var behavior     = stack.Block.GetBehaviorOrDefault(BlockBehaviorCarryable.DEFAULT);
            var slotSettings = behavior.Slots[slot];

            if (slotSettings?.Animation != null)
            {
                entity.StartAnimation(slotSettings.Animation);
            }

            if (entity is EntityAgent agent)
            {
                var speed = slotSettings?.WalkSpeedModifier ?? 0.0F;
                if (speed != 0.0F)
                {
                    agent.Stats.Set("walkspeed",
                                    $"{ CarrySystem.MOD_ID }:{ slot }", speed, false);
                }

                if (slot == CarrySlot.Hands)
                {
                    LockedItemSlot.Lock(agent.RightHandItemSlot);
                }
                if (slot != CarrySlot.Back)
                {
                    LockedItemSlot.Lock(agent.LeftHandItemSlot);
                }
                CarryHandler.SendLockSlotsMessage(agent as EntityPlayer);
            }
        }