Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Zerom69

Members
  • Joined

  • Last visited

  1. It generates and gives me the coords in the console, but when I go to the coords there is nothing there. I've tried different NBT's, but the generated structure does not appear.
  2. Zerom69 changed their profile photo
  3. Hello guys! So I'm having a problem with the new structure NBT system. I got the template to load and structure to randomly generate, but the structure is just not there! I've tried to look up a solution, but didn't find it! My Code: ModWorldGenerator: package com.zerom69.purnacopia.worldgen; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraft.world.gen.structure.template.Template; import net.minecraftforge.fml.common.IWorldGenerator; public class ModWorldGenerator implements IWorldGenerator { @Override public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { int blockX = chunkX * 16; int blockZ = chunkZ * 16; switch (world.provider.getDimension()) { case -1: generateNether(world, rand, blockX + 8, blockZ + 8); break; case 0: generateOverworld(world, rand, blockX + 8, blockZ + 8); break; case 1: generateEnd(world, rand, blockX + 8, blockZ + 8); break; } } private void generateOverworld(World world, Random rand, int blockX, int blockZ) { if ((int) (Math.random() * 100) == 0) { int y = getGroundFromAbove(world, blockX, blockZ); BlockPos pos = new BlockPos(blockX, y, blockZ); WorldGenerator obelisk = new ObeliskGen(); obelisk.generate(world, rand, pos); } } private void generateNether(World world, Random rand, int chunkX, int chunkZ) {} private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {} private void addOreSpawn(IBlockState block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY) { for (int i = 0; i < chanceToSpawn; i++) { int posX = blockXPos + random.nextInt(maxX); int posY = minY + random.nextInt(maxY - minY); int posZ = blockZPos + random.nextInt(maxZ); new WorldGenMinable(block, maxVeinSize).generate(world, random, new BlockPos(posX, posY, posZ)); } } public static int getGroundFromAbove(World world, int x, int z) { int y = 255; boolean foundGround = false; while(!foundGround && y-- >= 63) { Block blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock(); foundGround = blockAt == Blocks.DIRT || blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.GLASS; } return y; } public static boolean canSpawnHere(Template template, World world, BlockPos posAboveGround) { int zwidth = template.getSize().getZ(); int xwidth = template.getSize().getX(); // check all the corners to see which ones are replaceable boolean corner1 = isCornerValid(world, posAboveGround); boolean corner2 = isCornerValid(world, posAboveGround.add(xwidth, 0, zwidth)); // if Y > 20 and all corners pass the test, it's okay to spawn the structure return posAboveGround.getY() > 63 && corner1 && corner2; } public static boolean isCornerValid(World world, BlockPos pos) { int variation = 3; int highestBlock = getGroundFromAbove(world, pos.getX(), pos.getZ()); if (highestBlock > pos.getY() - variation && highestBlock < pos.getY() + variation) return true; return false; } } ObeliskGen: package com.zerom69.purnacopia.worldgen; import java.util.Random; import com.zerom69.purnacopia.PurnacopiaMod; import com.zerom69.purnacopia.utils.ResourceUtils; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Mirror; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraft.world.gen.structure.template.PlacementSettings; import net.minecraft.world.gen.structure.template.Template; import net.minecraft.world.gen.structure.template.TemplateManager; public class ObeliskGen extends WorldGenerator { @Override public boolean generate(World world, Random rand, BlockPos position) { WorldServer worldserver = (WorldServer) world; MinecraftServer minecraftserver = world.getMinecraftServer(); TemplateManager templatemanager = worldserver.getStructureTemplateManager(); Template template = templatemanager.getTemplate(minecraftserver, new ResourceLocation(PurnacopiaMod.modId+":structures/obelisk1.nbt")); if(template == null) { System.out.println("NO STRUCTURE"); return false; } if(ModWorldGenerator.canSpawnHere(template, worldserver, position)) { IBlockState iblockstate = world.getBlockState(position); world.notifyBlockUpdate(position, iblockstate, iblockstate, 3); PlacementSettings placementsettings = (new PlacementSettings()).setMirror(Mirror.NONE) .setRotation(Rotation.NONE).setIgnoreEntities(false).setChunk((ChunkPos) null) .setReplacedBlock((Block) null).setIgnoreStructureBlock(false); template.addBlocksToWorld(world, position.add(0, 1, 0), placementsettings); PurnacopiaMod.logger.info("Generating obelisk at "+position); return true; } return false; } } CommoProxy: package com.zerom69.purnacopia.proxy; import java.io.File; import com.zerom69.purnacopia.Config; import com.zerom69.purnacopia.PurnacopiaMod; import com.zerom69.purnacopia.block.ModBlocks; import com.zerom69.purnacopia.entity.EntityThunderball; import com.zerom69.purnacopia.item.ModItems; import com.zerom69.purnacopia.network.PacketHandler; import com.zerom69.purnacopia.worldgen.ModWorldGenerator; import net.minecraft.block.Block; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; @Mod.EventBusSubscriber public class CommonProxy { public static Configuration config; public void preInit(FMLPreInitializationEvent e) { registerEntities(); File directory = e.getModConfigurationDirectory(); config = new Configuration(new File(directory.getPath(), "purnacopia.cfg")); Config.readConfig(); PacketHandler.registerMessages(); } public void init(FMLInitializationEvent e) { NetworkRegistry.INSTANCE.registerGuiHandler(PurnacopiaMod.instance, new GuiProxy()); GameRegistry.registerWorldGenerator(new ModWorldGenerator(), 0); } public void postInit(FMLPostInitializationEvent e) { if (config.hasChanged()) { config.save(); } } public void registerEntities() { EntityRegistry.registerModEntity(new ResourceLocation(PurnacopiaMod.modId, "Thunderball"), EntityThunderball.class, "purnacopia:Thunderball", 1, PurnacopiaMod.instance, 128, 1, true); } @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event) { ModBlocks.register(event.getRegistry()); } @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { ModItems.register(event.getRegistry()); ModBlocks.registerItemBlocks(event.getRegistry()); } public void registerItemRenderer(Item item, int meta, String id) {} public void registerRenderers() {} }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.