DarkAssassin Posted April 12, 2020 Posted April 12, 2020 (edited) I have a code for a tile entity(modified mob spawner code) and now i have troubles making it a real block that i can place. how do i register something like that correctly? @Mod("spawntweak") public class SpawnTweak{ public static SpawnTweak instance; public static final String modid = "spawntweak"; private static final Logger logger = LogManager.getLogger(modid); public SpawnTweak() { instance=this; FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { logger.info("setup registered"); } private void clientRegistries(final FMLClientSetupEvent event) { logger.info("client registered"); } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents{ @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().registerAll( BlockList.spawner = new Block(Block.Properties.setRegistryName("minecraft:spawner"). ...) ); logger.info("Blocks registered"); } this is how i load my blocks Edited April 12, 2020 by DarkAssassin Quote
Draco18s Posted April 13, 2020 Posted April 13, 2020 You need an item form of your block. Blocks only exist in the world. Quote 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.
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 (edited) On 4/13/2020 at 1:42 AM, Draco18s said: You need an item form of your block. Blocks only exist in the world. Expand I don't really need to do that in my case because I'm using the same ID as a Standart vanilla spawner (im able to place my block with the vanilla item) I'm now only having troubles getting the tile entity to work correctly. see this on my newer post. Edited April 13, 2020 by DarkAssassin Quote
Draco18s Posted April 13, 2020 Posted April 13, 2020 On 4/13/2020 at 2:14 AM, DarkAssassin said: I don't really need to do that in my case because I'm using the same ID as a Standart vanilla spawner Expand Yes you do, because items don't know what their block is by registry name, but by being passed the instance in their constructor. Quote 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.
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 On 4/13/2020 at 6:45 AM, Draco18s said: Yes you do, because items don't know what their block is by registry name, but by being passed the instance in their constructor. Expand ok i will try that but what i´m wondering then is: why is the tile entity not loading and just a block when i comment out the TE out of my code when i place the vanilla item spawner Quote
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 On 4/13/2020 at 6:45 AM, Draco18s said: Yes you do, because items don't know what their block is by registry name, but by being passed the instance in their constructor. Expand the only thin changet for me is that i now have this item in a creative tab Quote
Animefan8888 Posted April 13, 2020 Posted April 13, 2020 On 4/13/2020 at 8:33 AM, DarkAssassin said: ok i will try that but what i´m wondering then is: why is the tile entity not loading and just a block when i comment out the TE out of my code when i place the vanilla item spawner Expand Did you register a TileEntityType for your TileEntity? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 (edited) On 4/13/2020 at 8:47 AM, Animefan8888 said: Did you register a TileEntityType for your TileEntity? Expand i thought so but i actually just have a questionmark. do you know what type a spawner is? @SubscribeEvent public static void registerTileEntety(RegistryEvent.Register<TileEntityType<?>> event) { TileEntityType<?> type = TileEntityType.Builder.create(MobSpawnerTileEntity::new, BlockList.spawner).build(null); type.setRegistryName("minecraft:spawner"); event.getRegistry().register(type); } if type.setRegistryName("minecraft:spawner") it is just a block and if type.setRegistryName("minecraft:mob_spawner") the game crashes with this error log [02:29:55] [Server thread/ERROR] [minecraft/Chunk]: A TileEntity type fabian.spawntweak.lists.MobSpawnerTileEntity has thrown an exception trying to write state. It will not persist, Report this to the mod author java.lang.RuntimeException: class fabian.spawntweak.lists.MobSpawnerTileEntity is missing a mapping! This is a bug! at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:72) ~[?:?] {re:classloading} at net.minecraft.tileentity.TileEntity.write(TileEntity.java:66) ~[?:?] {re:classloading} at fabian.spawntweak.lists.MobSpawnerTileEntity.write(MobSpawnerTileEntity.java:72) ~[?:?] {re:classloading} at net.minecraft.world.chunk.Chunk.func_223134_j(Chunk.java:444) ~[?:?] {re:classloading} at net.minecraft.world.chunk.storage.ChunkSerializer.write(ChunkSerializer.java:303) ~[?:?] {re:classloading} at net.minecraft.world.server.ChunkManager.func_219229_a(ChunkManager.java:677) ~[?:?] {re:classloading} at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) [?:1.8.0_241] {} at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) [?:1.8.0_241] {} at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) [?:1.8.0_241] {} at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) [?:1.8.0_241] {} at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) [?:1.8.0_241] {} at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) [?:1.8.0_241] {} at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) [?:1.8.0_241] {} at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) [?:1.8.0_241] {} at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [?:1.8.0_241] {} at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) [?:1.8.0_241] {} at net.minecraft.world.server.ChunkManager.save(ChunkManager.java:336) [?:?] {re:classloading} at net.minecraft.world.server.ServerChunkProvider.save(ServerChunkProvider.java:309) [?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.world.server.ServerWorld.save(ServerWorld.java:770) [?:?] {re:classloading} at net.minecraft.server.MinecraftServer.save(MinecraftServer.java:528) [?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:571) [?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:235) [?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:685) [?:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241] {} +the main reson is spawntweak.lists.MobSpawnerTileEntity has thrown an exception trying to write state. It will not persist, Report this to the mod author java.lang.RuntimeException: class fabian.spawntweak.lists.MobSpawnerTileEntity is missing a mapping! i Edited April 13, 2020 by DarkAssassin Quote
Animefan8888 Posted April 13, 2020 Posted April 13, 2020 On 4/13/2020 at 9:01 AM, DarkAssassin said: the game crashes with this error log Expand It would help if you showed more code. What does your Block look like what about your TileEntity? You are using a class for your Block and TileEntity right? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 On 4/13/2020 at 9:21 AM, Animefan8888 said: It would help if you showed more code. What does your Block look like what about your TileEntity? You are using a class for your Block and TileEntity right? Expand i´ve detailed it in another post but Tile Entity import java.util.Random; import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; 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.WeightedSpawnerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class MobSpawnerTileEntity extends TileEntity implements ITickableTileEntity { private final AbstractSpawner spawnerLogic = new AbstractSpawner() { public void broadcastEvent(int id) { MobSpawnerTileEntity.this.world.addBlockEvent(MobSpawnerTileEntity.this.pos, Blocks.SPAWNER, id, 0); } public World getWorld() { return MobSpawnerTileEntity.this.world; } public BlockPos getSpawnerPosition() { return MobSpawnerTileEntity.this.pos; } public void setNextSpawnData(WeightedSpawnerEntity nextSpawnData) { super.setNextSpawnData(nextSpawnData); if (this.getWorld() != null) { BlockState blockstate = this.getWorld().getBlockState(this.getSpawnerPosition()); this.getWorld().notifyBlockUpdate(MobSpawnerTileEntity.this.pos, blockstate, blockstate, 4); } } }; public void tick(BlockState state, World worldIn, BlockPos pos, Random random) { if (!worldIn.isRemote) { if (worldIn.isBlockPowered(pos)) { AbstractSpawner.isActivated = true; } else { AbstractSpawner.isActivated =false; } } } public MobSpawnerTileEntity() { super(TileEntityType.MOB_SPAWNER); } public void read(CompoundNBT compound) { super.read(compound); this.spawnerLogic.read(compound); } public CompoundNBT write(CompoundNBT compound) { super.write(compound); this.spawnerLogic.write(compound); return compound; } public void tick() { this.spawnerLogic.tick(); } @Nullable public SUpdateTileEntityPacket getUpdatePacket() { return new SUpdateTileEntityPacket(this.pos, 1, this.getUpdateTag()); } public CompoundNBT getUpdateTag() { CompoundNBT compoundnbt = this.write(new CompoundNBT()); compoundnbt.remove("SpawnPotentials"); return compoundnbt; } public boolean receiveClientEvent(int id, int type) { return this.spawnerLogic.setDelayToMin(id) ? true : super.receiveClientEvent(id, type); } public boolean onlyOpsCanSetNbt() { return true; } public AbstractSpawner getSpawnerBaseLogic() { return this.spawnerLogic; } } Block import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.world.IBlockReader; public class MobSpawner extends Block{ public MobSpawner(Properties properties) { super(Properties.create(Material.IRON).hardnessAndResistance(3.0f, 3.0f).sound(SoundType.METAL)); } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new MobSpawnerTileEntity(); } public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.TRANSLUCENT; } @Override public boolean hasTileEntity(BlockState state) { return true; } } is it right that i have this in my tile entity or do i need to put the function into the block class public void tick(BlockState state, World worldIn, BlockPos pos, Random random) { if (!worldIn.isRemote) { if (worldIn.isBlockPowered(pos)) { AbstractSpawner.isActivated = true; } else { AbstractSpawner.isActivated =false; } } } Quote
Draco18s Posted April 13, 2020 Posted April 13, 2020 On 4/12/2020 at 8:42 PM, DarkAssassin said: BlockList.spawner = new Block(... Expand Might help if you actually USED your block class. Quote 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.
DarkAssassin Posted April 13, 2020 Author Posted April 13, 2020 (edited) On 4/13/2020 at 1:51 PM, Draco18s said: Might help if you actually USED your block class. Expand my bad. the code is older and my setup function now looks like this private void setup(final FMLCommonSetupEvent event) { logger.info("setup registered"); } private void clientRegistries(final FMLClientSetupEvent event) { logger.info("client registered"); } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents{ @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll( ItemList.spawner= new BlockItem(BlockList.spawner, new Item.Properties().group(ItemGroup.TRANSPORTATION)).setRegistryName(BlockList.spawner.getRegistryName()));} @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().registerAll( BlockList.spawner = new MobSpawner(MobSpawner.Properties.create(Material.IRON).hardnessAndResistance(3.0f, 3.0f).sound(SoundType.METAL)).setRegistryName("minecraft:spawner")); logger.info("Blocks registered"); } @SubscribeEvent public static void registerTileEntety(RegistryEvent.Register<TileEntityType<?>> event) { TileEntityType<?> type = TileEntityType.Builder.create(MobSpawnerTileEntity::new, BlockList.spawner).build(null); type.setRegistryName("minecraft:mob_spawner"); event.getRegistry().register(type); } Edited April 13, 2020 by DarkAssassin Quote
Recommended Posts
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.