public DryingProp(JsonItemStack input, JsonItemStack output, int?dryingTime, JsonItemStack textureSource) { Input = input; Output = output; DryingTime = dryingTime; TextureSource = textureSource; }
public ItemStack[] GetMoldedStacks(ItemStack fromMetal) { if (block.Attributes["drop"].Exists) { JsonItemStack jstack = block.Attributes["drop"].AsObject <JsonItemStack>(); if (jstack == null) { return(null); } return(new ItemStack[] { stackFromCode(jstack, fromMetal) }); } else { JsonItemStack[] jstacks = block.Attributes["drops"].AsObject <JsonItemStack[]>(); List <ItemStack> stacks = new List <ItemStack>(); foreach (var jstack in jstacks) { ItemStack stack = stackFromCode(jstack, fromMetal); if (stack != null) { stacks.Add(stack); } } return(stacks.ToArray()); } }
ItemStack stackFromCode(JsonItemStack jstack, ItemStack fromMetal) { string metaltype = fromMetal.Collectible.LastCodePart(); string tooltype = block.LastCodePart(); jstack.Code.Path = jstack.Code.Path.Replace("{tooltype}", tooltype).Replace("{metal}", metaltype); jstack.Resolve(api.World, "tool mold drop for " + block.Code); return(jstack.ResolvedItemstack); }
public override void Initialize(JsonObject properties) { base.Initialize(properties); if (properties["dropBlockFace"].Exists) { dropBlockFace = properties["dropBlockFace"].AsString(); } if (properties["drop"].Exists) { drop = properties["drop"].AsObject <JsonItemStack>(null, block.Code.Domain); } }
/// <summary> /// Deserializes the alloy /// </summary> /// <param name="reader"></param> /// <param name="resolver"></param> public void FromBytes(BinaryReader reader, IWorldAccessor resolver) { Ingredients = new MetalAlloyIngredient[reader.ReadInt32()]; for (int i = 0; i < Ingredients.Length; i++) { Ingredients[i] = new MetalAlloyIngredient(); Ingredients[i].FromBytes(reader, resolver.ClassRegistry); Ingredients[i].Resolve(resolver, "[FromBytes]"); } Output = new JsonItemStack(); Output.FromBytes(reader, resolver.ClassRegistry); Output.Resolve(resolver, "[FromBytes]"); }
public ItemStack[] GetMoldedStacks(ItemStack fromMetal) { try { if (Block.Attributes["drop"].Exists) { JsonItemStack jstack = Block.Attributes["drop"].AsObject <JsonItemStack>(null, Block.Code.Domain); if (jstack == null) { return(null); } ItemStack stack = stackFromCode(jstack, fromMetal); if (stack == null) { return(new ItemStack[0]); } return(new ItemStack[] { stack }); } else { JsonItemStack[] jstacks = Block.Attributes["drops"].AsObject <JsonItemStack[]>(null, Block.Code.Domain); List <ItemStack> stacks = new List <ItemStack>(); foreach (var jstack in jstacks) { ItemStack stack = stackFromCode(jstack, fromMetal); if (stack != null) { stacks.Add(stack); } } return(stacks.ToArray()); } } catch (JsonReaderException e) { Api.World.Logger.Error("Failed getting molded stacks from tool mold of block {0}, probably unable to parse drop or drops attribute", Block.Code); throw e; } }
public override void FromBytes(BinaryReader reader, IClassRegistryAPI instancer) { base.FromBytes(reader, instancer); if (!reader.ReadBoolean()) { ShapeElement = reader.ReadString(); } if (!reader.ReadBoolean()) { TextureMapping = new string[] { reader.ReadString(), reader.ReadString() }; } if (!reader.ReadBoolean()) { CookedStack = new JsonItemStack(); CookedStack.FromBytes(reader, instancer); } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); rnd = new LCGRandom(api.World.Seed); JsonItemStack[] jstacks = Attributes["craftingResults"].AsObject <JsonItemStack[]>(); List <ItemStack> stacklist = new List <ItemStack>(); for (int i = 0; i < jstacks.Length; i++) { JsonItemStack jstack = jstacks[i]; jstack.Resolve(api.World, "Scrap weapon kit craft result"); if (jstack.ResolvedItemstack != null) { stacklist.Add(jstack.ResolvedItemstack); } } craftResultStacks = stacklist.ToArray(); }
public static bool IsItem(this JsonItemStack stack) => stack.Type == EnumItemClass.Item;
public static bool IsBlock(this JsonItemStack stack) => stack.Type == EnumItemClass.Block;
public override void Initialize(EntityProperties properties, JsonObject attributes) { base.Initialize(properties, attributes); blockCheck = entity.World.GetCachingBlockAccessor(false, false); if (attributes.IsTrue("relaxed")) { relaxed = true; } if (attributes.IsTrue("nochest")) { nochest = true; } if (attributes.IsTrue("nobarrel")) { nobarrel = true; } if (attributes.IsTrue("invLocked")) { invLocked = true; } if (attributes["restrictItem"] != null) { JsonItemStack prestack = attributes["restrictItem"].AsObject <JsonItemStack>(); if (prestack != null) { prestack.Resolve(entity.World, "Locust Program"); if (prestack.ResolvedItemstack != null) { maintree.SetItemstack("workStack", prestack.ResolvedItemstack); maintree.SetBool("restrictItem", true); restricted = true; } } } ITreeAttribute area = maintree.GetTreeAttribute("workArea"); ITreeAttribute box = maintree.GetTreeAttribute("workChest"); ITreeAttribute barrel = maintree.GetTreeAttribute("workBarrel"); workStack = maintree.GetItemstack("workStack"); workStack?.ResolveBlockOrItem(entity.World); if (entity.Api.Side == EnumAppSide.Client && maintree.GetBool("restrictItem")) { restricted = true; } if (area != null) { workArea = cuboiddFromTree(area); } if (box != null) { workChest = new BlockPos(box.GetInt("x"), box.GetInt("y"), box.GetInt("z")); } if (barrel != null) { workBarrel = new BlockPos(barrel.GetInt("x"), barrel.GetInt("y"), barrel.GetInt("z")); } ITreeAttribute tree = maintree["workInv"] as ITreeAttribute; if (tree != null) { workInv.FromTreeAttributes(tree); } }
public override void OnLoaded(ICoreAPI api) { if (api.Side != EnumAppSide.Client) { return; } ICoreClientAPI capi = api as ICoreClientAPI; string createdByText = "metalmolding"; if (Attributes?["createdByText"].Exists == true) { createdByText = Attributes["createdByText"].AsString(); } if (Attributes?["drop"].Exists == true) { JsonItemStack ojstack = Attributes["drop"].AsObject <JsonItemStack>(); if (ojstack != null) { MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>(); for (int i = 0; i < metals.Variants.Length; i++) { string metaltype = metals.Variants[i].Code.Path; string tooltype = LastCodePart(); JsonItemStack jstack = ojstack.Clone(); jstack.Code.Path = jstack.Code.Path.Replace("{tooltype}", tooltype).Replace("{metal}", metaltype); CollectibleObject collObj; if (jstack.Type == EnumItemClass.Block) { collObj = api.World.GetBlock(jstack.Code); } else { collObj = api.World.GetItem(jstack.Code); } if (collObj == null) { continue; } JToken token; if (collObj.Attributes?["handbook"].Exists != true) { if (collObj.Attributes == null) { collObj.Attributes = new JsonObject(JToken.Parse("{ handbook: {} }")); } else { token = collObj.Attributes.Token; token["handbook"] = JToken.Parse("{ }"); } } token = collObj.Attributes["handbook"].Token; token["createdBy"] = JToken.FromObject(createdByText); } } } interactions = ObjectCacheUtil.GetOrCreate(api, "toolmoldBlockInteractions", () => { List <ItemStack> smeltedContainerStacks = new List <ItemStack>(); foreach (CollectibleObject obj in api.World.Collectibles) { if (obj is BlockSmeltedContainer) { smeltedContainerStacks.Add(new ItemStack(obj)); } } return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-toolmold-pour", HotKeyCode = "sneak", MouseButton = EnumMouseButton.Right, Itemstacks = smeltedContainerStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold; return (betm != null && !betm.IsFull) ? wi.Itemstacks : null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-toolmold-takeworkitem", HotKeyCode = null, MouseButton = EnumMouseButton.Right, ShouldApply = (wi, bs, es) => { BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold; return betm != null && betm.IsFull && betm.IsHardened; } }, new WorldInteraction() { ActionLangCode = "blockhelp-toolmold-pickup", HotKeyCode = null, RequireFreeHand = true, MouseButton = EnumMouseButton.Right, ShouldApply = (wi, bs, es) => { BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold; return betm != null && betm.metalContent == null; } } }); }); }
private bool SpillContents(IItemSlot bucketSlot, IEntityAgent byEntity, BlockSelection blockSel) { BlockPos pos = blockSel.Position; IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; IBlockAccessor blockAcc = byEntity.World.BlockAccessor; BlockPos secondPos = blockSel.Position.AddCopy(blockSel.Face); WaterTightContainableProps props = GetContentProps(byEntity.World, bucketSlot.Itemstack); if (props == null || !props.AllowSpill || props.WhenSpilled == null) { return(false); } if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.PlaceBlock) { Block waterBlock = byEntity.World.GetBlock(props.WhenSpilled.Stack.Code); if (props.WhenSpilled.StackByFillLevel != null) { float currentlitres = GetCurrentLitres(byEntity.World, bucketSlot.Itemstack); JsonItemStack fillLevelStack = null; props.WhenSpilled.StackByFillLevel.TryGetValue((int)currentlitres, out fillLevelStack); if (fillLevelStack != null) { waterBlock = byEntity.World.GetBlock(fillLevelStack.Code); } } if (blockAcc.GetBlock(pos).Replaceable >= 6000) { blockAcc.SetBlock(waterBlock.BlockId, pos); blockAcc.MarkBlockDirty(pos); } else { if (blockAcc.GetBlock(secondPos).Replaceable >= 6000) { blockAcc.SetBlock(waterBlock.BlockId, secondPos); blockAcc.MarkBlockDirty(secondPos); } else { return(false); } } } if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.DropContents) { props.WhenSpilled.Stack.Resolve(byEntity.World, "bucketspill"); ItemStack stack = props.WhenSpilled.Stack.ResolvedItemstack.Clone(); stack.StackSize = (int)(props.ItemsPerLitre * GetContent(byEntity.World, bucketSlot.Itemstack).StackSize); byEntity.World.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(blockSel.HitPosition)); } ItemStack emptyBucketStack = new ItemStack(this); if (bucketSlot.Itemstack.StackSize <= 1) { bucketSlot.Itemstack = emptyBucketStack; bucketSlot.MarkDirty(); } else { bucketSlot.TakeOut(1); if (!byPlayer.InventoryManager.TryGiveItemstack(emptyBucketStack, true)) { byEntity.World.SpawnItemEntity(emptyBucketStack, byEntity.LocalPos.XYZ); } } byEntity.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z, byPlayer); return(true); }
private void onServerTick3s(float dt) { BlockPos coalPilePos = Pos.DownCopy(2); BlockPos othercoalPilePos = coalPilePos.AddCopy(blockScs.Orientation.Opposite); bool beforeReceiveHeat = receivesHeat; bool beforeStructureComplete = structureComplete; if (!receivesHeat) { totalHoursLastUpdate = Api.World.Calendar.TotalHours; } BlockEntityCoalPile becp = Api.World.BlockAccessor.GetBlockEntity(coalPilePos) as BlockEntityCoalPile; float leftHeatHoursLeft = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f; becp = Api.World.BlockAccessor.GetBlockEntity(othercoalPilePos) as BlockEntityCoalPile; float rightHeatHoursLeft = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f; receivesHeat = leftHeatHoursLeft > 0 && rightHeatHoursLeft > 0; if (processComplete || !IsFull || !hasLid()) { return; } MultiblockStructure msInUse = null; BlockPos posInUse = null; structureComplete = false; if (ms.InCompleteBlockCount(Api.World, Pos) == 0) { msInUse = ms; posInUse = Pos; structureComplete = true; } else if (msOpp.InCompleteBlockCount(Api.World, Pos.AddCopy(blockScs.Orientation.Opposite)) == 0) { msInUse = msOpp; posInUse = Pos.AddCopy(blockScs.Orientation.Opposite); structureComplete = true; } if (beforeReceiveHeat != receivesHeat || beforeStructureComplete != structureComplete) { MarkDirty(); } if (receivesHeat) { if (!structureComplete) { return; } double hoursPassed = Api.World.Calendar.TotalHours - totalHoursLastUpdate; double heatHoursReceived = Math.Max(0, Math.Min(hoursPassed, Math.Min(leftHeatHoursLeft, rightHeatHoursLeft))); progress += heatHoursReceived / 160f; totalHoursLastUpdate = Api.World.Calendar.TotalHours; MarkDirty(); } if (progress >= 1.0) { int stacksize = inv[1].Itemstack.StackSize; JsonItemStack jstack = inv[1].Itemstack.ItemAttributes?["carburizableProps"]["carburizedOutput"].AsObject <JsonItemStack>(null, Block.Code.Domain); if (jstack.Resolve(Api.World, "carburizable output")) { inv[0].Itemstack.StackSize -= 8; inv[1].Itemstack = jstack.ResolvedItemstack.Clone(); inv[1].Itemstack.StackSize = stacksize; } MarkDirty(); msInUse.WalkMatchingBlocks(Api.World, posInUse, (block, pos) => { float resis = block.Attributes?["heatResistance"].AsFloat(1) ?? 1; if (Api.World.Rand.NextDouble() > resis) { Block nowblock = Api.World.GetBlock(block.CodeWithVariant("state", "damaged")); Api.World.BlockAccessor.SetBlock(nowblock.Id, pos); } }); processComplete = true; } }