Posted January 29, 20214 yr i just want to add to my custom block (lightning rod) a tile entity but i got an error and i know there is an error in registration but i dont know where code: (code is frome the documentation package net.luis.cave.init; import ; @Mod.EventBusSubscriber(modid = Cave.Mod_Id, bus = Mod.EventBusSubscriber.Bus.MOD) public class CaveTileEntityType { public static final TileEntityType<LightningRodTileEntity> LIGHTNING_ROD = null; @SubscribeEvent public static void registerTE(RegistryEvent.Register<TileEntityType<?>> event) { TileEntityType<?> type = TileEntityType.Builder .create(LightningRodTileEntity::new, CaveBlocks.LIGHTNING_ROD.get()) .build(null); type.setRegistryName(Cave.Mod_Id, "lightminig_rod_tileentity"); event.getRegistry().register(type); } } and the error log: net.minecraft.crash.ReportedException: Ticking block entity at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:888) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:820) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:84) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:663) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:832) [?:?] {} Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.tileentity.TileEntityType.isValidBlock(net.minecraft.block.Block)" because the return value of "net.minecraft.tileentity.TileEntity.getType()" is null at net.minecraft.world.World.tickBlockEntities(World.java:537) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:374) ~[forge:?] {re:classloading} at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:884) ~[forge:?] {re:classloading,pl:accesstransformer:B} ... 5 more [13:52:48] [Server thread/ERROR] [minecraft/Chunk]: A TileEntity type net.luis.cave.blocks.tileentity.LightningRodTileEntity has thrown an exception trying to write state. It will not persist, Report this to the mod author java.lang.RuntimeException: class net.luis.cave.blocks.tileentity.LightningRodTileEntity is missing a mapping! This is a bug! at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:71) ~[forge:?] {re:classloading} at net.minecraft.tileentity.TileEntity.write(TileEntity.java:65) ~[forge:?] {re:classloading} at net.minecraft.world.chunk.Chunk.getTileEntityNBT(Chunk.java:438) ~[forge:?] {re:classloading} at net.minecraft.world.chunk.storage.ChunkSerializer.write(ChunkSerializer.java:287) ~[forge:?] {re:classloading} at net.minecraft.world.server.ChunkManager.chunkSave(ChunkManager.java:699) ~[forge:?] {re:classloading} at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176) ~[?:?] {} at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[?:?] {} at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?] {} at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) ~[?:?] {} at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?] {} at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?] {} at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?] {} at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?] {} at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?] {} at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) ~[?:?] {} at net.minecraft.world.server.ChunkManager.save(ChunkManager.java:354) ~[forge:?] {re:classloading} at net.minecraft.world.server.ServerChunkProvider.save(ServerChunkProvider.java:310) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.world.server.ServerWorld.save(ServerWorld.java:710) ~[forge:?] {re:classloading} at net.minecraft.server.MinecraftServer.save(MinecraftServer.java:544) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:583) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:186) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:700) ~[forge:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:832) [?:?] {} and my tileentity class: package net.luis.cave.blocks.tileentity; import java.util.Random; import ; public class LightningRodTileEntity extends TileEntity implements ITickableTileEntity { Random rng = this.getWorld().rand; public LightningRodTileEntity() { super(CaveTileEntityType.LIGHTNING_ROD); } @Override public void tick() { LightningBoltEntity lightning = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, this.getWorld()); lightning.setLocationAndAngles(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), rng.nextFloat() * 360, 0); if (this.getWorld().isThundering()) { if (this.getWorld().getGameTime() % (350 - rng.nextInt(200)) == 0) { this.getWorld().addEntity(lightning); } } } }
January 29, 20214 yr Author 5 hours ago, diesieben07 said: You never assign a value to LIGHTNING_ROD. When using registry events manually you need to use @ObjectHolder. what do you mean with "manually" is there another way to register TileEntitys
January 29, 20214 yr DeferredRegister is the other way. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 29, 20214 yr Author 17 minutes ago, Draco18s said: DeferredRegister is the other way. I kown but DefferredRegister will not work/I got an error which i don't understand: public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, Cave.Mod_Id); public static final RegistryObject<TileEntityType<LightningRodTileEntity>> LIGHTNING_ROD = TILE_ENTITIES.register("lightminig_rod_tileentity", () -> new TileEntityType<>(LightningRodTileEntity::new, CaveBlocks.LIGHTNING_ROD.get(), null)); 1. what should i add at "null" 2. when i add the Block which the TileEntity is vaild i got this error/ my ide say there is an error: "Cannot infer type arguments for TileEntityType<>"
January 29, 20214 yr 30 minutes ago, Luis_ST said: I kown but DefferredRegister will not work/I got an error which i don't understand: public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, Cave.Mod_Id); public static final RegistryObject<TileEntityType<LightningRodTileEntity>> LIGHTNING_ROD = TILE_ENTITIES.register("lightminig_rod_tileentity", () -> new TileEntityType<>(LightningRodTileEntity::new, CaveBlocks.LIGHTNING_ROD.get(), null)); 1. what should i add at "null" 2. when i add the Block which the TileEntity is vaild i got this error/ my ide say there is an error: "Cannot infer type arguments for TileEntityType<>" instead of a supplier, use the TileEntityType Builder
January 29, 20214 yr LightningBoltEntity lightning = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, this.getWorld()); lightning.setLocationAndAngles(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), rng.nextFloat() * 360, 0); if (this.getWorld().isThundering()) { if (this.getWorld().getGameTime() % (350 - rng.nextInt(200)) == 0) { this.getWorld().addEntity(lightning); } } you first create a new LightningBoltEntity and after that you check if you need to, dont do that
January 30, 20214 yr Author 17 hours ago, loordgek said: you first create a new LightningBoltEntity and after that you check if you need to, dont do that thanks but i have already fixed this problem 17 hours ago, kiou.23 said: instead of a supplier, use the TileEntityType Builder i tried a bit but i don't understand how replace the Supplier with TileEntityType Builder
January 30, 20214 yr Have you tried looking whats inside the TileEntityType.Builder class? Then it will be very obvious which method you have to use to create you tile entity type Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
January 30, 20214 yr Author 14 minutes ago, Beethoven92 said: Then it will be very obvious which method you have to use to create you tile entity type it works thank you
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.