Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. package com.drnickenstein.testmod.world.features;
  2.  
  3.  
  4.  
  5. import java.util.Random;
  6. import java.util.function.Function;
  7.  
  8. import com.mojang.datafixers.Dynamic;
  9.  
  10. import net.minecraft.util.Mirror;
  11. import net.minecraft.util.ResourceLocation;
  12. import net.minecraft.util.Rotation;
  13. import net.minecraft.util.math.BlockPos;
  14. import net.minecraft.util.math.MutableBoundingBox;
  15. import net.minecraft.world.IWorld;
  16. import net.minecraft.world.gen.ChunkGenerator;
  17. import net.minecraft.world.gen.GenerationSettings;
  18. import net.minecraft.world.gen.Heightmap;
  19. import net.minecraft.world.gen.feature.Feature;
  20. import net.minecraft.world.gen.feature.NoFeatureConfig;
  21. import net.minecraft.world.gen.feature.template.BlockIgnoreStructureProcessor;
  22. import net.minecraft.world.gen.feature.template.IntegrityProcessor;
  23. import net.minecraft.world.gen.feature.template.PlacementSettings;
  24. import net.minecraft.world.gen.feature.template.Template;
  25. import net.minecraft.world.server.ServerWorld;
  26.  
  27. public class RubberForestPondFeature extends Feature<NoFeatureConfig>
  28. {
  29.  
  30. private static final ResourceLocation STRUCTURE_POND_1 = new ResourceLocation("humlands:pond/pond_1");
  31. private static final ResourceLocation STRUCTURE_POND_2 = new ResourceLocation("humlands:pond/pond_2");
  32. //private static final ResourceLocation STRUCTURE_POND_3 = new ResourceLocation("humlands:pond/pond_3");
  33. //private static final ResourceLocation STRUCTURE_POND_4 = new ResourceLocation("humlands:pond/pond_4");
  34.  
  35. private static final ResourceLocation[] PONDS = new ResourceLocation[]
  36. {
  37. STRUCTURE_POND_1,
  38. STRUCTURE_POND_2,
  39. //STRUCTURE_POND_3,
  40. //STRUCTURE_POND_4
  41. };
  42.  
  43.  
  44. public RubberForestPondFeature(Function<Dynamic<?>, ? extends NoFeatureConfig> p_i49873_1_)
  45. {
  46. super(p_i49873_1_);
  47. }
  48.  
  49. public boolean place(IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand,
  50. BlockPos pos, NoFeatureConfig config) {
  51. Random random = worldIn.getRandom();
  52. Rotation[] arotation = Rotation.values();
  53. Rotation rotation = arotation[random.nextInt(arotation.length)];
  54. Template template = ((ServerWorld) worldIn.getWorld()).getSaveHandler().getStructureTemplateManager()
  55. .getTemplateDefaulted(PONDS[random.nextInt(PONDS.length)]);
  56.  
  57.  
  58. PlacementSettings placementsettings = (new PlacementSettings()).setRotation(rotation)
  59. //.setBoundingBox defines until where the structure should spawn, for example here it's max 25600 X, 256 Y and 25600 Z
  60. .setBoundingBox(new MutableBoundingBox((0 - 25600), (0 - 25600), (0 - 25600), 25600, 256, 25600))
  61. .setRandom(random)
  62. .addProcessor(BlockIgnoreStructureProcessor.AIR_AND_STRUCTURE_BLOCK);
  63. // j k l are respectively x y z , and define the width, height and depth of the structure
  64. BlockPos blockpos = template.transformedSize(rotation);
  65. int j = random.nextInt(20 - 0);
  66. int k = random.nextInt(20 - 0);
  67. int l = 256;
  68. for (int i1 = 0; i1 < blockpos.getX(); ++i1) {
  69. for (int j1 = 0; j1 < blockpos.getZ(); ++j1) {
  70. l = Math.min(l,
  71. worldIn.getHeight(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ()));
  72. }
  73. }
  74. //This is what actually generates the structure
  75. BlockPos blockpos1 = template.getZeroPositionWithTransform(
  76. new BlockPos(pos.add(j, 0, k).getX(), l, pos.add(j, 0, k).getZ()), Mirror.NONE, rotation);
  77. IntegrityProcessor integrityprocessor = new IntegrityProcessor(0.9F);
  78. placementsettings.clearProcessors().addProcessor(integrityprocessor);
  79. template.addBlocksToWorld(worldIn, blockpos1, placementsettings, 4);
  80. placementsettings.func_215220_b(integrityprocessor);
  81. return true;
  82.  
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement