Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
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
Posted
12 hours ago, winnetrie said:

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

You forgot an else statement

Thank you Winnetrie! Changed it and it worked. ❤️

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Those are just warnings, probably because those libraries do not contain actual mods, just helper classes or something, hence the missing mods.toml files. You should be fine just ignoring them.
    • [28Jan2025 17:04:56.714] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\{COMPUTER_USERNAME}\AppData\Roaming\ModrinthApp\meta\libraries\net\minecraftforge\fmlcore\1.19.2-43.3.5\fmlcore-1.19.2-43.3.5.jar is missing mods.toml file [28Jan2025 17:04:56.727] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\{COMPUTER_USERNAME}\AppData\Roaming\ModrinthApp\meta\libraries\net\minecraftforge\javafmllanguage\1.19.2-43.3.5\javafmllanguage-1.19.2-43.3.5.jar is missing mods.toml file [28Jan2025 17:04:56.739] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\{COMPUTER_USERNAME}\AppData\Roaming\ModrinthApp\meta\libraries\net\minecraftforge\lowcodelanguage\1.19.2-43.3.5\lowcodelanguage-1.19.2-43.3.5.jar is missing mods.toml file [28Jan2025 17:04:56.751] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\{COMPUTER_USERNAME}\AppData\Roaming\ModrinthApp\meta\libraries\net\minecraftforge\mclanguage\1.19.2-43.3.5\mclanguage-1.19.2-43.3.5.jar is missing mods.toml file
    • thank you! removing imeediatelyfast made it work
    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes, you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Introducing Minezone, home of SUPER CRAFT BLOCKS. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. All the other stuff from Classic/Duels apply to this mode as well like powerups.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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