Jump to content

1.17.1 Ore generation is not working properly.


Gianka1485

Recommended Posts

I have been working on a mod which adds minerals, the problem is that when they are generated, they ignore the maximum and minimum height that is established.

The main:

@Mod("examplemod")
public class ExampleMod {
    public static ExampleMod instance;
    public static final String modid = "examplemod";
    private static final Logger LOGGER = LogManager.getLogger("examplemod");
    public static final CreativeModeTab examplemod = new ExampleTab();

    public ExampleMod() {
        instance = this;

        ExampleBlocks.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ExampleItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        ModLoadingContext.get().registerConfig(Type.COMMON, ExampleModConfig.SPEC, "example-common.toml");

        MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, OreGeneration::generateOres);
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("Hello from preinit");
        LOGGER.info("Dirt block >> {}", Blocks.DIRT.getRegistryName());
    }

    @OnlyIn(Dist.CLIENT)
    public void clientSetup(FMLClientSetupEvent event) {
        LOGGER.info("Hello from client setup");
    }

    @SubscribeEvent
    public void serverStarting(FMLServerStartingEvent event) {
        LOGGER.info("Hello from server starting");
    }

    @EventBusSubscriber(bus = Bus.MOD)
    public static class RegistryEvents {
        public RegistryEvents() {
        }

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            LOGGER.info("Hello from Register Block");
        }

        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event) {
            LOGGER.info("Hello from Register Item");
        }

        @SubscribeEvent
        public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
            LOGGER.info("Hello from Register Entity");
        }

        @SubscribeEvent
        public static void registerEnchantments(final RegistryEvent.Register<Enchantment> event) {
            LOGGER.info("Hello from Register Enchantment");
        }

        @SubscribeEvent
        public static void registerSounds(final RegistryEvent.Register<SoundEvent> event) {
            LOGGER.info("Hello from Register Sound");
        }
    }
}

 

OreGeneration:

 

public class OreGeneration {
    public OreGeneration() {
    }

    public static void generateOres(final BiomeLoadingEvent event) {
        if (!event.getCategory().equals(Biome.BiomeCategory.NETHER) && !event.getCategory().equals(Biome.BiomeCategory.THEEND)) {
            exampleOreGenerate(event.getGeneration(), Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState(), (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_AMOUNT.get());
        }
    }

    private static void exampleOreGenerate(BiomeGenerationSettingsBuilder settings, RuleTest fillerType, BlockState state, int veinSize, int minHeight, int maxHeight, int amount) {
        settings.addFeature(Decoration.UNDERGROUND_ORES, (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(fillerType, state, veinSize)).rangeUniform(VerticalAnchor.aboveBottom(minHeight), VerticalAnchor.belowTop(maxHeight))).squared()).count(amount));
    }
}

 

 

The configuration:

 

public class ExampleConfig {
    public static final Builder BUILDER = new Builder();
    public static final ForgeConfigSpec SPEC;
    public static final ConfigValue<Boolean> EXAMPLE_ORE_GENERATION;
    public static final ConfigValue<Integer> EXAMPLE_ORE_SIZE;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MIN_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MAX_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_AMOUNT;

    public ExampleConfig() {
    }

    static {
        BUILDER.push("Example ore generation");
        EXAMPLE_ORE_GENERATION = BUILDER.define("Generate example ore", true);
        EXAMPLE_ORE_SIZE = BUILDER.define("Example ore vein size", 8);
        EXAMPLE_ORE_MIN_HEIGHT = BUILDER.define("Minimum example ore generation height", 16);
        EXAMPLE_ORE_MAX_HEIGHT = BUILDER.define("Maximum example ore generation height", 32);
        EXAMPLE_ORE_AMOUNT = BUILDER.define("Amount of generate example ore", 31); <- This is the value
        BUILDER.pop();
        SPEC = BUILDER.build();
    }
}

 

It seems that the problem is in the "amount" parameter, since if I change it, it will not The mineral is generated, or it is generated as it should not, if I set it to a value of 16 or less, the mineral is not generated, but if I set it to a value of 17 or greater, it is generated ignoring the maximum and minimum height established.

Edited by Gianka1485
Link to comment
Share on other sites

  • Gianka1485 changed the title to 1.17.1 Ore generation is not working properly.

To use the max and min height you need to change the VerticalAnchor you have set VerticalAnchor.aboveBottom and VerticalAnchor.belowTop, if you change it to VerticalAnchor.absolute it should work

public class OreGeneration {
    public OreGeneration() {
    }

    public static void generateOres(final BiomeLoadingEvent event) {
        if (!event.getCategory().equals(Biome.BiomeCategory.NETHER) && !event.getCategory().equals(Biome.BiomeCategory.THEEND)) {
            exampleOreGenerate(event.getGeneration(), Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState(), (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_AMOUNT.get());
        }
    }

    private static void exampleOreGenerate(BiomeGenerationSettingsBuilder settings, RuleTest fillerType, BlockState state, int veinSize, int minHeight, int maxHeight, int amount) {
        settings.addFeature(Decoration.UNDERGROUND_ORES, (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(fillerType, state, veinSize)).rangeUniform(VerticalAnchor.absolute(minHeight), VerticalAnchor.absolute(maxHeight))).squared()).count(amount));
    }
}
Edited by Grookey
Link to comment
Share on other sites

El 21/08/2021 a las 7:52 AM, Luis_ST dijo:

dejar de usar este código su roto!
debe registrar la configuración

Cambié el código de generación de los minerales a lo siguiente:

 

OreGeneration:

@EventBusSubscriber
public class OreGeneration {
    public static ImmutableList<TargetBlockState> EXAMPLE_ORE_TARGET_LIST;
    public static ConfiguredFeature<?, ?> EXAMPLE_ORE;

    public OreGeneration() {
    }

    public static void registerConfiguredFeatures() {
        EXAMPLE_ORE_TARGET_LIST = ImmutableList.of(OreConfiguration.target(Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()), OreConfiguration.target(Predicates.STONE_ORE_REPLACEABLES, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()));
        EXAMPLE_ORE = (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(EXAMPLE_ORE_TARGET_LIST, (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get())).rangeUniform(VerticalAnchor.aboveBottom((Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get()), VerticalAnchor.belowTop((Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get()))).squared()).count((Integer) ExampleConfig.EXAMPLE_ORE_CHANCE.get());
        Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation("examplemod", "example_ore"), EXAMPLE_ORE);
    }

    @SubscribeEvent
    public static void registerBiomeModification(BiomeLoadingEvent event) {
        registerConfiguredFeatures();
        event.getGeneration().getFeatures(Decoration.UNDERGROUND_ORES).add(() -> {
            return EXAMPLE_ORE;
        });
    }
}

 

 

Los principales:

@Mod("examplemod")
public class ExampleMod {
    public static ExampleMod instance;
    public static final String modid = "examplemod";
    private static final Logger LOGGER = LogManager.getLogger("examplemod");
    public static final CreativeModeTab examplemod = new ExampleTab();

    public ExampleMod() {
        instance = this;

        ExampleBlocks.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ExampleItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        ModLoadingContext.get().registerConfig(Type.COMMON, ExampleModConfig.SPEC, "example-common.toml");

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
      	OreGeneration.registerConfiguredFeatures;            <- THE CHANGE
        LOGGER.info("Hello from preinit");
        LOGGER.info("Dirt block >> {}", Blocks.DIRT.getRegistryName());
    }

    @OnlyIn(Dist.CLIENT)
    public void clientSetup(FMLClientSetupEvent event) {
        LOGGER.info("Hello from client setup");
    }

    @SubscribeEvent
    public void serverStarting(FMLServerStartingEvent event) {
        LOGGER.info("Hello from server starting");
    }

    @EventBusSubscriber(bus = Bus.MOD)
    public static class RegistryEvents {
        public RegistryEvents() {
        }

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            LOGGER.info("Hello from Register Block");
        }

        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event) {
            LOGGER.info("Hello from Register Item");
        }

        @SubscribeEvent
        public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
            LOGGER.info("Hello from Register Entity");
        }

        @SubscribeEvent
        public static void registerEnchantments(final RegistryEvent.Register<Enchantment> event) {
            LOGGER.info("Hello from Register Enchantment");
        }

        @SubscribeEvent
        public static void registerSounds(final RegistryEvent.Register<SoundEvent> event) {
            LOGGER.info("Hello from Register Sound");
        }
    }
}

 

 

Después de esto, ahora independientemente del número que pongas en la oportunidad de generar el mineral, se generará con los valores establecidos, pero todavía existe el error que ignora la altura máxima y mínima del mineral.

Edited by Gianka1485
Link to comment
Share on other sites

On 8/21/2021 at 7:34 AM, Grookey said:

To use the max and min height you need to change the VerticalAnchor you have set VerticalAnchor.aboveBottom and VerticalAnchor.belowTop, if you change it to VerticalAnchor.absolute it should work


public class OreGeneration {
    public OreGeneration() {
    }

    public static void generateOres(final BiomeLoadingEvent event) {
        if (!event.getCategory().equals(Biome.BiomeCategory.NETHER) && !event.getCategory().equals(Biome.BiomeCategory.THEEND)) {
            exampleOreGenerate(event.getGeneration(), Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState(), (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get(), (Integer) ExampleConfig.EXAMPLE_ORE_AMOUNT.get());
        }
    }

    private static void exampleOreGenerate(BiomeGenerationSettingsBuilder settings, RuleTest fillerType, BlockState state, int veinSize, int minHeight, int maxHeight, int amount) {
        settings.addFeature(Decoration.UNDERGROUND_ORES, (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(fillerType, state, veinSize)).rangeUniform(VerticalAnchor.absolute(minHeight), VerticalAnchor.absolute(maxHeight))).squared()).count(amount));
    }
}

It worked in the best possible way, it may seem very silly, but I spent about 3 days changing the code to fix the problem, and after so long, I just changed the values to absolute and it is as it should be, after a long time, my code It remained like this:

 

@EventBusSubscriber
public class OreGeneration {
    public static ImmutableList<TargetBlockState> EXAMPLE_ORE_TARGET_LIST;
    public static ConfiguredFeature<?, ?> EXAMPLE_ORE;

    public OreGeneration() {
    }

    public static void registerConfiguredFeatures() {
        EXAMPLE_ORE_TARGET_LIST = ImmutableList.of(OreConfiguration.target(Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()), OreConfiguration.target(Predicates.STONE_ORE_REPLACEABLES, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()));
        EXAMPLE_ORE = (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(EXAMPLE_ORE_TARGET_LIST, (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get())).rangeUniform(VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get()), VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get()))).squared()).count((Integer) ExampleConfig.EXAMPLE_ORE_CHANCE.get());
        Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation("examplemod", "example_ore"), EXAMPLE_ORE);
    }

    @SubscribeEvent
    public static void registerBiomeModification(BiomeLoadingEvent event) {
        registerConfiguredFeatures();
        event.getGeneration().getFeatures(Decoration.UNDERGROUND_ORES).add(() -> {
            return EXAMPLE_ORE;
        });
    }
}

 

Link to comment
Share on other sites

Now this brings another error, if in the ExampleConfig file the value of the variable "EXAMPLE_ORE_SIZE" is less than 4, the mineral is not generated, this is a big problem for me, since I want to add a mineral better than netherite, and That is just as rare, but it just doesn't appear, even if I increase the chance value a lot, it still doesn't work.

Link to comment
Share on other sites

22 minutes ago, Luis_ST said:

the vanilla code is an example

So where can I find the netherite example?

 

I already looked in features and only the base code of the generation appears, where then could I find the diamond one, for example?

Edited by Gianka1485
Link to comment
Share on other sites

9 minutes ago, Luis_ST said:

in which class did you look exactly

 

When I enter features the following appears:

public static final Feature<OreConfiguration> ORE = register("ore", new OreFeature(OreConfiguration.CODEC));

 

 

Upon entering OreFeature, the following appears:

public class OreFeature extends Feature<OreConfiguration> {
   public OreFeature(Codec<OreConfiguration> p_66531_) {
      super(p_66531_);
   }

   public boolean place(FeaturePlaceContext<OreConfiguration> p_160177_) {
      Random random = p_160177_.random();
      BlockPos blockpos = p_160177_.origin();
      WorldGenLevel worldgenlevel = p_160177_.level();
      OreConfiguration oreconfiguration = p_160177_.config();
      float f = random.nextFloat() * (float)Math.PI;
      float f1 = (float)oreconfiguration.size / 8.0F;
      int i = Mth.ceil(((float)oreconfiguration.size / 16.0F * 2.0F + 1.0F) / 2.0F);
      double d0 = (double)blockpos.getX() + Math.sin((double)f) * (double)f1;
      double d1 = (double)blockpos.getX() - Math.sin((double)f) * (double)f1;
      double d2 = (double)blockpos.getZ() + Math.cos((double)f) * (double)f1;
      double d3 = (double)blockpos.getZ() - Math.cos((double)f) * (double)f1;
      int j = 2;
      double d4 = (double)(blockpos.getY() + random.nextInt(3) - 2);
      double d5 = (double)(blockpos.getY() + random.nextInt(3) - 2);
      int k = blockpos.getX() - Mth.ceil(f1) - i;
      int l = blockpos.getY() - 2 - i;
      int i1 = blockpos.getZ() - Mth.ceil(f1) - i;
      int j1 = 2 * (Mth.ceil(f1) + i);
      int k1 = 2 * (2 + i);

      for(int l1 = k; l1 <= k + j1; ++l1) {
         for(int i2 = i1; i2 <= i1 + j1; ++i2) {
            if (l <= worldgenlevel.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, l1, i2)) {
               return this.doPlace(worldgenlevel, random, oreconfiguration, d0, d1, d2, d3, d4, d5, k, l, i1, j1, k1);
            }
         }
      }

      return false;
   }

   protected boolean doPlace(WorldGenLevel p_66533_, Random p_66534_, OreConfiguration p_66535_, double p_66536_, double p_66537_, double p_66538_, double p_66539_, double p_66540_, double p_66541_, int p_66542_, int p_66543_, int p_66544_, int p_66545_, int p_66546_) {
      int i = 0;
      BitSet bitset = new BitSet(p_66545_ * p_66546_ * p_66545_);
      BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
      int j = p_66535_.size;
      double[] adouble = new double[j * 4];

      for(int k = 0; k < j; ++k) {
         float f = (float)k / (float)j;
         double d0 = Mth.lerp((double)f, p_66536_, p_66537_);
         double d1 = Mth.lerp((double)f, p_66540_, p_66541_);
         double d2 = Mth.lerp((double)f, p_66538_, p_66539_);
         double d3 = p_66534_.nextDouble() * (double)j / 16.0D;
         double d4 = ((double)(Mth.sin((float)Math.PI * f) + 1.0F) * d3 + 1.0D) / 2.0D;
         adouble[k * 4 + 0] = d0;
         adouble[k * 4 + 1] = d1;
         adouble[k * 4 + 2] = d2;
         adouble[k * 4 + 3] = d4;
      }

      for(int l3 = 0; l3 < j - 1; ++l3) {
         if (!(adouble[l3 * 4 + 3] <= 0.0D)) {
            for(int i4 = l3 + 1; i4 < j; ++i4) {
               if (!(adouble[i4 * 4 + 3] <= 0.0D)) {
                  double d8 = adouble[l3 * 4 + 0] - adouble[i4 * 4 + 0];
                  double d10 = adouble[l3 * 4 + 1] - adouble[i4 * 4 + 1];
                  double d12 = adouble[l3 * 4 + 2] - adouble[i4 * 4 + 2];
                  double d14 = adouble[l3 * 4 + 3] - adouble[i4 * 4 + 3];
                  if (d14 * d14 > d8 * d8 + d10 * d10 + d12 * d12) {
                     if (d14 > 0.0D) {
                        adouble[i4 * 4 + 3] = -1.0D;
                     } else {
                        adouble[l3 * 4 + 3] = -1.0D;
                     }
                  }
               }
            }
         }
      }

      BulkSectionAccess bulksectionaccess = new BulkSectionAccess(p_66533_);

      try {
         for(int j4 = 0; j4 < j; ++j4) {
            double d9 = adouble[j4 * 4 + 3];
            if (!(d9 < 0.0D)) {
               double d11 = adouble[j4 * 4 + 0];
               double d13 = adouble[j4 * 4 + 1];
               double d15 = adouble[j4 * 4 + 2];
               int k4 = Math.max(Mth.floor(d11 - d9), p_66542_);
               int l = Math.max(Mth.floor(d13 - d9), p_66543_);
               int i1 = Math.max(Mth.floor(d15 - d9), p_66544_);
               int j1 = Math.max(Mth.floor(d11 + d9), k4);
               int k1 = Math.max(Mth.floor(d13 + d9), l);
               int l1 = Math.max(Mth.floor(d15 + d9), i1);

               for(int i2 = k4; i2 <= j1; ++i2) {
                  double d5 = ((double)i2 + 0.5D - d11) / d9;
                  if (d5 * d5 < 1.0D) {
                     for(int j2 = l; j2 <= k1; ++j2) {
                        double d6 = ((double)j2 + 0.5D - d13) / d9;
                        if (d5 * d5 + d6 * d6 < 1.0D) {
                           for(int k2 = i1; k2 <= l1; ++k2) {
                              double d7 = ((double)k2 + 0.5D - d15) / d9;
                              if (d5 * d5 + d6 * d6 + d7 * d7 < 1.0D && !p_66533_.isOutsideBuildHeight(j2)) {
                                 int l2 = i2 - p_66542_ + (j2 - p_66543_) * p_66545_ + (k2 - p_66544_) * p_66545_ * p_66546_;
                                 if (!bitset.get(l2)) {
                                    bitset.set(l2);
                                    blockpos$mutableblockpos.set(i2, j2, k2);
                                    if (p_66533_.ensureCanWrite(blockpos$mutableblockpos)) {
                                       LevelChunkSection levelchunksection = bulksectionaccess.getSection(blockpos$mutableblockpos);
                                       if (levelchunksection != LevelChunk.EMPTY_SECTION) {
                                          int i3 = SectionPos.sectionRelative(i2);
                                          int j3 = SectionPos.sectionRelative(j2);
                                          int k3 = SectionPos.sectionRelative(k2);
                                          BlockState blockstate = levelchunksection.getBlockState(i3, j3, k3);

                                          for(OreConfiguration.TargetBlockState oreconfiguration$targetblockstate : p_66535_.targetStates) {
                                             if (canPlaceOre(blockstate, bulksectionaccess::getBlockState, p_66534_, p_66535_, oreconfiguration$targetblockstate, blockpos$mutableblockpos)) {
                                                levelchunksection.setBlockState(i3, j3, k3, oreconfiguration$targetblockstate.state, false);
                                                ++i;
                                                break;
                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      } catch (Throwable throwable1) {
         try {
            bulksectionaccess.close();
         } catch (Throwable throwable) {
            throwable1.addSuppressed(throwable);
         }

         throw throwable1;
      }

      bulksectionaccess.close();
      return i > 0;
   }

   public static boolean canPlaceOre(BlockState p_160170_, Function<BlockPos, BlockState> p_160171_, Random p_160172_, OreConfiguration p_160173_, OreConfiguration.TargetBlockState p_160174_, BlockPos.MutableBlockPos p_160175_) {
      if (!p_160174_.target.test(p_160170_, p_160172_)) {
         return false;
      } else if (shouldSkipAirCheck(p_160172_, p_160173_.discardChanceOnAirExposure)) {
         return true;
      } else {
         return !isAdjacentToAir(p_160171_, p_160175_);
      }
   }

   protected static boolean shouldSkipAirCheck(Random p_160179_, float p_160180_) {
      if (p_160180_ <= 0.0F) {
         return true;
      } else if (p_160180_ >= 1.0F) {
         return false;
      } else {
         return p_160179_.nextFloat() >= p_160180_;
      }
   }
}

 

When entering OreConfiguration the following appears:

public class OreConfiguration implements FeatureConfiguration {
   public static final Codec<OreConfiguration> CODEC = RecordCodecBuilder.create((p_67849_) -> {
      return p_67849_.group(Codec.list(OreConfiguration.TargetBlockState.CODEC).fieldOf("targets").forGetter((p_161027_) -> {
         return p_161027_.targetStates;
      }), Codec.intRange(0, 64).fieldOf("size").forGetter((p_161025_) -> {
         return p_161025_.size;
      }), Codec.floatRange(0.0F, 1.0F).fieldOf("discard_chance_on_air_exposure").forGetter((p_161020_) -> {
         return p_161020_.discardChanceOnAirExposure;
      })).apply(p_67849_, OreConfiguration::new);
   });
   public final List<OreConfiguration.TargetBlockState> targetStates;
   public final int size;
   public final float discardChanceOnAirExposure;

   public OreConfiguration(List<OreConfiguration.TargetBlockState> p_161016_, int p_161017_, float p_161018_) {
      this.size = p_161017_;
      this.targetStates = p_161016_;
      this.discardChanceOnAirExposure = p_161018_;
   }

   public OreConfiguration(List<OreConfiguration.TargetBlockState> p_161013_, int p_161014_) {
      this(p_161013_, p_161014_, 0.0F);
   }

   public OreConfiguration(RuleTest p_161008_, BlockState p_161009_, int p_161010_, float p_161011_) {
      this(ImmutableList.of(new OreConfiguration.TargetBlockState(p_161008_, p_161009_)), p_161010_, p_161011_);
   }

   public OreConfiguration(RuleTest p_67843_, BlockState p_67844_, int p_67845_) {
      this(ImmutableList.of(new OreConfiguration.TargetBlockState(p_67843_, p_67844_)), p_67845_, 0.0F);
   }

   public static OreConfiguration.TargetBlockState target(RuleTest p_161022_, BlockState p_161023_) {
      return new OreConfiguration.TargetBlockState(p_161022_, p_161023_);
   }

   public static final class Predicates {
      public static final RuleTest NATURAL_STONE = new TagMatchTest(BlockTags.BASE_STONE_OVERWORLD);
      public static final RuleTest STONE_ORE_REPLACEABLES = new TagMatchTest(BlockTags.STONE_ORE_REPLACEABLES);
      public static final RuleTest DEEPSLATE_ORE_REPLACEABLES = new TagMatchTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES);
      public static final RuleTest NETHERRACK = new BlockMatchTest(Blocks.NETHERRACK);
      public static final RuleTest NETHER_ORE_REPLACEABLES = new TagMatchTest(BlockTags.BASE_STONE_NETHER);
   }

   public static class TargetBlockState {
      public static final Codec<OreConfiguration.TargetBlockState> CODEC = RecordCodecBuilder.create((p_161039_) -> {
         return p_161039_.group(RuleTest.CODEC.fieldOf("target").forGetter((p_161043_) -> {
            return p_161043_.target;
         }), BlockState.CODEC.fieldOf("state").forGetter((p_161041_) -> {
            return p_161041_.state;
         })).apply(p_161039_, OreConfiguration.TargetBlockState::new);
      });
      public final RuleTest target;
      public final BlockState state;

      TargetBlockState(RuleTest p_161036_, BlockState p_161037_) {
         this.target = p_161036_;
         this.state = p_161037_;
      }
   }
}

 

And this is the only code snippet that I can recognize to be part of the netherite:

   public OreConfiguration(RuleTest p_67843_, BlockState p_67844_, int p_67845_) {
      this(ImmutableList.of(new OreConfiguration.TargetBlockState(p_67843_, p_67844_)), p_67845_, 0.0F);
   }

 

Edited by Gianka1485
Link to comment
Share on other sites

 

For those who still don't have the code working, this was the solution I made to my project:

 

The config:

public class ExampleConfig {
    public static final Builder BUILDER = new Builder();
    public static final ForgeConfigSpec SPEC;
    public static final ConfigValue<Boolean> EXAMPLE_ORE_GENERATION;
    public static final ConfigValue<Integer> EXAMPLE_ORE_SIZE;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MIN_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MAX_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_CHANCE;

    public ExampleConfig() {
    }

    static {
        BUILDER.push("Example ore generation");
        EXAMPLE_ORE_GENERATION = BUILDER.define("Generate example ore", true);
        EXAMPLE_ORE_SIZE = BUILDER.define("Example ore vein size", 4);
        EXAMPLE_ORE_MIN_HEIGHT = BUILDER.define("Minimum example ore generation height", 0);
        EXAMPLE_ORE_MAX_HEIGHT = BUILDER.define("Maximum example ore generation height", 16);
        EXAMPLE_ORE_CHANCE = BUILDER.define("Chance of generate example ore", 1);
        BUILDER.pop();
        SPEC = BUILDER.build();
    }
}

 

The OreGeneration:

@EventBusSubscriber
public class OreGeneration {
    public static ImmutableList<TargetBlockState> EXAMPLE_ORE_TARGET_LIST;
    public static ConfiguredFeature<?, ?> EXAMPLE_ORE;

    public OreGeneration() {
    }

    public static void registerConfiguredFeatures() {
        EXAMPLE_ORE_TARGET_LIST = ImmutableList.of(OreConfiguration.target(Predicates.NATURAL_STONE, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()), OreConfiguration.target(Predicates.STONE_ORE_REPLACEABLES, ((Block) ExampleBlocks.EXAMPLE_ORE.get()).defaultBlockState()));
        EXAMPLE_ORE = (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(EXAMPLE_ORE_TARGET_LIST, (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get())).rangeUniform(VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get()), VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get()))).squared()).count((Integer) ExampleConfig.EXAMPLE_ORE_CHANCE.get());
        Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation("examplemod", "example_ore"), EXAMPLE_ORE);
    }

    @SubscribeEvent(priority = EventPriority.HIGH)
    public static void registerBiomeModification(BiomeLoadingEvent event) {
        registerConfiguredFeatures();
        event.getGeneration().getFeatures(Decoration.UNDERGROUND_ORES).add(() -> {
            return EXAMPLE_ORE;
        });
    }
}

 

The Main:

@Mod(Example.modid)
public class Example {
    public static Example instance;
    public static final String modid = "examplemod";
    private static final Logger LOGGER = LogManager.getLogger("examplemod");
    public static final CreativeModeTab gworld = new GWorldTab();

    public Examle() {
        instance = this;

        ExampleBlocks.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ExampleItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        ModLoadingContext.get().registerConfig(Type.COMMON, ExampleConfig.SPEC, "example-common.toml");

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        OreGeneration.registerConfiguredFeatures();
        LOGGER.info("Hello from preinit");
        LOGGER.info("Dirt block >> {}", Blocks.DIAMOND_ORE.getRegistryName());
    }

    @OnlyIn(Dist.CLIENT)
    public void clientSetup(FMLClientSetupEvent event) {
        LOGGER.info("Hello from client setup");
    }

    @SubscribeEvent
    public void serverStarting(FMLServerStartingEvent event) {
        LOGGER.info("Hello from server starting");
    }

    @EventBusSubscriber(bus = Bus.MOD)
    public static class RegistryEvents {
        public RegistryEvents() {
        }

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            LOGGER.info("Hello from Register Block");
        }
    }
}

 

Link to comment
Share on other sites

10 minutes ago, Luis_ST said:

why did you call registerConfiguredFeatures inside of BiomeLoadingEvent and FMLCommonSetupEvent,
you should only call it in FMLCommonSetupEvent

 

The mineral or mineral list is not generated if I remove "registerConfiguredFeatures" from "BiomeLoadingEvent"

Link to comment
Share on other sites

18 minutes ago, diesieben07 said:

What on earth does that sentence mean?

The thing is that BiomeLoadingEvent fires more than once, so it is not at all the correct place to register things.

If I start the minecraft client without "registerConfiguredFeatures" in "BiomeLoadingEvent", minecraft crashes .... XD

Link to comment
Share on other sites

31 minutes ago, diesieben07 said:

Did you do it in FMLCommonSetupEvent#enqueueWork like you were told?

After a while searching, I concluded that if in the vein size section, a value is set <4 then the mineral is not generated, and that it is not necessary to have "registerConfiguredFeatures" in "BiomeLoadingEvent".

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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