internal MeshData GenMesh() { if (ownBlock == null || contentCode == "") { return(null); } ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(null); } ICoreClientAPI capi = api as ICoreClientAPI; ItemStack firstStack = inventory.GetSlot(0).Itemstack; if (firstStack == null) { return(null); } int fillLevel = Math.Max(0, firstStack.StackSize / config.QuantityPerFillLevel - 1); string shapeLoc = config.ShapesPerFillLevel[Math.Min(config.ShapesPerFillLevel.Length - 1, fillLevel)]; Vec3f rotation = new Vec3f(ownBlock.Shape.rotateX, ownBlock.Shape.rotateY, ownBlock.Shape.rotateZ); MeshData meshbase; MeshData meshadd; blockTexPosSource = capi.Tesselator.GetTexSource(ownBlock); capi.Tesselator.TesselateShape("betrough", api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshbase, this, rotation); BlockTroughDoubleBlock doubleblock = ownBlock as BlockTroughDoubleBlock; if (doubleblock != null) { capi.Tesselator.TesselateShape("betroughcontents", api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshadd, this, rotation.Add(0, 180, 0), 0, 0, null, new string[] { "Origin point/contents/*" }); BlockFacing facing = doubleblock.OtherPartPos(); meshadd.Translate(facing.Normalf); meshbase.AddMeshData(meshadd); } return(meshbase); }
public bool IsSuitableFor(Entity entity) { ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(false); } for (int i = 0; i < config.Foodfor.Length; i++) { if (WildcardUtil.Match(config.Foodfor[i], entity.Code)) { return(inventory[0].StackSize >= config.QuantityPerFillLevel); } } return(false); }
public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) { if (contentConfigs == null) { return; } ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); ItemStack firstStack = inventory[0].Itemstack; if (config == null || firstStack == null) { return; } int fillLevel = firstStack.StackSize / config.QuantityPerFillLevel; dsc.AppendLine(Lang.Get("Portions: {0}", fillLevel)); }
public bool IsSuitableFor(Entity entity) { ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(false); } for (int i = 0; i < config.Foodfor.Length; i++) { if (RegistryObject.WildCardMatch(config.Foodfor[i], entity.Code)) { return(true); } } return(false); }
public float ConsumeOnePortion() { ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(0f); } inventory[0].TakeOut(config.QuantityPerFillLevel); if (inventory[0].Empty) { contentCode = ""; } inventory[0].MarkDirty(); MarkDirty(true); return(1f); }
public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) { ItemStack firstStack = inventory[0].Itemstack; if (contentConfigs == null) { return; } ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null && firstStack != null) { dsc.AppendLine(firstStack.StackSize + "x " + firstStack.GetName()); } if (config == null || firstStack == null) { return; } int fillLevel = firstStack.StackSize / config.QuantityPerFillLevel; dsc.AppendLine(Lang.Get("Portions: {0}", fillLevel)); ItemStack contentsStack = config.Content.ResolvedItemstack; if (contentsStack != null) { dsc.AppendLine(Lang.Get(contentsStack.GetName())); } if (config.FoodForDesc != null) { dsc.AppendLine(Lang.Get(config.FoodForDesc)); } }
internal MeshData GenMesh() { if (Block == null) { return(null); } ItemStack firstStack = inventory[0].Itemstack; if (firstStack == null) { return(null); } string shapeLoc = ""; ICoreClientAPI capi = Api as ICoreClientAPI; if (contentCode == "" || contentConfigs == null) { if (firstStack.Collectible.Code.Path == "rot") { shapeLoc = "block/wood/trough/" + (Block.Variant["part"] == "small" ? "small" : "large") + "/rotfill" + GameMath.Clamp(firstStack.StackSize / 4, 1, 4); } else { return(null); } } else { ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(null); } int fillLevel = Math.Max(0, firstStack.StackSize / config.QuantityPerFillLevel - 1); shapeLoc = config.ShapesPerFillLevel[Math.Min(config.ShapesPerFillLevel.Length - 1, fillLevel)]; } Vec3f rotation = new Vec3f(Block.Shape.rotateX, Block.Shape.rotateY, Block.Shape.rotateZ); MeshData meshbase; MeshData meshadd; blockTexPosSource = capi.Tesselator.GetTexSource(Block); Shape shape = Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(); capi.Tesselator.TesselateShape("betroughcontentsleft", shape, out meshbase, this, rotation); BlockTroughDoubleBlock doubleblock = Block as BlockTroughDoubleBlock; if (doubleblock != null) { capi.Tesselator.TesselateShape("betroughcontentsright", shape, out meshadd, this, rotation.Add(0, 180, 0)); BlockFacing facing = doubleblock.OtherPartFacing(); meshadd.Translate(facing.Normalf); meshbase.AddMeshData(meshadd); } return(meshbase); }
internal bool OnInteract(IPlayer byPlayer, BlockSelection blockSel) { ItemSlot handSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (handSlot.Empty) { return(false); } ItemStack[] stacks = GetContentStacks(); bool canAdd; // Add new if (stacks.Length == 0) { for (int i = 0; i < contentConfigs.Length; i++) { contentConfigs[i].Content.Resolve(api.World, "troughcontentconfig"); canAdd = handSlot.Itemstack.Equals(api.World, contentConfigs[i].Content.ResolvedItemstack, GlobalConstants.IgnoredStackAttributes) && handSlot.StackSize >= contentConfigs[i].QuantityPerFillLevel ; if (canAdd) { contentCode = contentConfigs[i].Code; inventory.GetSlot(0).Itemstack = handSlot.TakeOut(contentConfigs[i].QuantityPerFillLevel); if (api.Side == EnumAppSide.Client) { currentMesh = GenMesh(); } MarkDirty(true); return(true); } } } // Or merge ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(false); } canAdd = handSlot.Itemstack.Equals(api.World, stacks[0], GlobalConstants.IgnoredStackAttributes) && handSlot.StackSize >= config.QuantityPerFillLevel && stacks[0].StackSize < config.QuantityPerFillLevel * config.MaxFillLevels ; if (canAdd) { handSlot.TakeOut(config.QuantityPerFillLevel); inventory.GetSlot(0).Itemstack.StackSize += config.QuantityPerFillLevel; if (api.Side == EnumAppSide.Client) { currentMesh = GenMesh(); } MarkDirty(true); return(true); } return(false); }