public override bool OnPlayerInteractStart(IPlayer player, BlockSelection bs) { ItemSlot hotbarSlot = player.InventoryManager.ActiveHotbarSlot; if (hotbarSlot.Empty) { return(false); } if (currentBuildStage < buildStages.Length) { BuildStage stage = buildStages[currentBuildStage]; BuildStageMaterial[] mats = stage.Materials; for (int i = 0; i < mats.Length; i++) { var stack = mats[i].ItemStack; if (stack.Equals(Api.World, hotbarSlot.Itemstack, GlobalConstants.IgnoredStackAttributes) && stack.StackSize <= hotbarSlot.StackSize) { if (!isSameMatAsPreviouslyAdded(stack)) { continue; } int toMove = stack.StackSize; for (int j = 4; j < invSlotCount && toMove > 0; j++) { toMove -= hotbarSlot.TryPutInto(Api.World, inventory[j], toMove); } hotbarSlot.MarkDirty(); currentBuildStage++; mesh = null; MarkDirty(true); updateSelectiveElements(); (player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); if (stack.Collectible.Attributes?["placeSound"].Exists == true) { AssetLocation sound = AssetLocation.Create(stack.Collectible.Attributes["placeSound"].AsString(), stack.Collectible.Code.Domain); if (sound != null) { Api.World.PlaySoundAt(sound.WithPathPrefixOnce("sounds/"), Pos.X + 0.5, Pos.Y + 0.1, Pos.Z + 0.5, player, true, 12); } } } } } DetermineStorageProperties(null); return(true); }
BuildStageMaterial currentlyUsedMaterialOfStage(BuildStage buildStage) { BuildStageMaterial[] bsms = buildStage.Materials; for (int i = 0; i < bsms.Length; i++) { var bsm = bsms[i]; foreach (var slot in inventory) { if (slot.Empty) { continue; } if (slot.Itemstack.Equals(Api.World, bsm.ItemStack, GlobalConstants.IgnoredStackAttributes)) { return(bsm); } } } return(null); }
protected bool isSameMatAsPreviouslyAdded(ItemStack newStack) { BuildStage bstage = buildStages[currentBuildStage]; for (int i = 0; i < inventory.Count; i++) { ItemSlot slot = inventory[i]; if (slot.Empty) { continue; } if (bstage.Materials.FirstOrDefault(bsm => bsm.ItemStack.Equals(Api.World, slot.Itemstack, GlobalConstants.IgnoredStackAttributes)) != null) { if (!newStack.Equals(Api.World, slot.Itemstack, GlobalConstants.IgnoredStackAttributes)) { return(false); } } } return(true); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); Dictionary <string, BuildStageMaterial[]> resolvedMats = new Dictionary <string, BuildStageMaterial[]>(); List <ItemStack> canIgniteStacks = new List <ItemStack>(); foreach (CollectibleObject obj in api.World.Collectibles) { string firstCodePart = obj.FirstCodePart(); if (obj is Block && (obj as Block).HasBehavior <BlockBehaviorCanIgnite>() || obj is ItemFirestarter) { List <ItemStack> stacks = obj.GetHandBookStacks(api as ICoreClientAPI); if (stacks != null) { canIgniteStacks.AddRange(stacks); } } } ingiteInteraction = new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-firepit-ignite", MouseButton = EnumMouseButton.Right, HotKeyCode = "sneak", Itemstacks = canIgniteStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityPitKiln beg = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPitKiln; if (beg?.Lit != true && beg?.CanIgnite() == true) { return(wi.Itemstacks); } return(null); } } }; var modelConfigs = Attributes["modelConfigs"].AsObject <Dictionary <string, PitKilnModelConfig> >(); var buildMats = Attributes["buildMats"].AsObject <Dictionary <string, JsonItemStackBuildStage[]> >(); foreach (var val in buildMats) { resolvedMats[val.Key] = new BuildStageMaterial[val.Value.Length]; int i = 0; foreach (var stack in val.Value) { if (!stack.Resolve(api.World, "pit kiln build material", true)) { continue; } resolvedMats[val.Key][i++] = new BuildStageMaterial() { ItemStack = stack.ResolvedItemstack, EleCode = stack.EleCode, TextureCodeReplace = stack.TextureCodeReplace, BurnTimeHours = stack.BurnTimeHours }; } } foreach (var val in modelConfigs) { if (val.Value?.BuildStages == null || val.Value.BuildMatCodes == null || val.Value.Shape?.Base == null) { api.World.Logger.Error("Pit kiln model configs: Build stage array, build mat array or composite shape is null. Will ignore this config."); continue; } if (val.Value.BuildStages.Length != val.Value.BuildMatCodes.Length) { api.World.Logger.Error("Pit kiln model configs: Build stage array and build mat array not the same length, please fix. Will ignore this config."); continue; } var loc = val.Value.Shape.Base.Clone().WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/"); Shape shape = api.Assets.TryGet(loc)?.ToObject <Shape>(); if (shape == null) { api.World.Logger.Error("Pit kiln model configs: Shape file {0} not found. Will ignore this config.", val.Value.Shape.Base); continue; } string[] stages = val.Value.BuildStages; string[] matcodes = val.Value.BuildMatCodes; BuildStage[] resostages = new BuildStage[stages.Length]; for (int i = 0; i < stages.Length; i++) { BuildStageMaterial[] stacks; if (!resolvedMats.TryGetValue(matcodes[i], out stacks)) { api.World.Logger.Error("Pit kiln model configs: No such mat code " + matcodes[i] + ". Please fix. Will ignore all configs."); return; } float miny2 = 0; if (val.Value.MinHitboxY2 != null) { miny2 = val.Value.MinHitboxY2[GameMath.Clamp(i, 0, val.Value.MinHitboxY2.Length - 1)]; } resostages[i] = new BuildStage() { ElementName = stages[i], Materials = stacks, MinHitboxY2 = miny2, MatCode = matcodes[i] }; } BuildStagesByBlock[val.Key] = resostages; ShapesByBlock[val.Key] = shape; } }