Beispiel #1
0
        public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil)
        {
            if (!CanWork(stack))
            {
                return(null);
            }

            Item item = api.World.GetItem(new AssetLocation("workitem-" + Variant["metal"]));

            if (item == null)
            {
                return(null);
            }

            ItemStack workItemStack = new ItemStack(item);

            workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack));

            if (beAnvil.WorkItemStack == null)
            {
                CreateVoxelsFromIngot(api, ref beAnvil.Voxels, isBlisterSteel);
            }
            else
            {
                if (isBlisterSteel)
                {
                    return(null);
                }

                IAnvilWorkable workable = beAnvil.WorkItemStack.Collectible as IAnvilWorkable;

                if (!workable.GetBaseMaterial(beAnvil.WorkItemStack).Equals(api.World, GetBaseMaterial(stack), GlobalConstants.IgnoredStackAttributes))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        (api as ICoreClientAPI).TriggerIngameError(this, "notequal", Lang.Get("Must be the same metal to add voxels"));
                    }
                    return(null);
                }

                AddVoxelsFromIngot(api, ref beAnvil.Voxels);
            }

            return(workItemStack);
        }
Beispiel #2
0
        private bool TryPut(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Itemstack == null)
            {
                return(false);
            }

            ItemStack      stack       = slot.Itemstack;
            IAnvilWorkable workableobj = stack.Collectible as IAnvilWorkable;

            if (workableobj == null)
            {
                return(false);
            }
            int requiredTier = workableobj.GetRequiredAnvilTier(stack);

            if (requiredTier > OwnMetalTier)
            {
                if (world.Side == EnumAppSide.Client)
                {
                    (Api as ICoreClientAPI).TriggerIngameError(this, "toolowtier", Lang.Get("Working this metal needs a tier {0} anvil", requiredTier));
                }

                return(false);
            }

            ItemStack newWorkItemStack = workableobj.TryPlaceOn(stack, this);

            if (newWorkItemStack != null)
            {
                if (workItemStack == null)
                {
                    workItemStack = newWorkItemStack;
                    rotation      = workItemStack.Attributes.GetInt("rotation");
                }

                if (SelectedRecipeId < 0)
                {
                    var list = workableobj.GetMatchingRecipes(stack);
                    if (list.Count == 1)
                    {
                        SelectedRecipeId = list[0].RecipeId;
                    }
                    else
                    {
                        if (world.Side == EnumAppSide.Client)
                        {
                            OpenDialog(stack);
                        }
                    }
                }

                returnOnCancelStack = slot.TakeOut(1);
                slot.MarkDirty();

                if (Api.Side == EnumAppSide.Server)
                {
                    // Let the server decide the shape, then send the stuff to client, and then show the correct voxels
                    // instead of the voxels flicker thing when both sides do it (due to voxel placement randomness in iron bloom and blister steel)
                    RegenMeshAndSelectionBoxes();
                }

                CheckIfFinished(byPlayer);
                MarkDirty();
                return(true);
            }


            return(false);
        }