Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.17.1] BlockEntityType Registry not working as expected


DX12
 Share

Recommended Posts

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Are you using Fabric? I'm not sure if this forum would be the right place then.
    • server failed to start and gives me "Failed to load data packs, can't proceed with server load. You can either fix your data packs or reset to vanilla with --safeMode" error when i look in my logs. its updated to the latest version of forge(40.1.0), and I don't have any data packs installed as far as I know. And I will upload the full logs if asked as i dont know how to attach a document to this post.  
    • Pioneer Craft [modded] {1.18.2} {SMP} {Community} {Light Roleplay} We are Pioneer Craft and we seek you !!! We are building a community of passionate players to build, trade, and share some laughs with. Are you tired of playing alone? Or are you here seeking a server with dedicated members; a server where you are not overlooked and can voice your opinions? If you are interested in these things too, then come join us in Pioneer Craft! Our server is player built and driven. We have a custom mod pack with mods chosen by our community to suit our needs. We have designed our server for player driven roleplay! There will be four communities which will each be self-sufficient. We encourage and seek builders who want to create a beautiful world to live in. This is a whitelist server and we are looking for dedicated applicants and experienced builders. Applications are located on our website which can be accessed through the discord. Other than the application questions, we are requesting photos of your prior builds which will be taken into consideration. Please show photos of your builds in the share-your-work section of the discord. The server uses CurseForge to run. This server is for mature members (16+) . Discord (must join): https://discord.gg/c4uJvb29CN
    • Pioneer Craft [modded] {1.18.2} {SMP} {Community} {Light Roleplay} We are Pioneer Craft and we seek you !!! We are building a community of passionate players to build, trade, and share some laughs with. Are you tired of playing alone? Or are you here seeking a server with dedicated members; a server where you are not overlooked and can voice your opinions? If you are interested in these things too, then come join us in Pioneer Craft! Our server is player built and driven. We have a custom mod pack with mods chosen by our community to suit our needs. We have designed our server for player driven roleplay! There will be four communities which will each be self-sufficient. We encourage and seek builders who want to create a beautiful world to live in. This is a whitelist server and we are looking for dedicated applicants and experienced builders. Applications are located on our website which can be accessed through the discord. Other than the application questions, we are requesting photos of your prior builds which will be taken into consideration. Please show photos of your builds in the share-your-work section of the discord. The server uses CurseForge to run. This server is for mature members (16+) . Discord (must join): https://discord.gg/c4uJvb29CN 
    • Update: I didn't need capabilities. In fact, I didn't need to override applyEffectTick at all. But it seems like I need reflections. The increased hitbox size now works for both entity and block collision--with a little drawback. This is what it looks like so far: // this event handler checks every tick if the living entity has the "big" effect @SubscribeEvent public static void entitySizeChange(LivingEvent.LivingUpdateEvent event) { LivingEntity livingEntity = event.getEntityLiving(); if (livingEntity.getActiveEffectsMap() != null && livingEntity.hasEffect(ModEffects.BIG.get())) { EntityDimensions newDims = livingEntity.getDimensions(livingEntity.getPose()).scale(8.0F, 2.0F); try { // using reflection Field field = Entity.class.getDeclaredField("dimensions"); field.setAccessible(true); field.set(livingEntity, newDims); // setting the living entity's EntityDimensions EntityDimensions newEntityDimensions = (EntityDimensions) field.get(livingEntity); livingEntity.setBoundingBox(newEntityDimensions.makeBoundingBox( // setting the living entity's AABB livingEntity.getX(), livingEntity.getY(), livingEntity.getZ() )); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } } }   The aforementioned drawback is that, when the effect wears off, the living entity's still keeps its bigger hitbox until it changes pose (i.e. my player crouching). Given that the EntityEvent.Size event fires whenever an entity changes pose, should I manually fire it with EVENT_BUS::post when that entity's effect wears off? If so, where? I tried manually firing EntityEvent.Size on my overridden removeAttributeModifiers(), but to no avail. 
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.