public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo) { ItemStack[] contents = GetNonEmptyContents(capi.World, itemstack); string recipeCode = itemstack.Attributes.GetString("recipeCode"); AssetLocation loc = LabelForContents(recipeCode, contents); if (loc == null) { return; } Dictionary <string, MeshRef> meshrefs = ObjectCacheUtil.GetOrCreate(capi, "blockcrockGuiMeshRefs", () => { return(new Dictionary <string, MeshRef>()); }); string key = Code.ToShortString() + loc.ToShortString(); MeshRef meshref; if (!meshrefs.TryGetValue(key, out meshref)) { MeshData mesh = GenMesh(capi, loc, new Vec3f(0, 270, 0)); //mesh.Rgba2 = null; meshrefs[key] = meshref = capi.Render.UploadMesh(mesh); } renderinfo.ModelRef = meshref; }
public EntityBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos, AssetLocation fallSound, float impactDamageMul, bool canFallSideways, float dustIntensity) { this.impactDamageMul = impactDamageMul; this.fallSound = fallSound; this.canFallSideways = canFallSideways; this.dustIntensity = dustIntensity; WatchedAttributes.SetBool("canFallSideways", canFallSideways); WatchedAttributes.SetFloat("dustIntensity", dustIntensity); if (fallSound != null) { WatchedAttributes.SetString("fallSound", fallSound.ToShortString()); } this.Code = new AssetLocation("blockfalling"); this.blockCode = block.Code; this.removedBlockentity = blockEntity; this.initialPos = initialPos.Copy(); // Must have a Copy() here! ServerPos.SetPos(initialPos); ServerPos.X += 0.5; ServerPos.Z += 0.5; Pos.SetFrom(ServerPos); }
public virtual string GetMeshCacheKey(ItemStack itemstack) { ItemStack[] contents = GetNonEmptyContents(api.World, itemstack); string recipeCode = itemstack.Attributes.GetString("recipeCode"); AssetLocation loc = LabelForContents(recipeCode, contents); return(Code.ToShortString() + loc.ToShortString()); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); tree.SetString("mushroomBlockCode", mushroomBlockCode.ToShortString()); tree.SetVec3is("grownMushroomOffsets", grownMushroomOffsets); tree.SetDouble("mushromsGrownTotalDays", mushroomsGrownTotalDays); tree.SetDouble("mushroomsDiedTotalDays", mushroomsDiedTotalDays); tree.SetDouble("lastUpdateTotalDays", lastUpdateTotalDays); tree.SetDouble("mushroomsGrowingDays", mushroomsGrowingDays); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); tree.SetDouble("inc", timeToIncubate); tree.SetDouble("occ", occupiedTimeLast); for (int i = 0; i < 10; i++) { tree.SetInt("gen" + i, parentGenerations[i]); AssetLocation chickName = chickNames[i]; if (chickName != null) { tree.SetString("chick" + i, chickName.ToShortString()); } } }
public override void ToBytes(BinaryWriter writer, bool forClient) { base.ToBytes(writer, forClient); writer.Write(initialPos.X); writer.Write(initialPos.Y); writer.Write(initialPos.Z); writer.Write(blockCode.ToShortString()); writer.Write(blockEntityAttributes == null); if (blockEntityAttributes != null) { blockEntityAttributes.ToBytes(writer); writer.Write(blockEntityClass); } }
public static MeshData GetMesh(ITesselatorAPI tesselator, ICoreAPI api, BlockCrock block, ItemStack[] stacks, string recipeCode, Vec3f rot) { Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(api, "blockCrockMeshes", () => new Dictionary <string, MeshData>()); MeshData mesh = null; AssetLocation labelLoc = block.LabelForContents(recipeCode, stacks); if (labelLoc == null) { return(null); } if (meshes.TryGetValue(labelLoc.ToShortString() + block.Shape.rotateY, out mesh)) { return(mesh); } return(meshes[labelLoc.ToString() + block.Shape.rotateY] = block.GenMesh(api as ICoreClientAPI, labelLoc, rot, tesselator)); }
public AssetLocation GetClassifiedAssetLocation(AssetLocation loc, string category) { return(new AssetLocation(string.Format("{0}:{1}-{2}", loc.Domain, category, loc.ToShortString()))); }
public static string GetSafeName(this AssetLocation asset) { return(asset.ToShortString().Replace("/", "-")); }