Example #1
0
 public void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
 {
     Type              = (EnumTransitionType)reader.ReadUInt16();
     FreshHours        = NatFloat.createFromBytes(reader);
     TransitionHours   = NatFloat.createFromBytes(reader);
     TransitionedStack = new JsonItemStack();
     TransitionedStack.FromBytes(reader, instancer);
     TransitionRatio = reader.ReadSingle();
 }
Example #2
0
        /// <summary>
        /// Loads the ItemStack from the reader.
        /// </summary>
        /// <param name="reader">The reader to get the ItemStack from</param>
        /// <param name="instancer">The instancer for the ItemStack.</param>
        public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
        {
            Type      = (EnumItemClass)reader.ReadInt16();
            Code      = new AssetLocation(reader.ReadString());
            StackSize = reader.ReadInt32();

            if (reader.ReadBoolean())
            {
                ResolvedItemstack = new ItemStack(reader);
            }
        }
Example #3
0
 /// <summary>
 /// Reads the contents of the block bytes and converts it into a block.
 /// </summary>
 /// <param name="reader">The reader of the block</param>
 /// <param name="instancer">The block registry</param>
 public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
 {
     Type     = (EnumItemClass)reader.ReadInt16();
     Code     = new AssetLocation(reader.ReadString());
     Quantity = NatFloat.One;
     Quantity.FromBytes(reader);
     ResolvedItemstack = new ItemStack(reader);
     LastDrop          = reader.ReadBoolean();
     if (reader.ReadBoolean())
     {
         DropModbyStat = reader.ReadString();
     }
 }
        /// <summary>
        /// Writes all the data to the BinaryWriter.
        /// </summary>
        /// <param name="writer">The writer to write the save data</param>
        /// <param name="registry">The registry of blocks and items.</param>
        public void ToBytes(BinaryWriter writer, IClassRegistryAPI registry)
        {
            writer.Write(Tabs.Length);
            for (int i = 0; i < Tabs.Length; i++)
            {
                writer.Write(Tabs[i]);
            }

            writer.Write(Stacks.Length);
            for (int i = 0; i < Stacks.Length; i++)
            {
                Stacks[i].ToBytes(writer);
            }
        }
        /// <summary>
        /// Reads the blocks and items from the Json files and converts them to an array of tabs which contain those blocks and items.
        /// </summary>
        /// <param name="reader">The reader to read the json.</param>
        /// <param name="registry">The registry of blocks and items.</param>
        public void FromBytes(BinaryReader reader, IClassRegistryAPI registry)
        {
            Tabs = new string[reader.ReadInt32()];
            for (int i = 0; i < Tabs.Length; i++)
            {
                Tabs[i] = reader.ReadString();
            }

            Stacks = new JsonItemStack[reader.ReadInt32()];
            for (int i = 0; i < Stacks.Length; i++)
            {
                Stacks[i] = new JsonItemStack();
                Stacks[i].FromBytes(reader, registry);
            }
        }
Example #6
0
        public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
        {
            Code              = reader.ReadString();
            MinQuantity       = reader.ReadInt32();
            MaxQuantity       = reader.ReadInt32();
            PortionSizeLitres = reader.ReadSingle();

            int q = reader.ReadInt32();

            ValidStacks = new CookingRecipeStack[q];
            for (int i = 0; i < q; i++)
            {
                ValidStacks[i] = new CookingRecipeStack();
                ValidStacks[i].FromBytes(reader, instancer);
            }
        }
Example #7
0
        public void InitItem(IClassRegistryAPI instancer, ILogger logger, Item item, OrderedDictionary <string, string> searchReplace)
        {
            item.CreativeInventoryTabs = BlockType.GetCreativeTabs(item.Code, CreativeInventory, searchReplace);


            CollectibleBehaviorType[] behaviorTypes = Behaviors;

            if (behaviorTypes != null)
            {
                List <CollectibleBehavior> collbehaviors = new List <CollectibleBehavior>();

                for (int i = 0; i < behaviorTypes.Length; i++)
                {
                    CollectibleBehaviorType behaviorType = behaviorTypes[i];
                    CollectibleBehavior     behavior;

                    if (instancer.GetCollectibleBehaviorClass(behaviorType.name) != null)
                    {
                        behavior = instancer.CreateCollectibleBehavior(item, behaviorType.name);
                    }
                    else
                    {
                        logger.Warning(Lang.Get("Collectible behavior {0} for item {1} not found", behaviorType.name, item.Code));
                        continue;
                    }

                    if (behaviorType.properties == null)
                    {
                        behaviorType.properties = new JsonObject(new JObject());
                    }

                    try
                    {
                        behavior.Initialize(behaviorType.properties);
                    }
                    catch (Exception e)
                    {
                        logger.Error("Failed calling Initialize() on collectible behavior {0} for item {1}, using properties {2}. Will continue anyway. Exception: {3}", behaviorType.name, item.Code, behaviorType.properties.ToString(), e);
                    }

                    collbehaviors.Add(behavior);
                }

                item.CollectibleBehaviors = collbehaviors.ToArray();
            }
        }
Example #8
0
        public override void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
        {
            base.FromBytes(reader, instancer);

            if (!reader.ReadBoolean())
            {
                ShapeElement = reader.ReadString();
            }

            if (!reader.ReadBoolean())
            {
                TextureMapping = new string[] { reader.ReadString(), reader.ReadString() };
            }

            if (!reader.ReadBoolean())
            {
                CookedStack = new JsonItemStack();
                CookedStack.FromBytes(reader, instancer);
            }
        }
Example #9
0
 public void InitItem(IClassRegistryAPI instancer, Item item, Dictionary <string, string> searchReplace)
 {
     item.CreativeInventoryTabs = BlockType.GetCreativeTabs(item.Code, CreativeInventory, searchReplace);
 }
Example #10
0
        public void InitBlock(IClassRegistryAPI instancer, ILogger logger, Block block, OrderedDictionary <string, string> searchReplace)
        {
            BlockBehaviorType[] behaviorTypes = Behaviors;

            if (behaviorTypes != null)
            {
                List <BlockBehavior> behaviors = new List <BlockBehavior>();

                for (int i = 0; i < behaviorTypes.Length; i++)
                {
                    BlockBehaviorType behaviorType = behaviorTypes[i];

                    if (instancer.GetBlockBehaviorClass(behaviorType.name) == null)
                    {
                        logger.Warning(Lang.Get("Block behavior {0} for block {1} not found", behaviorType.name, block.Code));
                        continue;
                    }

                    BlockBehavior behavior = instancer.CreateBlockBehavior(block, behaviorType.name);
                    if (behaviorType.properties == null)
                    {
                        behaviorType.properties = new JsonObject(new JObject());
                    }

                    try
                    {
                        behavior.Initialize(behaviorType.properties);
                    } catch (Exception e)
                    {
                        logger.Error("Failed calling Initialize() on block behavior {0} for block {1}, using properties {2}. Will continue anyway. Exception: {3}", behaviorType.name, block.Code, behaviorType.properties.ToString(), e);
                    }

                    behavior.properties = behaviorType.properties;

                    behaviors.Add(behavior);
                }

                block.BlockBehaviors = behaviors.ToArray();
            }

            if (CropProps != null)
            {
                block.CropProps = new BlockCropProperties();
                block.CropProps.GrowthStages           = CropProps.GrowthStages;
                block.CropProps.HarvestGrowthStageLoss = CropProps.HarvestGrowthStageLoss;
                block.CropProps.MultipleHarvests       = CropProps.MultipleHarvests;
                block.CropProps.NutrientConsumption    = CropProps.NutrientConsumption;
                block.CropProps.RequiredNutrient       = CropProps.RequiredNutrient;
                block.CropProps.TotalGrowthDays        = CropProps.TotalGrowthDays;

                block.CropProps.ColdDamageBelow      = CropProps.ColdDamageBelow;
                block.CropProps.HeatDamageAbove      = CropProps.HeatDamageAbove;
                block.CropProps.DamageGrowthStuntMul = CropProps.DamageGrowthStuntMul;
                block.CropProps.ColdDamageRipeMul    = CropProps.ColdDamageRipeMul;


                if (CropProps.Behaviors != null)
                {
                    block.CropProps.Behaviors = new CropBehavior[CropProps.Behaviors.Length];
                    for (int i = 0; i < CropProps.Behaviors.Length; i++)
                    {
                        CropBehaviorType behaviorType = CropProps.Behaviors[i];
                        CropBehavior     behavior     = instancer.CreateCropBehavior(block, behaviorType.name);
                        if (behaviorType.properties != null)
                        {
                            behavior.Initialize(behaviorType.properties);
                        }
                        block.CropProps.Behaviors[i] = behavior;
                    }
                }
            }

            if (block.Drops == null)
            {
                block.Drops = new BlockDropItemStack[] { new BlockDropItemStack()
                                                         {
                                                             Code     = block.Code,
                                                             Type     = EnumItemClass.Block,
                                                             Quantity = NatFloat.One
                                                         } };
            }

            block.CreativeInventoryTabs = GetCreativeTabs(block.Code, CreativeInventory, searchReplace);

            foreach (BlockFacing facing in BlockFacing.ALLFACES)
            {
                if (SideAo != null && SideAo.ContainsKey(facing.Code))
                {
                    block.SideAo[facing.Index] = SideAo[facing.Code];
                }

                if (EmitSideAo != null && EmitSideAo.ContainsKey(facing.Code))
                {
                    block.EmitSideAo[facing.Index] = EmitSideAo[facing.Code];
                }

                if (SideSolid != null && SideSolid.ContainsKey(facing.Code))
                {
                    block.SideSolid[facing.Index] = SideSolid[facing.Code];
                }

                if (SideOpaque != null && SideOpaque.ContainsKey(facing.Code))
                {
                    block.SideOpaque[facing.Index] = SideOpaque[facing.Code];
                }
            }

            List <string> toRemove = new List <string>();
            int           j        = 0;

            foreach (var val in Textures)
            {
                if (val.Value.Base == null)
                {
                    logger.Error("The texture definition #{0} in block with code {1} is invalid. The base property is null. Will skip.", j, block.Code);
                    toRemove.Add(val.Key);
                }
                j++;
            }

            foreach (var val in toRemove)
            {
                Textures.Remove(val);
            }
        }
Example #11
0
 public override void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
 {
     base.FromBytes(reader, instancer);
     MinRatio = reader.ReadSingle();
     MaxRatio = reader.ReadSingle();
 }
Example #12
0
        public void InitBlock(IClassRegistryAPI instancer, ILogger logger, Block block, OrderedDictionary <string, string> searchReplace)
        {
            CollectibleBehaviorType[] behaviorTypes = Behaviors;

            if (behaviorTypes != null)
            {
                List <BlockBehavior>       blockbehaviors = new List <BlockBehavior>();
                List <CollectibleBehavior> collbehaviors  = new List <CollectibleBehavior>();

                for (int i = 0; i < behaviorTypes.Length; i++)
                {
                    CollectibleBehaviorType behaviorType = behaviorTypes[i];
                    CollectibleBehavior     behavior     = null;

                    if (instancer.GetCollectibleBehaviorClass(behaviorType.name) != null)
                    {
                        behavior = instancer.CreateCollectibleBehavior(block, behaviorType.name);
                    }

                    if (instancer.GetBlockBehaviorClass(behaviorType.name) != null)
                    {
                        behavior = instancer.CreateBlockBehavior(block, behaviorType.name);
                    }

                    if (behavior == null)
                    {
                        logger.Warning(Lang.Get("Block or Collectible behavior {0} for block {1} not found", behaviorType.name, block.Code));
                        continue;
                    }

                    if (behaviorType.properties == null)
                    {
                        behaviorType.properties = new JsonObject(new JObject());
                    }

                    try
                    {
                        behavior.Initialize(behaviorType.properties);
                    } catch (Exception e)
                    {
                        logger.Error("Failed calling Initialize() on collectible or block behavior {0} for block {1}, using properties {2}. Will continue anyway. Exception: {3}", behaviorType.name, block.Code, behaviorType.properties.ToString(), e);
                    }

                    collbehaviors.Add(behavior);
                    if (behavior is BlockBehavior bbh)
                    {
                        blockbehaviors.Add(bbh);
                    }
                }

                block.BlockBehaviors       = blockbehaviors.ToArray();
                block.CollectibleBehaviors = collbehaviors.ToArray();
            }

            if (CropProps != null)
            {
                block.CropProps = new BlockCropProperties();
                block.CropProps.GrowthStages           = CropProps.GrowthStages;
                block.CropProps.HarvestGrowthStageLoss = CropProps.HarvestGrowthStageLoss;
                block.CropProps.MultipleHarvests       = CropProps.MultipleHarvests;
                block.CropProps.NutrientConsumption    = CropProps.NutrientConsumption;
                block.CropProps.RequiredNutrient       = CropProps.RequiredNutrient;
                block.CropProps.TotalGrowthDays        = CropProps.TotalGrowthDays;
                block.CropProps.TotalGrowthMonths      = CropProps.TotalGrowthMonths;

                block.CropProps.ColdDamageBelow      = CropProps.ColdDamageBelow;
                block.CropProps.HeatDamageAbove      = CropProps.HeatDamageAbove;
                block.CropProps.DamageGrowthStuntMul = CropProps.DamageGrowthStuntMul;
                block.CropProps.ColdDamageRipeMul    = CropProps.ColdDamageRipeMul;


                if (CropProps.Behaviors != null)
                {
                    block.CropProps.Behaviors = new CropBehavior[CropProps.Behaviors.Length];
                    for (int i = 0; i < CropProps.Behaviors.Length; i++)
                    {
                        CropBehaviorType behaviorType = CropProps.Behaviors[i];
                        CropBehavior     behavior     = instancer.CreateCropBehavior(block, behaviorType.name);
                        if (behaviorType.properties != null)
                        {
                            behavior.Initialize(behaviorType.properties);
                        }
                        block.CropProps.Behaviors[i] = behavior;
                    }
                }
            }

            if (block.Drops == null)
            {
                block.Drops = new BlockDropItemStack[] { new BlockDropItemStack()
                                                         {
                                                             Code     = block.Code,
                                                             Type     = EnumItemClass.Block,
                                                             Quantity = NatFloat.One
                                                         } };
            }

            block.CreativeInventoryTabs = GetCreativeTabs(block.Code, CreativeInventory, searchReplace);

            foreach (BlockFacing facing in BlockFacing.ALLFACES)
            {
                if (SideAo != null && SideAo.ContainsKey(facing.Code))
                {
                    block.SideAo[facing.Index] = SideAo[facing.Code];
                }

                if (EmitSideAo != null && EmitSideAo.ContainsKey(facing.Code))
                {
                    if (EmitSideAo[facing.Code])
                    {
                        block.EmitSideAo |= (byte)facing.Flag;
                    }
                }

                if (SideSolid != null && SideSolid.ContainsKey(facing.Code))
                {
                    block.SideSolid[facing.Index] = SideSolid[facing.Code];
                }

                if (SideOpaque != null && SideOpaque.ContainsKey(facing.Code))
                {
                    block.SideOpaque[facing.Index] = SideOpaque[facing.Code];
                }
            }
        }
Example #13
0
        public void InitBlock(IClassRegistryAPI instancer, ILogger logger, Block block, Dictionary <string, string> searchReplace)
        {
            BlockBehaviorType[] behaviorTypes = Behaviors;

            if (behaviorTypes != null)
            {
                List <BlockBehavior> behaviors = new List <BlockBehavior>();

                for (int i = 0; i < behaviorTypes.Length; i++)
                {
                    BlockBehaviorType behaviorType = behaviorTypes[i];

                    if (instancer.GetBlockBehaviorClass(behaviorType.name) == null)
                    {
                        logger.Warning(Lang.Get("Block behavior {0} for block {1} not found", behaviorType.name, block.Code));
                        continue;
                    }

                    BlockBehavior behavior = instancer.CreateBlockBehavior(block, behaviorType.name);
                    if (behaviorType.properties == null)
                    {
                        behaviorType.properties = new JsonObject(new JObject());
                    }

                    behavior.Initialize(behaviorType.properties);
                    behavior.properties = behaviorType.properties;

                    behaviors.Add(behavior);
                }

                block.BlockBehaviors = behaviors.ToArray();
            }

            if (CropProps != null)
            {
                block.CropProps = new BlockCropProperties();
                block.CropProps.GrowthStages           = CropProps.GrowthStages;
                block.CropProps.HarvestGrowthStageLoss = CropProps.HarvestGrowthStageLoss;
                block.CropProps.MultipleHarvests       = CropProps.MultipleHarvests;
                block.CropProps.NutrientConsumption    = CropProps.NutrientConsumption;
                block.CropProps.RequiredNutrient       = CropProps.RequiredNutrient;
                block.CropProps.TotalGrowthDays        = CropProps.TotalGrowthDays;

                if (CropProps.Behaviors != null)
                {
                    block.CropProps.Behaviors = new CropBehavior[CropProps.Behaviors.Length];
                    for (int i = 0; i < CropProps.Behaviors.Length; i++)
                    {
                        CropBehaviorType behaviorType = CropProps.Behaviors[i];
                        CropBehavior     behavior     = instancer.CreateCropBehavior(block, behaviorType.name);
                        if (behaviorType.properties != null)
                        {
                            behavior.Initialize(behaviorType.properties);
                        }
                        block.CropProps.Behaviors[i] = behavior;
                    }
                }
            }

            if (block.Drops == null)
            {
                block.Drops = new BlockDropItemStack[] { new BlockDropItemStack()
                                                         {
                                                             Code     = block.Code,
                                                             Type     = EnumItemClass.Block,
                                                             Quantity = NatFloat.One
                                                         } };
            }

            block.CreativeInventoryTabs = GetCreativeTabs(block.Code, CreativeInventory, searchReplace);

            foreach (BlockFacing facing in BlockFacing.ALLFACES)
            {
                if (SideAo != null && SideAo.ContainsKey(facing.Code))
                {
                    block.SideAo[facing.Index] = SideAo[facing.Code];
                }

                if (SideSolid != null && SideSolid.ContainsKey(facing.Code))
                {
                    block.SideSolid[facing.Index] = SideSolid[facing.Code];
                }

                if (SideOpaque != null && SideOpaque.ContainsKey(facing.Code))
                {
                    block.SideOpaque[facing.Index] = SideOpaque[facing.Code];
                }
            }
        }