/// </summary> public override void Initialize(ICoreAPI api) { base.Initialize(api); if (Block.Attributes != null) { //requiredAmps = Block.Attributes["requiredAmps"].AsInt(requiredAmps); rmInputFace = BlockFacing.FromCode(Block.Attributes["inputFace"].AsString("up")); outputFace = BlockFacing.FromCode(Block.Attributes["outputFace"].AsString("down")); animationSpeed = Block.Attributes["animationSpeed"].AsFloat(animationSpeed); inputQuantity = Block.Attributes["inputQuantity"].AsInt(inputQuantity); outputQuantity = Block.Attributes["outputQuantity"].AsInt(outputQuantity); recipe = Block.Attributes["recipe"].AsString(recipe); ingredient = Block.Attributes["ingredient"].AsString(ingredient); rmInputFace = OrientFace(Block.Code.ToString(), rmInputFace); outputFace = OrientFace(Block.Code.ToString(), outputFace); processingTime = Block.Attributes["processingTime"].AsDouble(processingTime); heatRequirement = Block.Attributes["heatRequirement"].AsFloat(heatRequirement); blockoritem = Block.Attributes["blockoritem"].AsString(blockoritem); materials = Block.Attributes["materials"].AsArray <string>(materials); } dummy = new DummyInventory(api); }
public ItemstackComponentBase(ICoreClientAPI capi) : base(capi) { this.capi = capi; dummyInv = new DummyInventory(capi); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(0); }; renderedTooltipSlot = new DummySlot(null, dummyInv); stackInfoBounds = ElementBounds .FixedSize(EnumDialogArea.None, GuiElementItemstackInfo.BoxWidth, 0) .WithFixedPadding(10) .WithFixedPosition(20, 40) ; parentBounds = ElementBounds.Fixed(0, 0, 1, 1); parentBounds.WithParent(ElementBounds.Empty); stackInfoBounds.WithParent(parentBounds); stackInfo = new GuiElementItemstackInfo(capi, stackInfoBounds, OnRequireInfoText); stackInfo.SetSourceSlot(renderedTooltipSlot); stackInfo.ComposeElements(null, null); stackInfo.RecompCheckIgnoredStackAttributes = GlobalConstants.IgnoredStackAttributes; }
protected override void DoDeviceComplete() { deviceState = enDeviceState.IDLE; BlockPos bp = Pos.Copy().Offset(outputFace); BlockEntity checkblock = Api.World.BlockAccessor.GetBlockEntity(bp); var outputContainer = checkblock as BlockEntityContainer; if (Api.World is IServerWorldAccessor) { DummyInventory dummy = new DummyInventory(Api); List <ItemStack> outputitems = MacerationRecipe.GetMacerate(workingitem, Api, MachineName); foreach (ItemStack outitem in outputitems) { if (outitem == null) { continue; } dummy[0].Itemstack = outitem; //no output conatiner, spitout stuff if (outputContainer != null) { bool stoptrying = false; int safetycounter = 0; while (!stoptrying) { WeightedSlot tryoutput = outputContainer.Inventory.GetBestSuitedSlot(dummy[0]); if (tryoutput.slot != null) { ItemStackMoveOperation op = new ItemStackMoveOperation(Api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, dummy[0].StackSize); dummy[0].TryPutInto(tryoutput.slot, ref op); tryoutput.slot.MarkDirty(); if (dummy[0] == null) { stoptrying = true; } else if (dummy[0].StackSize == 0) { stoptrying = true; } } else { stoptrying = true; } safetycounter++; if (safetycounter > 24) { stoptrying = true; } } } Vec3d pos = bp.ToVec3d(); dummy.DropAll(pos); } } }
public void RunBeforeEveryTest() { _testObject = new GameObject("TestCharacter").AddComponent <Character3d>(); _dummyInventory = new DummyInventory(); _dummyResourceLoader = new DummyResourceLoader(); _testObject.Init(_dummyInventory, _dummyResourceLoader); }
void initSlot() { dummyInv = new DummyInventory(capi); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(0); }; slot = new DummySlot(null, dummyInv); }
public override TransitionState[] UpdateAndGetTransitionStates(IWorldAccessor world, ItemSlot inslot) { ItemStack[] stacks = GetContents(world, inslot.Itemstack); for (int i = 0; stacks != null && i < stacks.Length; i++) { DummySlot slot = null; if (inslot.Inventory == null) { DummyInventory dummyInv = new DummyInventory(api); //slot = new DummySlot(stacks != null && stacks.Length > 0 ? stacks[0] : null, dummyInv); - this seems wrong...? slot = new DummySlot(stacks[i], dummyInv); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(mul * GetContainingTransitionModifierContained(world, slot, transType)); }; stacks[i]?.Collectible.UpdateAndGetTransitionStates(world, slot); } else { slot = new DummySlot(stacks[i], inslot.Inventory); var pref = inslot.Inventory.OnAcquireTransitionSpeed; inslot.Inventory.OnAcquireTransitionSpeed = (EnumTransitionType transType, ItemStack stack, float mulByConfig) => { float mul = mulByConfig; if (pref != null) { mul = pref(transType, stack, mulByConfig); } return(GetContainingTransitionModifierContained(world, inslot, transType) * mul); //return mulByConfig * GetContainingTransitionModifierContained(world, slot, transType); - doesn't work for sealed crocks }; slot.MarkedDirty += () => { inslot.Inventory.DidModifyItemSlot(inslot); return(true); }; stacks[i]?.Collectible.UpdateAndGetTransitionStates(world, slot); if (slot.Itemstack == null) { stacks[i] = null; } inslot.Inventory.OnAcquireTransitionSpeed = pref; } } SetContents(inslot.Itemstack, stacks); return(base.UpdateAndGetTransitionStates(world, inslot)); }
public void OnBaked(ItemStack oldStack, ItemStack newStack) { // Copy over properties and bake the contents newStack.Attributes["contents"] = oldStack.Attributes["contents"]; newStack.Attributes.SetInt("pieSize", oldStack.Attributes.GetInt("pieSize")); newStack.Attributes.SetInt("topCrustType", oldStack.Attributes.GetInt("topCrustType")); newStack.Attributes.SetInt("bakeLevel", oldStack.Attributes.GetInt("bakeLevel", 0) + 1); ItemStack[] stacks = GetContents(api.World, newStack); // 1. Cook contents, if there is a cooked version of it for (int i = 0; i < stacks.Length; i++) { CombustibleProperties props = stacks[i]?.Collectible?.CombustibleProps; if (props != null) { ItemStack cookedStack = props.SmeltedStack?.ResolvedItemstack.Clone(); TransitionState state = UpdateAndGetTransitionState(api.World, new DummySlot(cookedStack), EnumTransitionType.Perish); if (state != null) { TransitionState smeltedState = cookedStack.Collectible.UpdateAndGetTransitionState(api.World, new DummySlot(cookedStack), EnumTransitionType.Perish); float nowTransitionedHours = (state.TransitionedHours / (state.TransitionHours + state.FreshHours)) * 0.8f * (smeltedState.TransitionHours + smeltedState.FreshHours) - 1; cookedStack.Collectible.SetTransitionState(cookedStack, EnumTransitionType.Perish, Math.Max(0, nowTransitionedHours)); } } } // Carry over and set perishable properties TransitionableProperties[] tprops = newStack.Collectible.GetTransitionableProperties(api.World, newStack, null); var perishProps = tprops.FirstOrDefault(p => p.Type == EnumTransitionType.Perish); perishProps.TransitionedStack.Resolve(api.World, "pie perished stack"); var inv = new DummyInventory(api, 4); inv[0].Itemstack = stacks[0]; inv[1].Itemstack = stacks[1]; inv[2].Itemstack = stacks[2]; inv[3].Itemstack = stacks[3]; CarryOverFreshness(api, inv.Slots, stacks, perishProps); SetContents(newStack, stacks); }
/// </summary> public override void Initialize(ICoreAPI api) { base.Initialize(api); if (Block.Attributes != null) { //requiredAmps = Block.Attributes["requiredAmps"].AsInt(requiredAmps); rmInputFace = BlockFacing.FromCode(Block.Attributes["inputFace"].AsString("up")); outputFace = BlockFacing.FromCode(Block.Attributes["outputFace"].AsString("down")); rmInputFace = OrientFace(Block.Code.ToString(), rmInputFace); outputFace = OrientFace(Block.Code.ToString(), outputFace); } //TEMP CODE TO ADD faces, should be loaded from attributes //rmInputFace.Add(BlockFacing.UP); //outputFaces.Add(BlockFacing.DOWN); dummy = new DummyInventory(api); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); BlockMeal mealblock = world.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal; CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack); ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack); if (stacks == null || stacks.Length == 0) { dsc.AppendLine("Empty"); return; } DummyInventory dummyInv = new DummyInventory(api); ItemSlot slot = GetDummySlotForFirstPerishableStack(api.World, stacks, null, dummyInv); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { float val = mul * GetContainingTransitionModifierContained(world, inSlot, transType); val *= inSlot.Inventory.GetTransitionSpeedMul(transType, inSlot.Itemstack); return(val); }; if (recipe != null) { double servings = inSlot.Itemstack.Attributes.GetDecimal("quantityServings"); if (recipe != null) { if (servings == 1) { dsc.AppendLine(Lang.Get("{0} serving of {1}", servings, recipe.GetOutputName(world, stacks))); } else { dsc.AppendLine(Lang.Get("{0} servings of {1}", servings, recipe.GetOutputName(world, stacks))); } } string facts = mealblock.GetContentNutritionFacts(world, inSlot, null); if (facts != null) { dsc.Append(facts); } } else { dsc.AppendLine("Contents:"); foreach (var stack in stacks) { if (stack == null) { continue; } dsc.AppendLine(stack.StackSize + "x " + stack.GetName()); } } slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world); if (inSlot.Itemstack.Attributes.GetBool("sealed")) { dsc.AppendLine("<font color=\"lightgreen\">" + Lang.Get("Sealed.") + "</font>"); } }
public string CrockInfoCompact(ItemSlot inSlot) { BlockMeal mealblock = Api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal; BlockCrock crock = inSlot.Itemstack.Collectible as BlockCrock; IWorldAccessor world = Api.World; CookingRecipe recipe = crock.GetCookingRecipe(world, inSlot.Itemstack); ItemStack[] stacks = crock.GetNonEmptyContents(world, inSlot.Itemstack); if (stacks == null || stacks.Length == 0) { return(Lang.Get("Empty Crock") + "\n"); } StringBuilder dsc = new StringBuilder(); if (recipe != null) { double servings = inSlot.Itemstack.Attributes.GetDecimal("quantityServings"); if (recipe != null) { if (servings == 1) { dsc.Append(Lang.Get("{0}x {1}.", servings, recipe.GetOutputName(world, stacks))); } else { dsc.Append(Lang.Get("{0}x {1}.", servings, recipe.GetOutputName(world, stacks))); } } } else { int i = 0; foreach (var stack in stacks) { if (stack == null) { continue; } if (i++ > 0) { dsc.Append(", "); } dsc.Append(stack.StackSize + "x " + stack.GetName()); } dsc.Append("."); } DummyInventory dummyInv = new DummyInventory(Api); ItemSlot contentSlot = BlockCrock.GetDummySlotForFirstPerishableStack(Api.World, stacks, null, dummyInv); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(mul * crock.GetContainingTransitionModifierContained(world, inSlot, transType) * inv.GetTransitionSpeedMul(transType, stack)); }; TransitionState[] transitionStates = contentSlot.Itemstack?.Collectible.UpdateAndGetTransitionStates(Api.World, contentSlot); bool addNewLine = true; if (transitionStates != null) { for (int i = 0; i < transitionStates.Length; i++) { TransitionState state = transitionStates[i]; TransitionableProperties prop = state.Props; float perishRate = contentSlot.Itemstack.Collectible.GetTransitionRateMul(world, contentSlot, prop.Type); if (perishRate <= 0) { continue; } addNewLine = false; float transitionLevel = state.TransitionLevel; float freshHoursLeft = state.FreshHoursLeft / perishRate; switch (prop.Type) { case EnumTransitionType.Perish: if (transitionLevel > 0) { dsc.AppendLine(" " + Lang.Get("{0}% spoiled", (int)Math.Round(transitionLevel * 100))); } else { double hoursPerday = Api.World.Calendar.HoursPerDay; if (freshHoursLeft / hoursPerday >= Api.World.Calendar.DaysPerYear) { dsc.AppendLine(" " + Lang.Get("Fresh for {0} years", Math.Round(freshHoursLeft / hoursPerday / Api.World.Calendar.DaysPerYear, 1))); } /*else if (freshHoursLeft / hoursPerday >= Api.World.Calendar.DaysPerMonth) - confusing. 12 days per months and stuff.. * { * dsc.AppendLine(Lang.Get("<font color=\"orange\">Perishable.</font> Fresh for {0} months", Math.Round(freshHoursLeft / hoursPerday / Api.World.Calendar.DaysPerMonth, 1))); * }*/ else if (freshHoursLeft > hoursPerday) { dsc.AppendLine(" " + Lang.Get("Fresh for {0} days", Math.Round(freshHoursLeft / hoursPerday, 1))); } else { dsc.AppendLine(" " + Lang.Get("Fresh for {0} hours", Math.Round(freshHoursLeft, 1))); } } break; } } } if (addNewLine) { dsc.AppendLine(""); } return(dsc.ToString()); }
void Awake() { Instance = this; // Set as singleton }