Jump to content

Recommended Posts

Posted

Hello there!
So i am just starting to dabble my toes into Tile entities seeing as how I need to make some things for my mod.
I have been using Deferred Registry for my registering of items and blocks like so:
 

Spoiler

In the main items file:


public class ModItems {
    // Setup the Deferred Register.
    public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, highgentech.MOD_ID);

    // Custom Item groups for creative tabs
    public static ItemGroup HGTmain = new ItemGroup("HGTmain") {
        @Override
        public ItemStack createIcon() {
            return new ItemStack(BRONZE_DUST.get());
        }
    };

    // Default item Properties
    public static Item.Properties Def = new Item.Properties().group(HGTmain);

    // Register new Items here!
    public static final RegistryObject<Item> BRONZE_DUST = ITEMS.register("bronze_dust",()->new Item(Def));
}

and in the main mod file:


@Mod(MOD_ID)
public class highgentech {
    // Set the MOD_ID here to use it in multiple places.
    public static final String MOD_ID = "highgentech";

    public static IEventBus EventBus;
    private static final Logger LOGGER = LogManager.getLogger();

    public highgentech(){
        // Get the FML EventBus the mod is on for easier use.
        EventBus = FMLJavaModLoadingContext.get().getModEventBus();
        // Setup a listener for the Setup event.
        EventBus.addListener(this::setup);
        // Register our self and all the stuff we are interested in.
        MinecraftForge.EVENT_BUS.register(this);
        ModBlocks.BLOCKS.register(EventBus);
        ModItems.ITEMS.register(EventBus);
    }

    private void setup(final FMLCommonSetupEvent event){
        // Pre-init code here
        LOGGER.info("Hello minecraft!");
    }
}

So i thought i could do something similar for Tile Entities. I made a new file, ModTileEntity, and before i could even finish typing the Deferred Registry line, i hit a snag.

Apparently it cannot be done like this:

public class ModTileEntity {
    public static final DeferredRegister<TileEntity> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, highgentech.MOD_ID);
}

and throws up a error about "Type not being within bounds", but doing it like this works fine:

public class ModTileEntity {
   public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, highgentech.MOD_ID);
}

So that is my first question. Do I use <TileEntity> and I was just using it wrong, or do I use <TileEntityType<?>>?

If it is TileEntityType, then here's my entire code so far:

package ahndreklicyri.highgentech.common.tileentities;

import ahndreklicyri.highgentech.highgentech;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModTileEntity {
    public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, highgentech.MOD_ID);

    //                                                                                                                                      v This is the issue
    public static final RegistryObject<TileEntityType<?>> EXAMPLE_ENTITY = TILE_ENTITIES.register("example_entity", ()->new TileEntityType<>());
}

It is asking for three arguments in the TileEntityType<>() function but i don't quite know what i am suppose to put there. It is asking for a Supplier, a Set<Block>, and a Type<?> but i am unsure as to what these are suppose to be.
Any help on this would be appreciated, thank you!
 

Posted
1 hour ago, Ahndrek Li'Cyri said:

public static final RegistryObject<TileEntityType<?>> EXAMPLE_ENTITY = TILE_ENTITIES.register("example_entity", ()->new TileEntityType<>());

Use the TileEntityType.Builder.create method to create your TileEntityType and replace TileEntityType<?> with your TileEntityType. This should fix the issues :)

  • Like 1
Posted

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/tileentity/altar/AltarTileEntity.java

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/main/registry/EvileDeferredRegistry.java#L125

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/main/registry/EvileDeferredRegistry.java#L59

These should help :)

 

1 hour ago, Ahndrek Li'Cyri said:

do I use <TileEntityType<?>>

Correct!

 

And don't forget to register your DeferredRegister using: 

TILE_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());

Or something similar. I do this in the constructor of my EvileDeferredRegistry, which is called in the constructor of my main mod class.

 

1 hour ago, Ahndrek Li'Cyri said:

i am unsure as to what these are suppose to be

No surprises here :) ... It isn't very intuitive (I think). Somewhere on this forum is me asking this exact question xD!

You have to use TileEntityBuilder.Builder#create:

public static final RegistryObject<TileEntityType<AmethystCrystalTileEntity>> TILE_ENTITY_AMETHYST_CRYSTAL = TILE_ENTITIES.register("tile_entity_amethyst_crystal", () -> TileEntityType.Builder.create(AmethystCrystalTileEntity::new, EvileDeferredRegistry.AMETHYST_CRYSTAL.get()).build(null));

You pass a new instance of your TileEntity (which must have a 0 argument constructor), and the Block you want to bind the TileEntity to. Then you have to call build(null) on the created Object.

  • Like 1

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Posted
1 hour ago, Skyriis said:

Use the TileEntityType.Builder.create method to create your TileEntityType and replace TileEntityType<?> with your TileEntityType. This should fix the issues :)

 

1 hour ago, GenElectrovise said:

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/tileentity/altar/AltarTileEntity.java

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/main/registry/EvileDeferredRegistry.java#L125

https://github.com/GenElectrovise/MagiksMostEvile/blob/1.15.2/src/main/java/genelectrovise/magiksmostevile/common/main/registry/EvileDeferredRegistry.java#L59

These should help :)

 

Correct!

 

And don't forget to register your DeferredRegister using: 


TILE_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());

Or something similar. I do this in the constructor of my EvileDeferredRegistry, which is called in the constructor of my main mod class.

 

No surprises here :) ... It isn't very intuitive (I think). Somewhere on this forum is me asking this exact question xD!

You have to use TileEntityBuilder.Builder#create:


public static final RegistryObject<TileEntityType<AmethystCrystalTileEntity>> TILE_ENTITY_AMETHYST_CRYSTAL = TILE_ENTITIES.register("tile_entity_amethyst_crystal", () -> TileEntityType.Builder.create(AmethystCrystalTileEntity::new, EvileDeferredRegistry.AMETHYST_CRYSTAL.get()).build(null));

You pass a new instance of your TileEntity (which must have a 0 argument constructor), and the Block you want to bind the TileEntity to. Then you have to call build(null) on the created Object.

Thank you guys so much i very much appreciate it! I was able to get it working. :D

  • Like 1
Posted

Okay so, it works, but it doesn't seem to actually apply the TileEntity to the block?
The tile Entity does exist, and I can see that in the logs, but for some reason, when I place the block, it doesn't seem to place as a tile entity.

TileEntity code:

package ahndreklicyri.highgentech.common.tileentities;

import ahndreklicyri.highgentech.highgentech;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;

public class FurnGenTin_TE extends TileEntity implements ITickableTileEntity {
    public int tickCount = 0;

    public FurnGenTin_TE() {
        super(ModTileEntity.FURN_GEN_TIN_TE.get());
    }

    // Required by ITickableTileEntity
    @Override
    public void tick() {
        tickCount++;
        if(tickCount == 60){
            highgentech.LOGGER.debug("Ticker working!");
            tickCount = 0;
        }
    }
}

DeferredRegistry file code:

package ahndreklicyri.highgentech.common.tileentities;

import ahndreklicyri.highgentech.common.blocks.ModBlocks;
import ahndreklicyri.highgentech.highgentech;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModTileEntity {
    public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<TileEntityType<?>>(ForgeRegistries.TILE_ENTITIES,highgentech.MOD_ID);

    public static final RegistryObject<TileEntityType<FurnGenTin_TE>> FURN_GEN_TIN_TE = TILE_ENTITIES.register("tile_entity_furnace_gen_tin",()->TileEntityType.Builder.create(FurnGenTin_TE::new, ModBlocks.TIN_FURN_GEN.get()).build(null));
}

Main file code:
 

@Mod(MOD_ID)
public class highgentech {
    // Set the MOD_ID here to use it in multiple places.
    public static final String MOD_ID = "highgentech";

    public static IEventBus EventBus;
    public static final Logger LOGGER = LogManager.getLogger();

    public highgentech(){
        // Get the FML EventBus the mod is on for easier use.
        EventBus = FMLJavaModLoadingContext.get().getModEventBus();
        // Setup a listener for the Setup event.
        EventBus.addListener(this::setup);
        // Register our self and all the stuff we are interested in.
        MinecraftForge.EVENT_BUS.register(this);
        ModBlocks.BLOCKS.register(EventBus);
        ModItems.ITEMS.register(EventBus);
        ModTileEntity.TILE_ENTITIES.register(EventBus);
    }

    private void setup(final FMLCommonSetupEvent event){
        // Pre-init code here
        LOGGER.info("Hello Minecraft!");
    }
}

Some help would be nice. I feel like it's something simple I'm just missing but i can't tell.

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



×
×
  • Create New...

Important Information

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