public override void OnLoadCollectibleMappings(IWorldAccessor worldForResolve, Dictionary <int, AssetLocation> oldBlockIdMapping, Dictionary <int, AssetLocation> oldItemIdMapping) { ItemStack stack = inventory?.GetSlot(0)?.Itemstack; if (stack?.FixMapping(oldBlockIdMapping, oldItemIdMapping, worldForResolve) == false) { inventory.GetSlot(0).Itemstack = null; } }
public void UpdateRatios(int forceUnchanged = -1) { updating = true; int quantityFilledSlots = 0; float totalChance = 0; for (int i = 0; i < 10; i++) { ItemSlot slot = inv.GetSlot(i); quantityFilledSlots += (slot.Itemstack != null) ? 1 : 0; GuiElementNumberInput inp = SingleComposer.GetNumberInput("chance" + (i + 1)); totalChance += inp.GetValue(); } float chanceForMissingOnes = 100 / Math.Max(1, quantityFilledSlots); float scaleValue = 100f / totalChance; int totalNew = 0; for (int i = 0; i < 10; i++) { GuiElementNumberInput inp = SingleComposer.GetNumberInput("chance" + (i + 1)); ItemSlot slot = inv.GetSlot(i); if (slot.Itemstack == null) { inp.SetValue(""); continue; } int newVal = (int)(inp.GetValue() * scaleValue); if (inp.GetText().Length != 0) { if ((i != forceUnchanged || (int)(inp.GetValue()) > 100) && totalChance > 100) { inp.SetValue("" + newVal); totalNew += newVal; } else { totalNew += (int)inp.GetValue(); } } } updating = false; SingleComposer.GetDynamicText("totalchance").SetNewText("Total chance: " + (int)totalNew + "%"); }
void loadToolMeshes() { BlockFacing facing = getFacing().GetCW(); if (facing == null) { return; } Vec3f facingNormal = facing.Normalf; Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f); ICoreClientAPI clientApi = (ICoreClientAPI)api; for (int i = 0; i < 4; i++) { toolMeshes[i] = null; IItemStack stack = inventory.GetSlot(i).Itemstack; if (stack == null) { continue; } tmpItem = stack.Collectible; if (stack.Class == EnumItemClass.Item) { clientApi.Tesselator.TesselateItem(stack.Item, out toolMeshes[i], this); } else { clientApi.Tesselator.TesselateBlock(stack.Block, out toolMeshes[i]); } if (stack.Class == EnumItemClass.Item && stack.Item.Shape?.VoxelizeTexture == true) { toolMeshes[i].Scale(origin, 0.33f, 0.33f, 0.33f); toolMeshes[i].Translate(((i % 2) == 0) ? 0.23f : -0.3f, (i > 1) ? 0.2f : -0.3f, 0.429f * ((facing.Axis == EnumAxis.X) ? -1 : 1)); toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, 0); toolMeshes[i].Rotate(origin, 180 * GameMath.DEG2RAD, 0, 0); } else { toolMeshes[i].Scale(origin, 0.6f, 0.6f, 0.6f); float x = ((i > 1) ? -0.2f : 0.3f); float z = ((i % 2 == 0) ? 0.23f : -0.2f) * (facing.Axis == EnumAxis.X ? 1 : -1); toolMeshes[i].Translate(x, 0.429f, z); toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, GameMath.PIHALF); toolMeshes[i].Rotate(origin, 0, GameMath.PIHALF, 0); } } }
public override void OnBlockBroken() { if (api.World is IServerWorldAccessor) { IItemSlot slot = inventory.GetSlot(0); while (slot.StackSize > 0) { ItemStack split = slot.TakeOut(GameMath.Clamp(slot.StackSize, 1, System.Math.Max(1, slot.Itemstack.Collectible.MaxStackSize / 4))); api.World.SpawnItemEntity(split, pos.ToVec3d().Add(0.5, 0.5, 0.5)); } } }
public override string GetBlockInfo(IPlayer forPlayer) { StringBuilder str = new StringBuilder(); for (int i = 0; i < 3; i++) { ItemStack stack = bloomeryInv.GetSlot(i).Itemstack; if (stack != null) { str.AppendLine(" " + stack.StackSize + "x " + stack.GetName()); } } if (str.Length > 0) { return("Contents:\n" + str); } return(base.GetBlockInfo(forPlayer)); }
public float ConsumeOnePortion() { ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode); if (config == null) { return(0f); } inventory.GetSlot(0).TakeOut(config.QuantityPerFillLevel); if (inventory.GetSlot(0).Empty) { contentCode = ""; } MarkDirty(true); return(1f); }
public ItemStack GetContent() { return(inventory.GetSlot(0).Itemstack); }
public GuiDialogItemLootRandomizer(ItemStack[] stacks, float[] chances, ICoreClientAPI capi) : base("Item Loot Randomizer", capi) { double pad = GuiElementItemSlotGrid.unscaledSlotPadding; ElementBounds slotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 45 + pad, 10, 1).FixedGrow(2 * pad, 2 * pad); ElementBounds chanceInputBounds = ElementBounds.Fixed(3, 0, 48, 30).FixedUnder(slotBounds, -4); ElementBounds leftButton = ElementBounds.Fixed(EnumDialogArea.LeftFixed, 0, 0, 0, 0).WithFixedPadding(10, 1); ElementBounds chanceTextBounds = ElementBounds.Fixed(EnumDialogArea.CenterFixed, 0, 0, 150, 30).WithFixedPadding(10, 1); ElementBounds rightButton = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(10, 1); ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(ElementGeometrics.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; inv = new InventoryGeneric(10, "lootrandomizer-1", capi, null); for (int i = 0; i < 10; i++) { inv.GetSlot(i).Itemstack = stacks[i]; } ElementBounds dialogBounds = ElementStdBounds .AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle) .WithFixedAlignmentOffset(ElementGeometrics.DialogToScreenPadding, 0); float totalChance = chances.Sum(); string text = "Total chance: " + (int)totalChance + "%"; SingleComposer = capi.Gui .CreateCompo("itemlootrandomizer", dialogBounds, false) .AddDialogBG(bgBounds, true) .AddDialogTitleBar("Item Loot Randomizer", OnTitleBarClose) .BeginChildElements(bgBounds) .AddItemSlotGrid(inv, SendInvPacket, 10, slotBounds, "slots") .AddNumberInput(chanceInputBounds = chanceInputBounds.FlatCopy(), (t) => OnTextChanced(0), CairoFont.WhiteDetailText(), "chance1") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(1), CairoFont.WhiteDetailText(), "chance2") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(2), CairoFont.WhiteDetailText(), "chance3") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(3), CairoFont.WhiteDetailText(), "chance4") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(4), CairoFont.WhiteDetailText(), "chance5") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(5), CairoFont.WhiteDetailText(), "chance6") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(6), CairoFont.WhiteDetailText(), "chance7") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(7), CairoFont.WhiteDetailText(), "chance8") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(8), CairoFont.WhiteDetailText(), "chance9") .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(9), CairoFont.WhiteDetailText(), "chance10") .AddButton("Close", OnCloseClicked, leftButton.FixedUnder(chanceInputBounds, 25)) .AddDynamicText(text, CairoFont.WhiteDetailText(), EnumTextOrientation.Left, chanceTextBounds.FixedUnder(chanceInputBounds, 25), 1, "totalchance") .AddButton("Save", OnSaveClicked, rightButton.FixedUnder(chanceInputBounds, 25)) .EndChildElements() .Compose() ; for (int i = 0; i < 10; i++) { GuiElementNumberInput inp = SingleComposer.GetNumberInput("chance" + (i + 1)); inp.SetValue("" + chances[i]); } SingleComposer.GetSlotGrid("slots").CanClickSlot = OnCanClickSlot; }