-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
204 additions
and
7 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...in/java/de/derfrzocker/feature/impl/v1_18_R1/feature/generator/ScatteredOreGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2019 - 2021 Marvin (DerFrZocker) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package de.derfrzocker.feature.impl.v1_18_R1.feature.generator; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import de.derfrzocker.feature.api.Registries; | ||
import de.derfrzocker.feature.common.value.number.FloatType; | ||
import de.derfrzocker.feature.common.value.number.FloatValue; | ||
import de.derfrzocker.feature.common.value.number.IntegerType; | ||
import de.derfrzocker.feature.common.value.number.IntegerValue; | ||
import de.derfrzocker.feature.impl.v1_18_R1.feature.generator.configuration.OreFeatureConfiguration; | ||
import de.derfrzocker.feature.impl.v1_18_R1.value.target.TargetType; | ||
import de.derfrzocker.feature.impl.v1_18_R1.value.target.TargetValue; | ||
import net.minecraft.world.level.levelgen.feature.OreFeature; | ||
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; | ||
import org.bukkit.generator.LimitedRegion; | ||
import org.bukkit.generator.WorldInfo; | ||
import org.bukkit.util.BlockVector; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
|
||
public class ScatteredOreGenerator extends MinecraftFeatureGenerator<OreConfiguration, OreFeatureConfiguration> { | ||
|
||
public ScatteredOreGenerator(Registries registries) { | ||
super(registries, OreFeature.SCATTERED_ORE, "scattered_ore"); | ||
} | ||
|
||
public Codec<OreFeatureConfiguration> createCodec(Registries registries) { | ||
return RecordCodecBuilder.create((builder) -> builder.group( | ||
Codec.list(registries.getValueTypeRegistry(TargetType.class). | ||
dispatch("target_type", TargetValue::getValueType, TargetType::getCodec)). | ||
optionalFieldOf("targets"). | ||
forGetter(config -> Optional.ofNullable(config.getTargets())), | ||
registries.getValueTypeRegistry(IntegerType.class).dispatch("size_type", IntegerValue::getValueType, IntegerType::getCodec). | ||
optionalFieldOf("size").forGetter(config -> Optional.ofNullable(config.getSize())), | ||
registries.getValueTypeRegistry(FloatType.class).dispatch("discard_chance_on_air_exposure_type", FloatValue::getValueType, FloatType::getCodec). | ||
optionalFieldOf("discard_chance_on_air_exposure").forGetter(config -> Optional.ofNullable(config.getDiscardChanceOnAirExposure())) | ||
).apply(builder, (targets, size, discardChanceOnAirExposure) -> new OreFeatureConfiguration(this, targets.orElse(null), size.orElse(null), discardChanceOnAirExposure.orElse(null)))); | ||
} | ||
|
||
@Override | ||
public OreFeatureConfiguration mergeConfig(OreFeatureConfiguration first, OreFeatureConfiguration second) { | ||
return new OreFeatureConfiguration(this, | ||
first.getTargets() != null ? first.getTargets() : second.getTargets(), | ||
first.getSize() != null ? first.getSize() : second.getSize(), | ||
first.getDiscardChanceOnAirExposure() != null ? first.getDiscardChanceOnAirExposure() : second.getDiscardChanceOnAirExposure()); | ||
} | ||
|
||
@Override | ||
public OreConfiguration createConfiguration(@NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion, @NotNull OreFeatureConfiguration configuration) { | ||
List<OreConfiguration.TargetBlockState> blockStates = new ArrayList<>(); | ||
if (configuration.getTargets() != null) { | ||
for (TargetValue targetValue : configuration.getTargets()) { | ||
blockStates.add(targetValue.getValue(worldInfo, random, position, limitedRegion)); | ||
} | ||
} | ||
|
||
int size = 0; | ||
if (configuration.getSize() != null) { | ||
size = configuration.getSize().getValue(worldInfo, random, position, limitedRegion); | ||
} | ||
|
||
float discardChanceOnAirExposure = 0f; | ||
if (configuration.getDiscardChanceOnAirExposure() != null) { | ||
discardChanceOnAirExposure = configuration.getDiscardChanceOnAirExposure().getValue(worldInfo, random, position, limitedRegion); | ||
} | ||
|
||
return new OreConfiguration(blockStates, size, discardChanceOnAirExposure); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...rzocker/ore/control/impl/v1_18_R1/feature/generator/ScatteredOreFeatureGeneratorHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2019 - 2021 Marvin (DerFrZocker) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package de.derfrzocker.ore.control.impl.v1_18_R1.feature.generator; | ||
|
||
import de.derfrzocker.feature.api.Registries; | ||
import de.derfrzocker.feature.impl.v1_18_R1.feature.generator.configuration.OreFeatureConfiguration; | ||
import de.derfrzocker.feature.impl.v1_18_R1.value.target.TargetValue; | ||
import de.derfrzocker.ore.control.api.Biome; | ||
import de.derfrzocker.ore.control.api.dao.ConfigDao; | ||
import net.minecraft.world.level.levelgen.feature.Feature; | ||
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.generator.LimitedRegion; | ||
import org.bukkit.generator.WorldInfo; | ||
import org.bukkit.util.BlockVector; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class ScatteredOreFeatureGeneratorHook extends MinecraftFeatureGeneratorHook<OreConfiguration, OreFeatureConfiguration> { | ||
|
||
public ScatteredOreFeatureGeneratorHook(@NotNull Registries registries, ConfigDao configDao, @NotNull NamespacedKey namespacedKey, @NotNull Biome biome) { | ||
super(OreConfiguration.CODEC, Feature.SCATTERED_ORE, registries, configDao, "scattered_ore", biome, namespacedKey); | ||
} | ||
|
||
@Override | ||
public OreConfiguration createConfig(@NotNull OreConfiguration defaultConfiguration, @NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion, @NotNull OreFeatureConfiguration configuration) { | ||
List<OreConfiguration.TargetBlockState> blockStates; | ||
if (configuration.getTargets() == null) { | ||
blockStates = defaultConfiguration.targetStates; | ||
} else { | ||
blockStates = new ArrayList<>(); | ||
|
||
for (TargetValue targetValue : configuration.getTargets()) { | ||
blockStates.add(targetValue.getValue(worldInfo, random, position, limitedRegion)); | ||
} | ||
} | ||
|
||
int size; | ||
if (configuration.getSize() == null) { | ||
size = defaultConfiguration.size; | ||
} else { | ||
size = configuration.getSize().getValue(worldInfo, random, position, limitedRegion); | ||
} | ||
|
||
float discardChanceOnAirExposure; | ||
if (configuration.getDiscardChanceOnAirExposure() == null) { | ||
discardChanceOnAirExposure = defaultConfiguration.discardChanceOnAirExposure; | ||
} else { | ||
discardChanceOnAirExposure = configuration.getDiscardChanceOnAirExposure().getValue(worldInfo, random, position, limitedRegion); | ||
} | ||
|
||
return new OreConfiguration(blockStates, size, discardChanceOnAirExposure); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters