Posted April 15, 20205 yr As i said I would like to register a tile entity using deferred register: Code package com.fogc123.randomadditions.tilentities; import com.fogc123.randomadditions.RandomAdditions; import com.fogc123.randomadditions.blocks.ModBlocks; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class ModTileEntities { public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, RandomAdditions.MODID); public static final RegistryObject<TileEntityType<TileEntityWandInfuser>> WAND_INFUSER = TILE_ENTITIES.register("firstblock", () -> TileEntityType.Builder.create(TileEntityWandInfuser::new, ModBlocks.WAND_INFUSER.get()).build(null)); } package com.fogc123.randomadditions.blocks; import com.fogc123.randomadditions.tilentities.ModTileEntities; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import javax.annotation.Nullable; public class BlockWandInfuser extends Block { public BlockWandInfuser() { super(Block.Properties.create(Material.WOOD)); } @Override public boolean hasTileEntity(final BlockState state) { return true; } @Nullable @Override public TileEntity createTileEntity(final BlockState state, final IBlockReader world) { return ModTileEntities.WAND_INFUSER.get().create(); } } package com.fogc123.randomadditions.tilentities; import com.fogc123.randomadditions.blocks.ModBlocks; import com.fogc123.randomadditions.containers.WandInfuserContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.ItemStackHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class TileEntityWandInfuser extends TileEntity implements ITickableTileEntity, INamedContainerProvider { //only one slot for now for testing public static final int BOOK_SLOT = 0; //handles inventory public final ItemStackHandler inventory = new ItemStackHandler(1) { @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { // check if item is valid for slot, just return true for now(all items will be valid) return true; } @Override protected void onContentsChanged(int slot) { //callled everytime contents of inventory is changed super.onContentsChanged(slot); //mark entity dirty so game will save chunk to disc TileEntityWandInfuser.this.markDirty(); System.out.println("Tile Entity Inventory Contents Changed!"); } }; //reduces number of objects i create(more efficient) public final LazyOptional<ItemStackHandler> inventoryCapabilityExternal = LazyOptional.of(() -> this.inventory) public TileEntityWandInfuser(TileEntityType<?> tileEntityTypeIn) { super(tileEntityTypeIn); } @Override public void tick() { //called every tick } @Override public void remove() { super.remove(); inventoryCapabilityExternal.invalidate(); } @Nonnull public CompoundNBT getUpdateTag() { return this.write(new CompoundNBT()); } @Override public ITextComponent getDisplayName() { return new TranslationTextComponent(ModBlocks.WAND_INFUSER.get().); } /** * Called from {@link NetworkHooks#openGui} * (which is called from {@link BlockWandInfuser#onBlockActivated} on the logical server) * * @return The logical-server-side Container for this TileEntity */ @Nullable @Override public Container createMenu(int windowId, PlayerInventory inv, PlayerEntity player) { return new WandInfuserContainer(windowId, inv, this); } }
April 15, 20205 yr You need to register TILE_ENTITIES on the mod event bus, as far as I've seen all deferred registers are usually registered on the mod event bus in the mod constructor.
April 15, 20205 yr Author 35 minutes ago, Ugdhar said: You need to register TILE_ENTITIES on the mod event bus, as far as I've seen all deferred registers are usually registered on the mod event bus in the mod constructor. Sorry i wasnt very clear with my question, I have registered the deferred register on my mod event bus but: "TileEntityType.Builder.create(TileEntityWandInfuser::new, ModBlocks.WAND_INFUSER.get())" still returns error Cannot resolve method 'create(<method reference>, net.minecraftforge.registries.IForgeRegistryEntry)'
April 15, 20205 yr What if you remove the .get() from the ModBlocks.WAND_INFUSER in the builder create call? Looking at an example elsewhere that shows it using the actual supplier and not the Block.
April 15, 20205 yr Author 2 minutes ago, Ugdhar said: What if you remove the .get() from the ModBlocks.WAND_INFUSER in the builder create call? Looking at an example elsewhere that shows it using the actual supplier and not the Block. Didn't seem to work
April 15, 20205 yr 7 minutes ago, FOGC123 said: Didn't seem to work Please post logs and updated code. Code is best shared using a github repo, so even if you forget to share a piece, someone can still look at it.
April 15, 20205 yr Author 57 minutes ago, Ugdhar said: Please post logs and updated code. Code is best shared using a github repo, so even if you forget to share a piece, someone can still look at it. Heres my github link : https://github.com/FOGC123/randomadditions1.15.2
April 15, 20205 yr Hi Just a guess because I haven't used DeferredRegistry yet, but your block doesn't appear to be typed properly? public static final RegistryObject WAND_INFUSER = BLOCKS.register("wand_infuser", () -> new BlockWandInfuser()); i.e. RegistryObject<Block> ? -TGG
April 20, 20205 yr Author On 4/15/2020 at 4:30 PM, TheGreyGhost said: Hi Just a guess because I haven't used DeferredRegistry yet, but your block doesn't appear to be typed properly? public static final RegistryObject WAND_INFUSER = BLOCKS.register("wand_infuser", () -> new BlockWandInfuser()); i.e. RegistryObject<Block> ? -TGG I fixed that but it still returns an error!
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.