Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • How would i register a tile entity using deferred register
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
FOGC123

How would i register a tile entity using deferred register

By FOGC123, April 15, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 15, 2020

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);
    }

}

 

  • Quote

Share this post


Link to post
Share on other sites

Ugdhar    232

Ugdhar

Ugdhar    232

  • World Shaper
  • Ugdhar
  • Members
  • 232
  • 2215 posts
Posted April 15, 2020

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.

  • Quote

Share this post


Link to post
Share on other sites

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 15, 2020 (edited)

 a

Edited April 15, 2020 by FOGC123
  • Quote

Share this post


Link to post
Share on other sites

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 15, 2020
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)'

  • Quote

Share this post


Link to post
Share on other sites

Ugdhar    232

Ugdhar

Ugdhar    232

  • World Shaper
  • Ugdhar
  • Members
  • 232
  • 2215 posts
Posted April 15, 2020

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.

  • Quote

Share this post


Link to post
Share on other sites

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 15, 2020
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

  • Quote

Share this post


Link to post
Share on other sites

Ugdhar    232

Ugdhar

Ugdhar    232

  • World Shaper
  • Ugdhar
  • Members
  • 232
  • 2215 posts
Posted April 15, 2020
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. :)

 

  • Quote

Share this post


Link to post
Share on other sites

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 15, 2020
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

 

 

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted April 15, 2020

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

  • Quote

Share this post


Link to post
Share on other sites

FOGC123    0

FOGC123

FOGC123    0

  • Tree Puncher
  • FOGC123
  • Members
  • 0
  • 18 posts
Posted April 20, 2020
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!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • JayNeedsHelp
      Logger not working

      By JayNeedsHelp · Posted 16 minutes ago

      So I'm currently creating a forge mod and I'm having an issue where the console stops logging after some errors. It seems to be connected to the access transformers that I'm using as before I added at's my console was working fine.   Here is my at file:  public-f net.minecraft.client.Minecraft session public net.minecraft.client.Minecraft timer public net.minecraft.client.gui.GuiScreen buttonList public net.minecraft.util.Timer tickLength public net.minecraft.network.play.client.CPacketPlayer onGround public net.minecraft.network.play.server.SPacketEntityVelocity motionX public net.minecraft.network.play.server.SPacketEntityVelocity motionY public net.minecraft.network.play.server.SPacketEntityVelocity motionZ public net.minecraft.network.play.server.SPacketExplosion motionX public net.minecraft.network.play.server.SPacketExplosion motionY public net.minecraft.network.play.server.SPacketExplosion motionZ public net.minecraft.client.renderer.entity.RenderManager renderPosX public net.minecraft.client.renderer.entity.RenderManager renderPosY public net.minecraft.client.renderer.entity.RenderManager renderPosZ   Any help is greatly appreciated thank you!
    • cadbane86140
      Minecraft: Hunger Games Game #36- Shear FIGHT!

      By cadbane86140 · Posted 1 hour ago

      Hello There! Today we are back on Hunger Games after a little break but we are finally back! In this episode we are on the good ol' map Survival Games 4 and it ACTUALLY went well for once. Also we have so many great battles on rooftops, small rooms and just out in the open! We also use shears to fight at one point and that was pretty crazy! There are so many hilarious moments in this episode that I know you guys are gonna love! I hope you all enjoy this video and if you did don't forget to like and sub for more Hunger Games in the future!  
    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted 1 hour ago

      latest.log
    • diesieben07
      Game crashes whenever I try to increase the RAM

      By diesieben07 · Posted 2 hours ago

      In the logs folder of your game directory.
    • Unusualty
      GUI'S and player editing

      By Unusualty · Posted 2 hours ago

      So I'm trying to make a mod that is inspired by Origin's because this mod isn't for forge I was wondering if anyone can help me do something like this where you get a GUI when you join the world where you can select a race that has abilities and down sides to them, I also want to have classes but first I want these race's done so if anyone can help this would be appreciated.
  • Topics

    • JayNeedsHelp
      0
      Logger not working

      By JayNeedsHelp
      Started 17 minutes ago

    • cadbane86140
      0
      Minecraft: Hunger Games Game #36- Shear FIGHT!

      By cadbane86140
      Started 1 hour ago

    • Sad Whale
      6
      Game crashes whenever I try to increase the RAM

      By Sad Whale
      Started 3 hours ago

    • Unusualty
      0
      GUI'S and player editing

      By Unusualty
      Started 2 hours ago

    • fluiX
      1
      server wont start

      By fluiX
      Started 3 hours ago

  • Who's Online (See full list)

    • Chumbanotz
    • _Traficantefav_
    • Lyon
    • JayNeedsHelp
    • PyRoTheLifeLess
    • Beethoven92
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • How would i register a tile entity using deferred register
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community