Jump to content

[1.12.2] My custom crafting table inventory is working odd


Triphion

Recommended Posts

I have everything handled and in order for this to work, and everything does work, except for the inventory. When i click on some slots and/or items in the inventory, they move to other places inside the inventory or duplicates or something else. I have no idea why this happens and would very much appreciate some help here. 

The block:

Quote

public class BlockCyclopsSmithy extends BlockBase
{
    public BlockCyclopsSmithy(String unlocalizedName, Material materialIn) 
    {
        super(unlocalizedName, materialIn);
        this.setSoundType(SoundType.STONE);
        this.setDefaultState(this.blockState.getBaseState());
    }
    
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
    {
        if(worldIn.isRemote)
        {
            playerIn.openGui(MainClass.instance, MainClass.GUI_ENUM.CYCLOPS_SMITHY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
        
        return true;
    }

The Container:

Quote

public class ContainerCyclopsSmithy extends Container
{
    /** The crafting matrix inventory (3x3). */
    public InventoryCrafting craftMatrix = new InventoryCyclopsSmithy(this, 3, 3);
    public InventoryCraftResult craftResult = new InventoryCraftResult();
    private final World world;
    /** Position of the workbench */
    private final BlockPos pos;
    private final EntityPlayer player;
    
    public ContainerCyclopsSmithy(InventoryPlayer playerInventory, World parWorld, BlockPos posIn) 
    {
               this.world = parWorld;
            this.pos = posIn;
            this.player = playerInventory.player;
            this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
                }
            }

            for (int k = 0; k < 3; ++k)
            {
                for (int i1 = 0; i1 < 9; ++i1)
                {
                    this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
                }
            }

            for (int l = 0; l < 9; ++l)
            {
                this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
            }
     }

        /**
         * Callback for when the crafting matrix is changed.
         */
        public void onCraftMatrixChanged(IInventory inventoryIn)
        {
            this.slotChangedCraftingGrid(this.world, this.player, this.craftMatrix, this.craftResult);
        }

        /**
         * Called when the container is closed.
         */
        public void onContainerClosed(EntityPlayer playerIn)
        {
            super.onContainerClosed(playerIn);

            if (!this.world.isRemote)
            {
                this.clearContainer(playerIn, this.world, this.craftMatrix);
            }
        }

        /**
         * Determines whether supplied player can use this container
         */
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            if (this.world.getBlockState(this.pos).getBlock() != EtauricBlocks.CYCLOPS_SMITHY)
            {
                return false;
            }
            else
            {
                return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
            }
        }

        /**
         * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
         * inventory and the other inventory(s).
         */
        public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
        {
            ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);

            if (slot != null && slot.getHasStack())
            {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();

                if (index == 0)
                {
                    itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);

                    if (!this.mergeItemStack(itemstack1, 10, 46, true))
                    {
                        return ItemStack.EMPTY;
                    }

                    slot.onSlotChange(itemstack1, itemstack);
                }
                else if (index >= 10 && index < 37)
                {
                    if (!this.mergeItemStack(itemstack1, 37, 46, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (index >= 37 && index < 46)
                {
                    if (!this.mergeItemStack(itemstack1, 10, 37, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (!this.mergeItemStack(itemstack1, 10, 46, false))
                {
                    return ItemStack.EMPTY;
                }

                if (itemstack1.isEmpty())
                {
                    slot.putStack(ItemStack.EMPTY);
                }
                else
                {
                    slot.onSlotChanged();
                }

                if (itemstack1.getCount() == itemstack.getCount())
                {
                    return ItemStack.EMPTY;
                }

                ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);

                if (index == 0)
                {
                    playerIn.dropItem(itemstack2, false);
                }
            }

            return itemstack;
        }

        /**
         * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
         * is null for the initial slot that was double-clicked.
         */
        public boolean canMergeSlot(ItemStack stack, Slot slotIn)
        {
            return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
        }

The Inventory:

Quote

public class InventoryCyclopsSmithy extends InventoryCrafting
{
    public InventoryCyclopsSmithy(Container eventHandlerIn, int width, int height) 
    {
        super(eventHandlerIn, width, height);
    }
}

Basically all of it is copy-pasted from the normal workbench, but with my own block instead. 

Edited by Triphion
Link to comment
Share on other sites

2 hours ago, Triphion said:

if(worldIn.isRemote)
        {
            playerIn.openGui(MainClass.instance, MainClass.GUI_ENUM.CYCLOPS_SMITHY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
        }

I think this has to be if(!worldIn.isRemote) 

Because you want to do the following action if the statement is NOT true

 

EDIT: Just checked the workbench class, you should check the onBlockActivated method again.

You forgot an else statement

Edited by winnetrie
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my bad, i shared a very old LOG, now must be the right one, im sorry.
    • Hello TileEntity, thanks for your help, is just that i do not have terraria mod installed, i can give you mi list of mods.   EpicFight-20.7.4.jar handcrafted-forge-1.20.1-3.0.6.jar resourcefullib-forge-1.20.1-2.1.25.jar thedragonlib-1.20.1-1.0.0.jar tameablebeasts-1.20.1-5.1.jar geckolib-forge-1.20.1-4.4.6.jar mythicmounts-20.1-7.4.2-forge.jar Patchouli-1.20.1-84-FORGE.jar morevillagers-forge-1.20.1-5.0.0.jar balm-forge-1.20.1-7.3.4-all.jar trashslot-forge-1.20-15.1.0.jar peacefulrecipes 1.20.jar ferritecore-6.0.1-forge.jar darkmining-forge-1.20.1-1.1.0.jar ParCool-1.20.1-3.2.1.2-R.jar minecolonies-1.20.1-1.1.563-RELEASE.jar towntalk-1.20.1-1.1.0.jar structurize-1.20.1-1.0.733-RELEASE.jar blockui-1.20.1-1.0.156-RELEASE.jar domum_ornamentum-1.20.1-1.0.186-RELEASE-universal.jar multipiston-1.20-1.2.43-RELEASE.jar svmm-1.20.1-1.3.0.3.jar InsaneLib-1.13.5-mc1.20.1.jar Satako-7.0.16-1.20.1.jar Bountiful-6.0.3+1.20.1-forge.jar Kambrik-6.1.1+1.20.1-forge.jar kotlinforforge-4.11.0-all.jar kubejs-forge-2001.6.5-build.7.jar rhino-forge-2001.2.2-build.18.jar superbosses-1.2.0-1.20.1.jar lootjs-forge-1.20.1-2.12.0.jar MobsPropertiesRandomness-4.10.8-mc1.20.1.jar Pehkui-3.8.2+1.20.1-forge.jar lostcities-1.20-7.1.8.jar yuushya-1.20.1-forge-2.1.1.jar architectury-9.2.14-forge.jar artifacts-forge-9.5.11.jar curios-forge-5.9.1+1.20.1.jar cloth-config-11.1.118-forge.jar mcdar-4.0.3.jar mcdw-9.0.4.jar mcda-5.0.2.jar Connector-1.0.0-beta.43+1.20.1.jar ConnectorExtras-1.10.1+1.20.1.jar fabric-api-0.92.2+1.11.8+1.20.1.jar immersive_armors-1.6.1+1.20.1-forge.jar cosmeticarmorreworked-1.20.1-v1a.jar K-Turrets-3.0.25-1.20.1.jar M'TEG-1.0.1-1.20.1.jar JustEnoughGuns-0.4.0-1.20.1.jar framework-forge-1.20.1-0.7.6.jar JustEnoughResources-1.20.1-1.4.0.247.jar modernfix-forge-5.18.1+mc1.20.1.jar corpse-forge-1.20.1-1.0.12.jar randombonemealflowers-1.20.1-4.5.jar collective-1.20.1-7.61.jar treeharvester-1.20.1-8.7.jar ImprovableSkills-1.20.1-20.1.8.jar HammerLib-1.20.1-20.1.30.jar easy_mob_farm_1.20.1-7.1.0.jar easy-piglins-forge-1.20.1-1.0.5.jar easy_villagers-1.20.1-1.0.17.jar the_bumblezone-7.4.5+1.20.1-forge.jar productivebees-1.20.1-12.5.3.jar XaerosWorldMap_1.38.8_Forge_1.20.jar Xaeros_Minimap_24.2.0_Forge_1.20.jar jei-1.20.1-forge-15.3.0.8.jar Rats-1.20.1-8.1.2.jar citadel-2.5.4-1.20.1.jar Animation_Overhaul-forge-1.20.x-1.3.1.jar Necronomicon-Forge-1.4.2.jar invtweaks-1.20.1-1.1.0.jar sophisticatedbackpacks-1.20.1-3.20.5.1044.jar sophisticatedcore-1.20.1-0.6.22.611.jar travelersbackpack-forge-1.20.1-9.1.14.jar BetterThirdPerson-Forge-1.20-1.9.0.jar  
    • ill be asleep by the time you respond so mention like a lot of thing to do so when i wake i can try them
    • it instantly crashes
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.