Example #1
0
        /*public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null)
         * {
         *  BlockEntityChisel bec = blockAccessor.GetBlockEntity(pos) as BlockEntityChisel;
         *  if (bec?.Materials == null)
         *  {
         *      return base.GetLightHsv(blockAccessor, pos, stack);
         *  }
         *
         *  for (int i = 0; i < bec.Materials.Length; i++)
         *  {
         *      Block block = blockAccessor.GetBlock(bec.Materials[i]);
         *      if (block.LightHsv[2] > 0) return block.LightHsv;
         *  }
         *
         *  return base.GetLightHsv(blockAccessor, pos, stack);
         * }
         *
         * public override int GetLightAbsorption(IBlockAccessor blockAccessor, BlockPos pos)
         * {
         *  BlockEntityChisel bec = blockAccessor.GetBlockEntity(pos) as BlockEntityChisel;
         *  if (bec?.Materials == null)
         *  {
         *      return base.GetLightAbsorption(blockAccessor, pos);
         *  }
         *
         *  int absorb = 99;
         *
         *  for (int i = 0; i < bec.Materials.Length; i++)
         *  {
         *      Block block = blockAccessor.GetBlock(bec.Materials[i]);
         *      absorb = Math.Min(absorb, block.LightAbsorption);
         *  }
         *
         *  return base.GetLightAbsorption(blockAccessor, pos);
         * }*/


        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityChisel bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;

            if (bec == null)
            {
                return(null);
            }

            TreeAttribute tree = new TreeAttribute();

            bec.ToTreeAttributes(tree);
            tree.RemoveAttribute("posx");
            tree.RemoveAttribute("posy");
            tree.RemoveAttribute("posz");

            return(new ItemStack(this.Id, EnumItemClass.Block, 1, tree, world));
        }
Example #2
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityMicroBlock bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityMicroBlock;

            if (bec == null)
            {
                return(null);
            }

            TreeAttribute tree = new TreeAttribute();

            bec.ToTreeAttributes(tree);
            tree.RemoveAttribute("posx");
            tree.RemoveAttribute("posy");
            tree.RemoveAttribute("posz");
            tree.RemoveAttribute("snowcuboids");

            return(new ItemStack(notSnowCovered.Id, EnumItemClass.Block, 1, tree, world));
        }
Example #3
0
        //when the player uses the middle button to select a block
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            Block       block = world.BlockAccessor.GetBlock(CodeWithParts("north", "down"));
            BlockEntity bec   = world.BlockAccessor.GetBlockEntity(pos);

            if (bec == null)
            {
                return(null);
            }

            TreeAttribute tree = new TreeAttribute();

            bec.ToTreeAttributes(tree);
            tree.RemoveAttribute("posx");
            tree.RemoveAttribute("posy");
            tree.RemoveAttribute("posz");

            return(new ItemStack(block.Id, EnumItemClass.Block, 1, tree, world));
        }
Example #4
0
        /// <summary> Creates a <see cref="CarriedBlock"/> from the specified world
        ///           and position, but doesn't remove it. Returns null if unsuccessful. </summary>
        /// <example cref="ArgumentNullException"> Thrown if world or pos is null. </exception>
        public static CarriedBlock Get(IWorldAccessor world, BlockPos pos, CarrySlot slot)
        {
            if (world == null)
            {
                throw new ArgumentNullException(nameof(world));
            }
            if (pos == null)
            {
                throw new ArgumentNullException(nameof(pos));
            }

            var block = world.BlockAccessor.GetBlock(pos);

            if (block.Id == 0)
            {
                return(null);                           // Can't pick up air.
            }
            var stack = block.OnPickBlock(world, pos) ?? new ItemStack(block);

            ITreeAttribute blockEntityData = null;

            if (world.Side == EnumAppSide.Server)
            {
                var blockEntity = world.BlockAccessor.GetBlockEntity(pos);
                if (blockEntity != null)
                {
                    blockEntityData = new TreeAttribute();
                    blockEntity.ToTreeAttributes(blockEntityData);
                    blockEntityData = blockEntityData.Clone();
                    // We don't need to keep the position.
                    blockEntityData.RemoveAttribute("posx");
                    blockEntityData.RemoveAttribute("posy");
                    blockEntityData.RemoveAttribute("posz");
                    // And angle needs to be removed, or else it will
                    // override the angle set from block placement.
                    blockEntityData.RemoveAttribute("meshAngle");
                }
            }

            return(new CarriedBlock(slot, stack, blockEntityData));
        }
Example #5
0
        public bool TryTriggerState(string statecode)
        {
            bool triggered = false;

            for (int stateid = 0; stateid < availableStates.Count; stateid++)
            {
                EmotionState newstate = availableStates[stateid];

                if (newstate.Code != statecode || entity.World.Rand.NextDouble() > newstate.Chance)
                {
                    continue;
                }

                if (newstate.whenHealthRelBelow < healthRel)
                {
                    continue;
                }

                float activedur = 0;

                foreach (int activestateid in ActiveStatesById.Keys)
                {
                    if (activestateid == stateid)
                    {
                        activedur = ActiveStatesById[stateid];
                        continue;
                    }

                    EmotionState activestate = availableStates[activestateid];

                    if (activestate.Slot == newstate.Slot)
                    {
                        // Active state has priority over this one
                        if (activestate.Priority > newstate.Priority)
                        {
                            return(false);
                        }
                        else
                        {
                            // New state has priority
                            ActiveStatesById.Remove(activestateid);
                            entityAttrById.RemoveAttribute("" + activestateid);
                            entityAttr.RemoveAttribute(newstate.Code);
                            break;
                        }
                    }
                }

                float newDuration = 0;
                if (newstate.AccumType == EnumAccumType.Sum)
                {
                    newDuration = activedur + newstate.Duration;
                }
                if (newstate.AccumType == EnumAccumType.Max)
                {
                    newDuration = Math.Max(activedur, newstate.Duration);
                }
                if (newstate.AccumType == EnumAccumType.NoAccum)
                {
                    newDuration = activedur > 0 ? activedur : newstate.Duration;
                }

                ActiveStatesById[stateid] = newDuration;
                entityAttrById.SetFloat("" + stateid, newDuration);
                entityAttr.SetFloat(newstate.Code, newDuration);
                triggered = true;
            }

            return(triggered);
        }
Example #6
0
        public bool TryTriggerState(string statecode, double chance)
        {
            bool triggered = false;

            for (int stateid = 0; stateid < availableStates.Count; stateid++)
            {
                EmotionState newstate = availableStates[stateid];

                if (newstate.Code != statecode || chance > newstate.Chance)
                {
                    continue;
                }

                if (newstate.whenHealthRelBelow < healthRel)
                {
                    continue;
                }

                float activedur = 0;

                foreach (int activestateid in ActiveStatesById.Keys)
                {
                    if (activestateid == stateid)
                    {
                        activedur = ActiveStatesById[stateid];
                        continue;
                    }

                    EmotionState activestate = availableStates[activestateid];

                    if (activestate.Slot == newstate.Slot)
                    {
                        // Active state has priority over this one
                        if (activestate.Priority > newstate.Priority)
                        {
                            return(false);
                        }
                        else
                        {
                            // New state has priority
                            ActiveStatesById.Remove(activestateid);
                            entityAttrById.RemoveAttribute("" + activestateid);
                            entityAttr.RemoveAttribute(newstate.Code);
                            break;
                        }
                    }
                }

                float duration = newstate.Duration;
                if (newstate.BelowTempThreshold > -99 && entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues).Temperature < newstate.BelowTempDuration)
                {
                    duration = newstate.BelowTempDuration;
                }

                float newDuration = 0;
                if (newstate.AccumType == EnumAccumType.Sum)
                {
                    newDuration = activedur + duration;
                }
                if (newstate.AccumType == EnumAccumType.Max)
                {
                    newDuration = Math.Max(activedur, duration);
                }
                if (newstate.AccumType == EnumAccumType.NoAccum)
                {
                    newDuration = activedur > 0 ? activedur : duration;
                }

                ActiveStatesById[stateid] = newDuration;
                entityAttrById.SetFloat("" + stateid, newDuration);
                entityAttr.SetFloat(newstate.Code, newDuration);
                triggered = true;
            }

            return(triggered);
        }
        public bool TryTriggerState(string statecode, double chance, long sourceEntityId)
        {
            bool triggered = false;

            for (int stateid = 0; stateid < availableStates.Length; stateid++)
            {
                EmotionState newstate = availableStates[stateid];

                if (newstate.Code != statecode || chance > newstate.Chance)
                {
                    continue;
                }

                if (newstate.whenHealthRelBelow < healthRel)
                {
                    continue;
                }

                ActiveEmoState activeState = null;

                foreach (var val in ActiveStatesByCode)
                {
                    if (val.Key == newstate.Code)
                    {
                        activeState = val.Value;
                        continue;
                    }

                    int          activestateid = val.Value.StateId;
                    EmotionState activestate   = availableStates[activestateid];
                    if (activestate.Slot == newstate.Slot)
                    {
                        // Active state has priority over this one
                        if (activestate.Priority > newstate.Priority)
                        {
                            return(false);
                        }
                        else
                        {
                            // New state has priority
                            ActiveStatesByCode.Remove(val.Key);

                            entityAttr.RemoveAttribute(newstate.Code);
                            break;
                        }
                    }
                }

                float duration = newstate.Duration;
                if (newstate.BelowTempThreshold > -99 && entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues).Temperature < newstate.BelowTempDuration)
                {
                    duration = newstate.BelowTempDuration;
                }

                float newDuration = 0;
                if (newstate.AccumType == EnumAccumType.Sum)
                {
                    newDuration = activeState?.Duration ?? 0 + duration;
                }
                if (newstate.AccumType == EnumAccumType.Max)
                {
                    newDuration = Math.Max(activeState?.Duration ?? 0, duration);
                }
                if (newstate.AccumType == EnumAccumType.NoAccum)
                {
                    newDuration = activeState?.Duration > 0 ? activeState?.Duration ?? 0 : duration;
                }

                if (activeState == null)
                {
                    ActiveStatesByCode[newstate.Code] = new ActiveEmoState()
                    {
                        Duration = newDuration, SourceEntityId = sourceEntityId, StateId = stateid
                    };
                }
                else
                {
                    activeState.SourceEntityId = sourceEntityId;
                }


                entityAttr.SetFloat(newstate.Code, newDuration);
                triggered = true;
            }

            return(triggered);
        }
Example #8
0
        public bool TryTriggerState(string statecode)
        {
            EmotionState newstate;

            if (!availableStates.TryGetValue(statecode, out newstate))
            {
                return(false);
            }
            if (entity.World.Rand.NextDouble() > newstate.Chance)
            {
                return(false);
            }

            float activedur = 0;

            foreach (string activestatecode in activeStates.Keys)
            {
                if (activestatecode == statecode)
                {
                    activedur = activeStates[activestatecode];
                    continue;
                }

                EmotionState activestate = availableStates[activestatecode];

                if (activestate.Slot == newstate.Slot)
                {
                    // Active state has priority over this one
                    if (activestate.Priority > newstate.Priority)
                    {
                        return(false);
                    }
                    else
                    {
                        // New state has priority
                        activeStates.Remove(activestatecode);
                        entityAttr.RemoveAttribute(activestatecode);
                        break;
                    }
                }
            }

            float newDuration = 0;

            if (newstate.AccumType == EnumAccumType.Sum)
            {
                newDuration = activedur + newstate.Duration;
            }
            if (newstate.AccumType == EnumAccumType.Max)
            {
                newDuration = Math.Max(activedur, newstate.Duration);
            }
            if (newstate.AccumType == EnumAccumType.NoAccum)
            {
                newDuration = activedur > 0 ? activedur : newstate.Duration;
            }

            activeStates[statecode] = newDuration;
            entityAttr.SetFloat(statecode, newDuration);

            return(true);
        }