Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted
package com.SkyWarsFun2019.moreblock.init;

import java.util.function.Supplier;

import com.SkyWarsFun2019.moreblock.RandomFhings;
import com.SkyWarsFun2019.moreblock.blockentity.StorageBlockEntity;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModBlockEntity 
{
	public static DeferredRegister<BlockEntityType<?>> BLOCK_ENTITYS = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, RandomFhings.MOD_ID);

	public static RegistryObject<BlockEntityType<StorageBlockEntity>> CHEST = register("storage", StorageBlockEntity::new, () -> new Block[] {}); 
	
	public static void register(IEventBus bus)
	{
		BLOCK_ENTITYS.register(bus);
	}
	
	private static <T extends BlockEntity> RegistryObject<BlockEntityType<T>> register(String name, BlockEntityType.BlockEntitySupplier<T> supplier, Supplier<Block[]> validBlocksSupplier)
    {
        return BLOCK_ENTITYS.register(name, () -> BlockEntityType.Builder.of(supplier, validBlocksSupplier.get()).build(null));
    }

}

This is my registry class so far however the error reported is as follows. The type StorageBlockEntity does not define StorageBlockEntity(BlockPos, BlocState) that is applicable here

package com.SkyWarsFun2019.moreblock.blockentity;

import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public class StorageBlockEntity extends StorageBlockEntityBase {

	public StorageBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState)
	{
		super(pType, pWorldPosition, pBlockState);
	}

	@Override
	public int getContainerSize() 
	{
		return 27;
	}

	@Override
	protected Component getDefaultName()
	{
		return new TranslatableComponent("container.mbs.storage");
	}

	@Override
	protected AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory)
	{
		return new ChestMenu(MenuType.GENERIC_9x3, pContainerId, pInventory, pInventory, pContainerId);
	}

}

That is the BlockEntity Class that im trying to register however its super class is below

package com.SkyWarsFun2019.moreblock.blockentity;

import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public abstract class StorageBlockEntityBase extends RandomizableContainerBlockEntity
{
	protected NonNullList<ItemStack> items;

	public StorageBlockEntityBase(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) 
	{
		super(pType, pWorldPosition, pBlockState);
		this.items = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
	}

	public boolean isMatchingContainerMenu(AbstractContainerMenu menu)
    {
        return menu instanceof ChestMenu chestMenu && chestMenu.getContainer() == this;
    }
	
	@Override
	public abstract int getContainerSize();

	@Override
	protected NonNullList<ItemStack> getItems()
	{
		return items;
	}

	@Override
	protected void setItems(NonNullList<ItemStack> pItemStacks)
	{
		this.items = pItemStacks;
	}

	@Override
	protected abstract Component getDefaultName();
	
	@Override
	protected abstract AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory);
	
	@Override
	public boolean canPlaceItem(int pIndex, ItemStack pStack)
	{
		return true;
	}
	
	public boolean isFull()
    {
        for(ItemStack stack : this.items)
        {
            if(stack.isEmpty())
            {
                return false;
            }
        }
        return true;
    }
	
	protected boolean addItem(ItemStack stack)
    {
        for(int i = 0; i < this.getContainerSize(); i++)
        {
            if(this.getItem(i).isEmpty())
            {
                this.setItem(i, stack);
                return true;
            }
        }
        return false;
    }
	//NBT
	@Override
	public CompoundTag save(CompoundTag pCompound)
	{
		
		super.save(pCompound);
		if(!this.trySaveLootTable(pCompound))
        {
            ContainerHelper.saveAllItems(pCompound, this.items);
        }
        return pCompound;
	}
	@Override
	public void load(CompoundTag pTag)
	{
		super.load(pTag);
		this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
        if(!this.tryLoadLootTable(pTag))
        {
            ContainerHelper.loadAllItems(pTag, this.items);
        }
	}
}

Any help is greatly appreciated.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.