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