public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); if (energyStorage == null) { energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), 0, MyMiniLib.GetAttributeInt(Block, "output", 500)); } energyStorage.setEnergy(tree.GetFloat("energy")); if (Api != null && Api.World.Side == EnumAppSide.Client) { generation = tree.GetFloat("gen"); } }
public override void ToTreeAttributes(ITreeAttribute tree) { tree.SetString("owner", OwnerUID); for (int i = 0; i < limit; i++) { if (i >= Breakins.Count) { continue; } tree.SetString("breakins" + i, Breakins[i]); } base.ToTreeAttributes(tree); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); ITreeAttribute invtree = new TreeAttribute(); Inventory.ToTreeAttributes(invtree); tree["inventory"] = invtree; tree.SetFloat("furnaceTemperature", furnaceTemperature); tree.SetInt("maxTemperature", maxTemperature); tree.SetFloat("oreCookingTime", inputStackCookingTime); tree.SetFloat("fuelBurnTime", fuelBurnTime); tree.SetFloat("maxFuelBurnTime", maxFuelBurnTime); }
public override void ToTreeAttributes(ITreeAttribute tree) { if (caps.Count > 0) { tree.SetInt("capCount", caps.Count); for (int i = 0; i < caps.Count; i++) { tree.SetInt("cap" + i + "x", caps[i].X); tree.SetInt("cap" + i + "y", caps[i].Y); tree.SetInt("cap" + i + "z", caps[i].Z); } } base.ToTreeAttributes(tree); }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); deserializeVoxels(tree.GetBytes("voxels")); selectedRecipeId = tree.GetInt("selectedRecipeId", -1); BaseMaterial = tree.GetItemstack("baseMaterial"); if (Api?.World != null) { BaseMaterial?.ResolveBlockOrItem(Api.World); } RegenMeshAndSelectionBoxes(); }
private MeshRef CreateModel(ItemStack forStack) { ITreeAttribute tree = forStack.Attributes; int[] materials = BlockEntityChisel.MaterialIdsFromAttributes(tree, capi.World); uint[] cuboids = (tree["cuboids"] as IntArrayAttribute)?.AsUint; List <uint> voxelCuboids = cuboids == null ? new List <uint>() : new List <uint>(cuboids); MeshData mesh = BlockEntityChisel.CreateMesh(capi, voxelCuboids, materials); mesh.Rgba2 = null; return(capi.Render.UploadMesh(mesh)); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); _inv.ToTreeAttributes(tree); if (PlayerUid != null) { tree.SetString("playerUID", PlayerUid); } if (PlayerName != null) { tree.SetString("playerName", PlayerName); } }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); tree.SetInt("count", positionsCount); for (int i = 0; i < positionsCount; i++) { FruitData val = fruitPoints[i]; if (val == null) continue; tree.SetDouble("td" + i, val.transitionDate); tree.SetInt("var" + i, val.variant); tree.SetInt("tc" + i, val.currentStage); } }
public override void ToTreeAttributes(ITreeAttribute tree) { if (ConnectedFruits != null) { tree.SetBytes("myFruits", JsonUtil.ToBytes(ConnectedFruits)); } if (ConnectedFronds != null) { tree.SetBytes("myFronds", JsonUtil.ToBytes(ConnectedFronds)); } tree.SetDouble("nextGrowTime", nextGrowTime); base.ToTreeAttributes(tree); }
private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null) { ushort[] heightmap = chunks[0].MapChunk.RainHeightMap; IntMap climateMap = chunks[0].MapChunk.MapRegion.ClimateMap; int regionChunkSize = api.WorldManager.RegionSize / chunksize; float fac = (float)climateMap.InnerSize / regionChunkSize; int rlX = chunkX % regionChunkSize; int rlZ = chunkZ % regionChunkSize; climateUpLeft = climateMap.GetUnpaddedInt((int)(rlX * fac), (int)(rlZ * fac)); climateUpRight = climateMap.GetUnpaddedInt((int)(rlX * fac + fac), (int)(rlZ * fac)); climateBotLeft = climateMap.GetUnpaddedInt((int)(rlX * fac), (int)(rlZ * fac + fac)); climateBotRight = climateMap.GetUnpaddedInt((int)(rlX * fac + fac), (int)(rlZ * fac + fac)); int climateMid = GameMath.BiLerpRgbColor(0.5f, 0.5f, climateUpLeft, climateUpRight, climateBotLeft, climateBotRight); // 16-23 bits = Red = temperature // 8-15 bits = Green = rain // 0-7 bits = Blue = humidity int rain = (climateMid >> 8) & 0xff; int humidity = climateMid & 0xff; // Lake density at chunk center float lakeDensity = 4 * (rain + humidity) / 255f; float maxTries = lakeDensity * 10; int dx, dz; while (maxTries-- > 0) { if (maxTries < 1 && rand.NextDouble() > maxTries) { break; } dx = rand.Next(chunksize); dz = rand.Next(chunksize); TryPlaceLakeAt(dx, dz, chunkX, chunkZ, heightmap); //ushort blockId = blockAccessor.GetBlock(new AssetLocation("creativeblock-37")).BlockId; //blockAccessor.SetBlock(blockId, new BlockPos(chunkX * chunksize + dx, heightmap[dz * chunksize + dx] + 1, chunkZ * chunksize + dz)); } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { ItemStack contentStack = GetContent(slot.Itemstack); if (contentStack != null) { if (contentStack.MatchesSearchText(byEntity.World, "potion")) { try { essencesDic.Clear(); ITreeAttribute potion = contentStack.Attributes; foreach (var essence in maxEssenceDic.Keys.ToList()) { if (potion.TryGetFloat("potion" + essence) != null) { if (!essencesDic.ContainsKey(essence)) { essencesDic.Add(essence, 0); } essencesDic[essence] = potion.GetFloat("potion" + essence); } } } catch (Exception e) { api.World.Logger.Error("Failed loading potion effects for potion {0}. Will ignore. Exception: {1}", Code, e); } //api.Logger.Debug("potion {0}, {1}", essencesDic.Count, potionId); //api.Logger.Debug("[Potion] check if drinkable {0}", byEntity.WatchedAttributes.GetLong(potionId)); /* This checks if the potion effect callback is on */ if (essencesDic.Count > 0) { if (byEntity.WatchedAttributes.TryGetLong("potionid") == null || byEntity.WatchedAttributes.TryGetLong("potionid") == 0) { //api.Logger.Debug("potion {0}", byEntity.WatchedAttributes.GetLong(potionId)); byEntity.World.RegisterCallback((dt) => playEatSound(byEntity, "drink", 1), 500); handling = EnumHandHandling.PreventDefault; } } return; } } else { tickSec = 0; essencesDic.Clear(); } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
private void RefreshBuyingSellingInventory() { if (TradeProps == null) { return; } TradeProps.Buying.List.Shuffle(World.Rand); int quantity = Math.Min(TradeProps.Buying.List.Length, TradeProps.Buying.MaxItems); for (int i = 0; i < quantity; i++) { ItemSlotTrade slot = Inventory.GetBuyingSlot(i); TradeItem tradeItem = TradeProps.Buying.List[i]; if (tradeItem.Name == null) { tradeItem.Name = i + ""; } slot.SetTradeItem(tradeItem.Resolve(World)); slot.MarkDirty(); } TradeProps.Selling.List.Shuffle(World.Rand); quantity = Math.Min(TradeProps.Selling.List.Length, TradeProps.Selling.MaxItems); //Console.WriteLine("=================="); //Console.WriteLine("resolving for " + EntityId + ", total items: " +TradeConf.Selling.List.Length + ", on side " + api.Side); for (int i = 0; i < quantity; i++) { ItemSlotTrade slot = Inventory.GetSellingSlot(i); TradeItem tradeItem = TradeProps.Selling.List[i]; if (tradeItem.Name == null) { tradeItem.Name = i + ""; } slot.SetTradeItem(tradeItem.Resolve(World)); slot.MarkDirty(); //Console.WriteLine("resolved to: " + slot.Itemstack); } ITreeAttribute tree = GetOrCreateTradeStore(); Inventory.ToTreeAttributes(tree); }
public static ItemStack GetToolheadStack(IItemStack stack) { ItemStack partstack = null; if (stack.Item is IModularTool) { string toolheadslot = (stack.Item as IModularTool).TinkerProps.ToolheadSlot ?? "toolhead"; ITreeAttribute TinkerSlots = stack.Attributes.GetOrAddTreeAttribute("toolparts"); partstack = TinkerSlots.GetItemstack(toolheadslot); } return(partstack); }
public static bool HasNeededParts(ItemStack stack) { ITreeAttribute ToolSlots = stack.Attributes.GetOrAddTreeAttribute("toolparts"); foreach (SlotDefinition slotdef in GetSlotDefinitions(stack.Item as IModularItem)) { if (slotdef.Optional == false && !ToolSlots.HasAttribute(slotdef.SlotName)) { return(false); } } return(true); }
/// <summary> /// Loads the entity from a stored byte array from the SaveGame /// </summary> /// <param name="tree"></param> public virtual void FromAttributes(ITreeAttribute tree, string version) { foreach (var val in tree) { byte[] data = (val.Value as ByteArrayAttribute).value; using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(ms)) { ActiveAnimationsByAnimCode[val.Key] = AnimationMetaData.FromBytes(reader, version); } } } }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve) { base.FromTreeAttributes(tree, worldAccessForResolve); mushroomBlockCode = new AssetLocation(tree.GetString("mushroomBlockCode")); grownMushroomOffsets = tree.GetVec3is("grownMushroomOffsets"); mushroomsGrownTotalDays = tree.GetDouble("mushromsGrownTotalDays"); mushroomsDiedTotalDays = tree.GetDouble("mushroomsDiedTotalDays"); lastUpdateTotalDays = tree.GetDouble("lastUpdateTotalDays"); mushroomsGrowingDays = tree.GetDouble("mushroomsGrowingDays"); setMushroomBlock(worldAccessForResolve.GetBlock(mushroomBlockCode)); }
private bool TryGetPregnant() { if (entity.World.Rand.NextDouble() > 0.03) { return(false); } if (TotalDaysCooldownUntil > entity.World.Calendar.TotalDays) { return(false); } ITreeAttribute tree = entity.WatchedAttributes.GetTreeAttribute("hunger"); if (tree == null) { return(false); } float saturation = tree.GetFloat("saturation", 0); if (saturation >= PortionsEatenForMultiply) { Entity maleentity = null; if (RequiresNearbyEntityCode != null && (maleentity = GetRequiredEntityNearby()) == null) { return(false); } if (entity.World.Rand.NextDouble() < 0.2) { tree.SetFloat("saturation", saturation - 1); return(false); } tree.SetFloat("saturation", saturation - PortionsEatenForMultiply); if (maleentity != null) { maleentity.WatchedAttributes.SetFloat("saturation", Math.Max(0, saturation - 1)); } IsPregnant = true; TotalDaysPregnancyStart = entity.World.Calendar.TotalDays; entity.WatchedAttributes.MarkPathDirty("multiply"); return(true); } return(false); }
public override void Initialize(EntityProperties properties, JsonObject attributes) { bodyheatTree = entity.WatchedAttributes.GetTreeAttribute("bodyheat"); if (bodyheatTree == null) { entity.WatchedAttributes.SetAttribute("bodyheat", bodyheatTree = new TreeAttribute()); Bodyheat = 36; MaxBodyheat = 42; } base.Initialize(properties, attributes); }
public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve) { base.FromTreeAtributes(tree, worldAccessForResolve); Materials = (tree["materials"] as IntArrayAttribute).AsUShort; VoxelCuboids = new List <uint>((tree["cuboids"] as IntArrayAttribute).AsUint); if (api is ICoreClientAPI) { RegenMesh(); RegenSelectionBoxes(null); MarkDirty(true); } }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); QuantityServings = (float)tree.GetDecimal("quantityServings"); RecipeCode = tree.GetString("recipeCode", ""); Sealed = tree.GetBool("sealed"); if (Api != null && Api.Side == EnumAppSide.Client) { currentMesh = null; MarkDirty(true); } }
public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAtributes(tree, worldForResolving); RecipeCode = tree.GetString("recipeCode"); QuantityServings = (float)tree.GetDecimal("quantityServings"); if (api?.Side == EnumAppSide.Client && currentMesh == null) { currentMesh = GenMesh(); MarkDirty(true); } }
private static bool ApplyPart(IItemStack parent, string slot, ItemStack partstack) { ITreeAttribute ToolSlots = parent.Attributes.GetOrAddTreeAttribute("toolparts"); if (!ToolSlots.HasAttribute(slot)) { ToolSlots.SetItemstack(slot, partstack); (parent.Item as IModularItem).RecalculateAttributes(parent); return(true); } return(false); }
public virtual ModelTransform GetModelTransform(string key) { ITreeAttribute attr = GetTreeAttribute(key); if (attr == null) { return(null); } ITreeAttribute torigin = attr.GetTreeAttribute("origin"); ITreeAttribute trotation = attr.GetTreeAttribute("rotation"); ITreeAttribute ttranslation = attr.GetTreeAttribute("translation"); float scale = attr.GetFloat("scale", 1); Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f); if (torigin != null) { origin.X = torigin.GetFloat("x"); origin.Y = torigin.GetFloat("y"); origin.Z = torigin.GetFloat("z"); } Vec3f rotation = new Vec3f(); if (trotation != null) { rotation.X = trotation.GetFloat("x"); rotation.Y = trotation.GetFloat("y"); rotation.Z = trotation.GetFloat("z"); } Vec3f translation = new Vec3f(); if (ttranslation != null) { translation.X = ttranslation.GetFloat("x"); translation.Y = ttranslation.GetFloat("y"); translation.Z = ttranslation.GetFloat("z"); } return(new ModelTransform() { Scale = scale, Origin = origin, Translation = translation, Rotation = rotation }); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); ovenInv.ToTreeAttributes(tree); tree.SetInt("burn", burning ? 1 : 0); tree.SetInt("rota", rotation); tree.SetFloat("temp", ovenTemperature); tree.SetFloat("tfuel", fuelBurnTime); for (int i = 0; i < itemCapacity; i++) { bakingData[i].WriteToTree(tree, i); } }
public override void Initialize(EntityProperties properties, JsonObject typeAttributes) { ITreeAttribute tiredTree = entity.WatchedAttributes.GetTreeAttribute("tiredness"); if (tiredTree == null) { entity.WatchedAttributes.SetAttribute("tiredness", tiredTree = new TreeAttribute()); Tiredness = typeAttributes["currenttiredness"].AsFloat(0); } listenerId = entity.World.RegisterGameTickListener(SlowTick, 3000); hoursTotal = entity.World.Calendar.TotalHours; }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); transitionHoursLeft = tree.GetDouble("transitionHoursLeft"); if (tree.HasAttribute("transitionAtTotalDays")) // Pre 1.13 format { transitionAtTotalDaysOld = tree.GetDouble("transitionAtTotalDays"); } lastCheckAtTotalDays = tree.GetDouble("lastCheckAtTotalDays"); ConvertToOverride = tree.GetString("convertToOverride", null); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); if (ownBlock != null) { tree.SetString("forBlockCode", ownBlock.Code.ToShortString()); } if (type == null) { type = defaultType; // No idea why. Somewhere something has no type. Probably some worldgen ruins } tree.SetString("type", type); }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); transitionHoursLeft = tree.GetDouble("transitionHoursLeft"); if (tree.HasAttribute("totalDaysForNextStage")) // Pre 1.13 format { totalDaysForNextStageOld = tree.GetDouble("totalDaysForNextStage"); } lastCheckAtTotalDays = tree.GetDouble("lastCheckAtTotalDays"); roomness = tree.GetInt("roomness"); }
public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAtributes(tree, worldForResolving); Circuit.FromTreeAttributes(tree.GetTreeAttribute("circuit"), worldForResolving); Blockentity.MarkDirty(true); if (Api == null) { return; } if (Api.Side == EnumAppSide.Client) { renderer.RegenCircuitMesh(this.Circuit); } }
/// <summary> /// Merges trees (it will overwrite existing values) /// </summary> /// <param name="tree"></param> public virtual void MergeTree(ITreeAttribute tree) { lock (attributesLock) { if (tree is TreeAttribute) { foreach (var attribute in (tree as TreeAttribute).attributes) { MergeAttribute(this, attribute.Key, attribute.Value); } } } throw new ArgumentException("Excepted TreeAtribute but got " + tree.GetType().Name + "! " + tree.ToString() + ""); }