Jump to content

Container size 41 is smaller than expected 45


Zaksen

Recommended Posts

I make a crate that need to have 45 but when i try open it, he not opening. in logs he sand like Container size 41 is smaller than expected 45

GoldCrate

Spoiler
package com.zaksen.fancydecorativeblocks.blocks;

import com.zaksen.fancydecorativeblocks.FancyBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

import java.util.Random;

public class GoldCrate extends BaseEntityBlock {

    public GoldCrate() {
        super(Properties.of(Material.METAL).sound(SoundType.METAL).destroyTime(1f).explosionResistance(2f));
    }

    @Override
    public InteractionResult use(BlockState BState, Level Level, BlockPos BPos, Player P, InteractionHand Hand, BlockHitResult Result) {
        if(!Level.isClientSide)
        {
            BlockEntity entity = Level.getBlockEntity(BPos);
            if(entity instanceof GoldCrateEntity)
            {
                NetworkHooks.openGui(((ServerPlayer)P), (GoldCrateEntity)entity, BPos);
            }
            else
            {
                throw new IllegalStateException("Container provider is missing!");
            }
        }
        return InteractionResult.sidedSuccess(Level.isClientSide());
    }

    @Override
    public void tick(BlockState BState, ServerLevel Level, BlockPos BPos, Random Rand) {
        super.tick(BState, Level, BPos, Rand);
    }

    @Override
    public void onRemove(BlockState BState, Level Level, BlockPos BPos, BlockState BState2, boolean bool) {
        if(BState.getBlock() != BState2.getBlock())
        {
            BlockEntity blockEntity = Level.getBlockEntity(BPos);
            if(blockEntity instanceof GoldCrateEntity)
            {
                ((GoldCrateEntity) blockEntity).drops();
            }
        }
        super.onRemove(BState, Level, BPos, BState2, bool);
    }

    @Override
    public RenderShape getRenderShape(BlockState BState) {
        return RenderShape.MODEL;
    }

    @Nullable
    @Override
    public BlockEntity newBlockEntity(BlockPos BPos, BlockState BState) {
        return new GoldCrateEntity(BPos, BState);
    }

    @Nullable
    @Override
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level Level, BlockState BState, BlockEntityType<T> BlockEntity) {
        return createTickerHelper(BlockEntity, FancyBlockEntities.GOLD_CRATE.get(), GoldCrateEntity::tick);
    }
}

 

GoldCrateEntity
 

Spoiler
package com.zaksen.fancydecorativeblocks.blocks;

import com.zaksen.fancydecorativeblocks.FancyBlockEntities;
import com.zaksen.fancydecorativeblocks.screen.GoldCrateMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class GoldCrateEntity extends BaseStorageEntityBlock{
    public GoldCrateEntity(BlockPos BPos, BlockState BState) {
        super(FancyBlockEntities.GOLD_CRATE.get(), BPos, BState, 45, "Gold Crate");
    }

    @Override
    public @Nullable AbstractContainerMenu createMenu(int ContainerId, Inventory Inv, Player P) {
        return new GoldCrateMenu(ContainerId, Inv, this);
    }
}

 

GoldCrateMenu
 

Spoiler
package com.zaksen.fancydecorativeblocks.screen;

import com.zaksen.fancydecorativeblocks.FancyBlocks;
import com.zaksen.fancydecorativeblocks.blocks.GoldCrateEntity;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class GoldCrateMenu extends AbstractContainerMenu {
    private final GoldCrateEntity blockEntity;
    private final Level level;

    protected GoldCrateMenu(int ContrainerId, Inventory Inv, FriendlyByteBuf extraData) {
        this(ContrainerId, Inv, Inv.player.level.getBlockEntity(extraData.readBlockPos()));
    }

    public GoldCrateMenu(int ContrainerId, Inventory Inv, BlockEntity entity) {
        super(FancyMenuTypes.GOLD_CRATE_MENU.get(), ContrainerId);
        checkContainerSize(Inv,45);
        blockEntity = ((GoldCrateEntity) entity);
        this.level = Inv.player.level;

        addPlayerInventory(Inv);
        addPlayerHotbar(Inv);

        this.blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(iItemHandler -> {
            this.addSlot(new SlotItemHandler(iItemHandler, 0, 8, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 1, 26, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 2, 44, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 3, 62, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 4, 80, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 5, 98, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 6, 116, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 7, 134, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 8, 152, 18));
            this.addSlot(new SlotItemHandler(iItemHandler, 9, 8, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 10, 26, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 11, 44, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 12, 62, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 13, 80, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 14, 98, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 15, 116, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 16, 134, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 17, 152, 36));
            this.addSlot(new SlotItemHandler(iItemHandler, 18, 8, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 19, 26, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 20, 44, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 21, 62, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 22, 80, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 23, 98, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 24, 116, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 25, 134, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 26, 152, 54));
            this.addSlot(new SlotItemHandler(iItemHandler, 27, 8, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 28, 26, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 29, 44, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 30, 62, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 31, 80, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 32, 98, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 33, 116, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 34, 134, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 35, 152, 72));
            this.addSlot(new SlotItemHandler(iItemHandler, 36, 8, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 37, 26, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 38, 44, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 39, 62, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 40, 80, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 41, 98, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 42, 116, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 43, 134, 90));
            this.addSlot(new SlotItemHandler(iItemHandler, 44, 152, 90));
        });
    }

    @Override
    public boolean stillValid(Player P) {
        return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), P, FancyBlocks.GOLD_CRATE.get());
    }

    private void addPlayerInventory(Inventory playerInv)
    {
        for(int i = 0; i < 3; ++i)
        {
            for(int l = 0; l < 9; ++l)
            {
                this.addSlot(new Slot(playerInv, l + i * 9 + 9, 8 + l * 18, 84 + i * 18));
            }
        }
    }

    private void addPlayerHotbar(Inventory playerInventory)
    {
        for(int i = 0; i < 9; ++i)
        {
            this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
        }
    }

    private static final int HOTBAR_SLOT_COUNT = 9;
    private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
    private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
    private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
    private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
    private static final int VANILLA_FIRST_SLOT_INDEX = 0;
    private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
    private static final int TE_INVENTORY_SLOT_COUNT = 45;

    @Override
    public ItemStack quickMoveStack(Player p, int index)
    {
        Slot sourceSlot = slots.get(index);
        if(sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY;
        ItemStack sourceStack = sourceSlot.getItem();
        ItemStack copyOfSourceStack = sourceStack.copy();

        if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT)
        {
            // This is a vanilla container slot so merge the stack into the tile inventory
            if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false))
            {
                return ItemStack.EMPTY;  // EMPTY_ITEM
            }
        }
        else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT)
        {
            // This is a TE slot so merge the stack into the players inventory
            if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else
        {
            System.out.println("Invalid Slot Index: " + index);
            return ItemStack.EMPTY;
        }

        if(sourceStack.getCount() == 0)
        {
            sourceSlot.set(ItemStack.EMPTY);
        }
        else
        {
            sourceSlot.setChanged();
        }
        sourceSlot.onTake(p, sourceStack);
        return copyOfSourceStack;
    }
}

 

GoldCrateSreen
 

Spoiler
package com.zaksen.fancydecorativeblocks.screen;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.zaksen.fancydecorativeblocks.FancyDecorativeBlocks;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class GoldCrateScreen extends AbstractContainerScreen<GoldCrateMenu> {
    private static final ResourceLocation TEXTURE = new ResourceLocation(FancyDecorativeBlocks.MOD_ID, "textures/gui/gold_crate_gui.png");

    public GoldCrateScreen(GoldCrateMenu Menu, Inventory Inv, Component Title) {
        super(Menu, Inv, Title);
    }

    @Override
    protected void renderBg(PoseStack PoseStack, float PartialTick, int MouseX, int MouseY) {
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.setShaderTexture(0, TEXTURE);
        imageWidth = 176;
        imageHeight = 202;
        titleLabelX = 8;
        titleLabelY = -22;
        inventoryLabelX = 8;
        inventoryLabelY = 94;
        int x = (width - imageWidth) / 2;
        int y = (height - imageHeight) / 2;

        this.blit(PoseStack, x, y, 0, 0, imageWidth, imageHeight);
    }

    @Override
    public void render(PoseStack PoseStack, int MouseX, int MouseY, float Delata)
    {
        renderBackground(PoseStack);
        super.render(PoseStack, MouseX, MouseY, Delata);
        renderTooltip(PoseStack, MouseX, MouseY);
    }
}

 

if you need there is Github Repo:
https://github.com/zaDR0tic/FancyDecorativeBlocks

Edited by Zaksen
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • 배방오피 ♣BCGAME88·COM▼ 숭인오피 연건오피 충정오피 항동오피 olg03 역삼오피 파주오피 정읍오피 시흥오피 otp16 계동오피 문래오피 과천오피 충정오피 jrw28 서교오피 창전오피 장안오피 신정오피 cyf67 창천오피 가리봉오피 공덕오피 동빙고오피 jfy28 재동오피 청파오피 송월오피 정동오피 brp94 자곡오피 산방오피 포항오피 장사오피 vew34 통의오피 삼성오피 경운오피 수송오피 mda46 제기오피 삼각오피 창동오피 창신오피 fyp00 세곡오피 마곡오피 번동오피 삼선오피 cxc89 거여오피 광명오피 도렴오피 홍성오피 rqi56 양산오피 본동오피 의정부오피 청암오피 fho71 본동오피 화양오피 돈의오피 수유오피 vfb96 영천오피 개포오피 통의오피 사천오피 sum32 용산오피 신내오피 세종오피 권농오피 ytr85 서빙고오피 온수오피 삼성오피 관악오피 vmp10 중학오피 미근오피 중구오피 도화오피 tjd18 도곡오피 삼척오피 청량리오피 청파오피 fvi88 남산오피 서린오피 서초오피 남양주오피 lxy59 대치오피 응봉오피 상일오피 사천오피 ovk61 예지오피 가리봉오피 을지오피 본동오피 hiy53 강서오피 저동오피 현저오피 홍성오피 uuy30 을지오피 화곡오피 도화오피 의정부오피 ssq94
    • 서초핸플 ▥BCGAME88·COM▣ 수유핸플 신설핸플 세곡핸플 동선핸플 sap96 산방핸플 광명핸플 남산핸플 봉천핸플 jjx32 녹번핸플 이천핸플 도원핸플 광장핸플 dwt78 부천핸플 홍성핸플 풍납핸플 여의도핸플 vbw74 도화핸플 옥수핸플 가양핸플 서린핸플 kmk23 양산핸플 상일핸플 창성핸플 청담핸플 hfp17 신월핸플 명륜핸플 장위핸플 공평핸플 hai67 익산핸플 해남핸플 서빙고핸플 중동핸플 pjf38 오쇠핸플 마곡핸플 묵동핸플 안성핸플 ssc74 신문핸플 독산핸플 천왕핸플 오곡핸플 rox80 원효핸플 서계핸플 여주핸플 봉래핸플 eyd00 신도림핸플 양재핸플 수하핸플 율현핸플 bvx86 광명핸플 하왕십리핸플 본동핸플 노량진핸플 fgk83 구로핸플 대방핸플 충무핸플 문배핸플 rew93 춘천핸플 파주핸플 파주핸플 냉천핸플 ynn17 외발산핸플 가산핸플 광장핸플 광명핸플 pfq23 용인핸플 망원핸플 부여핸플 전주핸플 ebk12 남산핸플 연남핸플 옥수핸플 잠원핸플 hvg94 서린핸플 남창핸플 동숭핸플 신정핸플 sfv72 염리핸플 창신핸플 서귀포핸플 문정핸플 cke94 군자핸플 장충핸플 광명핸플 장위핸플 env09 공주핸플 삼선핸플 안양핸플 수유핸플 pkw41 재동핸플 이촌핸플 예장핸플 태평로핸플 jst84
    • 신림핸플 ◎BCGAME88·COM㈜ 삼성핸플 율현핸플 하월곡핸플 천연핸플 wgc72 서산핸플 문경핸플 의정부핸플 천왕핸플 bqt89 강서핸플 개포핸플 서귀포핸플 대흥핸플 uli33 수송핸플 현석핸플 관훈핸플 신월핸플 vou88 길음핸플 여주핸플 동해핸플 화곡핸플 obq08 만리핸플 여의도핸플 북가좌핸플 고척핸플 qsj98 의왕핸플 궁동핸플 이천핸플 산천핸플 fpp94 칠곡핸플 부천핸플 노고산핸플 화곡핸플 dbn35 오류핸플 안국핸플 태평핸플 봉래핸플 ebx84 독산핸플 원서핸플 부여핸플 광주핸플 lnl96 전주핸플 암사핸플 장지핸플 포천핸플 rnp71 누상핸플 석촌핸플 신대방핸플 장위핸플 btg32 금산핸플 창원핸플 이천핸플 안성핸플 jlx30 화방핸플 잠원핸플 내수핸플 군포핸플 ugf84 시흥핸플 당산핸플 창녕핸플 오산핸플 pao94 장지핸플 창녕핸플 내수핸플 광양핸플 yyk93 광양핸플 돈암핸플 서소문핸플 장지핸플 nmt12 삼청핸플 강동핸플 신창핸플 구리핸플 igb21 온수핸플 대현핸플 망우핸플 마장핸플 amb86 의왕핸플 예지핸플 영주핸플 문경핸플 lqd37 도선핸플 울산핸플 장지핸플 의왕핸플 lem56 당주핸플 토정핸플 수서핸플 광주핸플 usp20 개포핸플 세종로핸플 상봉핸플 포천핸플 vri76
    • 남현출장건마 ☎BCGAME88·COM◎ 서대문출장건마 우면출장건마 경주출장건마 안양출장건마 cvc40 소공출장건마 나주출장건마 을지출장건마 동숭출장건마 cgm82 정동출장건마 강서출장건마 세곡출장건마 은평출장건마 pgo25 북창출장건마 안양출장건마 상봉출장건마 누상출장건마 biy58 상도출장건마 마천출장건마 자양출장건마 문래출장건마 tru32 연건출장건마 구리출장건마 합동출장건마 성북출장건마 bud40 정읍출장건마 공항출장건마 대치출장건마 회기출장건마 gay08 만리출장건마 천연출장건마 우면출장건마 을지출장건마 byu28 대치출장건마 성내출장건마 신사출장건마 도곡출장건마 gkr76 김해출장건마 서귀포출장건마 당진출장건마 석관출장건마 inb22 오쇠출장건마 고척출장건마 구의출장건마 하중출장건마 riq70 부천출장건마 예장출장건마 전농출장건마 숭인출장건마 ihy64 청운출장건마 여주출장건마 염창출장건마 충주출장건마 wbm00 고흥출장건마 풍납출장건마 필운출장건마 의정부출장건마 sar13 용문출장건마 마천출장건마 한강출장건마 영주출장건마 iap88 하왕십리출장건마 동교출장건마 무학출장건마 청주출장건마 aps39 장위출장건마 인현출장건마 여주출장건마 신월출장건마 wjc98 묵동출장건마 대흥출장건마 송월출장건마 마포출장건마 wxl11 팔판출장건마 문배출장건마 광명출장건마 장사출장건마 brn33 주성출장건마 창성출장건마 월계출장건마 세곡출장건마 esg46 우이출장건마 광주출장건마 도렴출장건마 대흥출장건마 lnm42 하남출장건마 예장출장건마 안암출장건마 풍납출장건마 gpf63 천왕출장건마 광양출장건마 통인출장건마 갈월출장건마 qxy56
    • 봉천미팅 ▦BCGAME88·COM♠ 영천미팅 문래미팅 을지미팅 성구미팅 ryu82 갈월미팅 잠실미팅 충신미팅 김해미팅 akt84 서초미팅 서초미팅 양주미팅 도원미팅 mqa98 관악미팅 행당미팅 정릉미팅 우이미팅 jsp86 무안미팅 양주미팅 휘경미팅 재동미팅 jms67 입정미팅 역촌미팅 신대방미팅 제주미팅 goy30 연지미팅 나주미팅 당산미팅 창전미팅 ptg52 누하미팅 도곡미팅 도곡미팅 수서미팅 vos68 내수미팅 여주미팅 관수미팅 안양미팅 qtx41 도렴미팅 신수미팅 개봉미팅 도선미팅 ryu24 평동미팅 청담미팅 오쇠미팅 구미미팅 bca46 완주미팅 권농미팅 군포미팅 신사미팅 txc05 화방미팅 강남미팅 청담미팅 체부미팅 uje30 하중미팅 홍익미팅 독산미팅 신원미팅 suq45 선릉미팅 전주미팅 해남미팅 정릉미팅 fqf46 이촌미팅 울산미팅 소공미팅 양화미팅 tab30 제주미팅 봉천미팅 개포미팅 번동미팅 wgs45 성구미팅 쌍문미팅 경운미팅 선릉미팅 enu29 화성미팅 안암미팅 상주미팅 세곡미팅 qnh58 군포미팅 구산미팅 서초미팅 개봉미팅 lkg60 동선미팅 회현미팅 강동미팅 영등포미팅 wfj38 소공미팅 황학미팅 천연미팅 하왕십리미팅 lso59 하월곡미팅 율현미팅 옥천미팅 구기미팅 uwc49
  • Topics

×
×
  • Create New...

Important Information

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