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(); } }
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]; } } }