Jump to content

Recommended Posts

Posted

Hey Guys,

i'm trying to create an entity which has it's own inventory and a openable container.

The entity breaks blocks and put the drops into the inventory.

Upgrades and food impact the breaking speed and the drops from the entity.

The container should look like this:

Spoiler

Screenshot-2022-01-29-131207.png

red -> Player Inventory

Blue -> Entity Inventory (Players can only take items from it but can't put items into it)

Brown -> Entity Food Slot (only items with a `minion_food` tag)

Yellow -> Special Upgrade Slot (only items with a `minon_special_upgrade` tag)

Green -> Upgrade Slot (only items with a `minon_upgrade` tag)

I already created an Entity which can break and place blocks but i got no idea how to add such an inventory / container to my entity.

 

How can i create such an container / inventory?

Posted

you can simply create a new instance and store it in a final field,
then override addAdditionalSaveData and readAdditionalSaveData to serialize and deserialize the Inventory

  • Thanks 1
Posted

Hi!

You can use

player.openMenu

and give it a new SimpleMenuProvider with your MenuConstructor and the name of the entity

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

If you don't have a MenuConstructor you can make a new one and give it a ChestMenu with your Items in the createMenu function, but this only work if you have an Inventory with the same slots as a MenuType (3*3 Slots, 9*1 Slots, 9*2 Slots, 9*3 Slots ... 9*6 Slots)

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

I got the container class:

public class MinerMinionMenu extends AbstractContainerMenu {
    private final InvWrapper playerInvWrapper;
    private final ItemStackHandler minionInventory;
    private final MinerEntity minerEntity;

    public MinerMinionMenu(int pContainerId, Inventory inventory, MinerEntity minerEntity) {
        super(SkyblockRegistries.container.minerMinionMenu.get(), pContainerId);
        this.playerInvWrapper = new InvWrapper(inventory);
        this.minionInventory = minerEntity.getInventory();
        this.minerEntity = minerEntity;
    }

    @Override
    public boolean stillValid(Player pPlayer) {
        return false;
    }
}

and register it using

    public static final RegistryObject<MenuType<MinerMinionMenu>> minerMinionMenu = registry.register("miner_minion_menu", () -> IForgeMenuType.create(
        (windowId, inv, data) -> {
            Entity entity = Skyblock.getProxy().getLevel().getEntity(data.readInt());

            if (entity instanceof MinerEntity minerEntity) {
                return new MinerMinionMenu(windowId, inv, minerEntity);
            } else {
                throw new IllegalStateException("Tried to open a miner minion inventory with a non miner minion entity!");
            }
        }));

but how do i provide the extra data (the entity Id) to open the container?

Posted
3 minutes ago, diesieben07 said:

You already do exactly that in your IForgeMenuType

but when i try to open the menu i'll get a NPE because `data` is null. I'm trying to open the menu using:

        pPlayer.openMenu(new SimpleMenuProvider((pContainerId, pInventory, pPlayer1) -> {

            return SkyblockRegistries.container.minerMinionMenu.get().create(pContainerId, pPlayer1.getInventory());
        }, getCustomName()));

 

 

Posted
4 minutes ago, diesieben07 said:

You must use NetworkHooks.openGui

Okay i'm using 

        if (pPlayer instanceof ServerPlayer serverPlayer) {
            NetworkHooks.openGui(serverPlayer, new SimpleMenuProvider((pContainerId, pInventory, pPlayer1) -> {
                return SkyblockRegistries.container.minerMinionMenu.get().create(pContainerId, pPlayer1.getInventory());
            }, getCustomName()), buf -> buf.writeInt(getId()));
        }

in my entity class now but i'm still running into the NPE

Posted (edited)
1 minute ago, diesieben07 said:

Those 4 slots are used for special items which are present in all types of my entity.

I thought it's easier to always add them to the amount of slots, the entity has as inventory space instead of always remembering to add them.

Edited by Skyriis
  • 2 weeks later...
Posted

i ran into a new problem on the same thing... shift-clicking a item in the player inventory results into a game freeze without any error message. :S

any ideas what could cause such a behavior?

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



×
×
  • Create New...

Important Information

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