Skip to content

Commit

Permalink
First push of v2 1.18.1
Browse files Browse the repository at this point in the history
Took 14 hours 52 minutes
  • Loading branch information
DerFrZocker committed Dec 31, 2021
1 parent 12fa316 commit 5c63b42
Show file tree
Hide file tree
Showing 234 changed files with 3,611 additions and 26,381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
*
*/

package de.derfrzocker.ore.control.api.dao;
package de.derfrzocker.feature.api;

import de.derfrzocker.ore.control.api.WorldOreConfig;
import de.derfrzocker.spigot.utils.dao.BasicDao;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Keyed;

public interface WorldOreConfigDao extends BasicDao<String, WorldOreConfig> {
import java.util.List;

@NotNull
WorldOreConfig getGlobalWorldOreConfig();
public interface Feature<C extends FeatureGeneratorConfiguration> extends Keyed {

List<FeaturePlacementModifier> getPlacementPositions();

FeatureGenerator<C> getGenerator();
}
44 changes: 44 additions & 0 deletions api/src/main/java/de/derfrzocker/feature/api/FeatureGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.api;

import com.mojang.serialization.Codec;
import org.bukkit.Keyed;
import org.bukkit.generator.LimitedRegion;
import org.bukkit.generator.WorldInfo;
import org.bukkit.util.BlockVector;
import org.jetbrains.annotations.NotNull;

import java.util.Random;

public interface FeatureGenerator<C extends FeatureGeneratorConfiguration> extends Keyed {

Codec<FeatureGeneratorConfiguration> getCodec();

C merge(FeatureGeneratorConfiguration first, FeatureGeneratorConfiguration second);

void place(@NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion, @NotNull C configuration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*
*/

package de.derfrzocker.ore.control.api;
package de.derfrzocker.feature.api;

public enum ConfigType {
public interface FeatureGeneratorConfiguration {

OVERWORLD, NETHER, TEMPLATE, GLOBAL, UNKNOWN
FeatureGenerator<?> getFeatureGenerator();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@
*
*/

package de.derfrzocker.ore.control.impl.v1_16_R2;
package de.derfrzocker.feature.api;

import net.minecraft.server.v1_16_R2.WorldGenDecoratorHeightAverageConfiguration;
import com.mojang.serialization.Codec;
import org.bukkit.Keyed;
import org.bukkit.generator.LimitedRegion;
import org.bukkit.generator.WorldInfo;
import org.bukkit.util.BlockVector;
import org.jetbrains.annotations.NotNull;

public class DepthAveragedCombinedConfiguration {
import java.util.Random;
import java.util.stream.Stream;

private final int veinCount;
@NotNull
private final WorldGenDecoratorHeightAverageConfiguration configuration;
public interface FeaturePlacementModifier<C extends PlacementModifierConfiguration> extends Keyed {

public DepthAveragedCombinedConfiguration(final int veinCount, @NotNull final WorldGenDecoratorHeightAverageConfiguration configuration) {
this.veinCount = veinCount;
this.configuration = configuration;
}
Codec<PlacementModifierConfiguration> getCodec();

public int getVeinCount() {
return this.veinCount;
}

@NotNull
public WorldGenDecoratorHeightAverageConfiguration getConfiguration() {
return configuration;
}
C merge(PlacementModifierConfiguration first, PlacementModifierConfiguration second);

Stream<BlockVector> getPositions(@NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion, @NotNull C configuration);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.api;

public interface PlacementModifierConfiguration {

FeaturePlacementModifier<?> getPlacementModifier();

}
53 changes: 53 additions & 0 deletions api/src/main/java/de/derfrzocker/feature/api/Registries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.api;

import java.util.LinkedHashMap;
import java.util.Map;

public class Registries {

private final Registry<Feature<?>> featureRegistry = new Registry<>();
private final Registry<FeatureGenerator<?>> featureGeneratorRegistry = new Registry<>();
private final Registry<FeaturePlacementModifier<?>> placementModifierRegistry = new Registry<>();
private final Map<Class<?>, Registry<?>> valueTypeRegistry = new LinkedHashMap<>();

public Registry<Feature<?>> getFeatureRegistry() {
return featureRegistry;
}

public Registry<FeatureGenerator<?>> getFeatureGeneratorRegistry() {
return featureGeneratorRegistry;
}

public Registry<FeaturePlacementModifier<?>> getPlacementModifierRegistry() {
return placementModifierRegistry;
}

public <O extends ValueType<?, O, ?>> Registry<O> getValueTypeRegistry(Class<O> clazz) {
return (Registry<O>) valueTypeRegistry.computeIfAbsent(clazz, aClass -> new Registry<>());
}
}
81 changes: 81 additions & 0 deletions api/src/main/java/de/derfrzocker/feature/api/Registry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.api;

import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Lifecycle;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

public class Registry<V extends Keyed> implements Codec<V> {

public static final Codec<NamespacedKey> KEY_GODEC = Codec.STRING.comapFlatMap(value -> {
if (value == null || value.isEmpty()) {
return DataResult.error("Value is null or empty");
}
NamespacedKey namespacedKey = NamespacedKey.fromString(value);
if (namespacedKey == null) {
return DataResult.error("Value " + value + " could not be parsed to a NamespaceKey");
}

return DataResult.success(namespacedKey);
}, NamespacedKey::toString);

private final Map<NamespacedKey, V> values = new LinkedHashMap<>();

public Optional<V> get(NamespacedKey key) {
return Optional.ofNullable(values.get(key));
}

public void register(V value) {
values.put(value.getKey(), value);
}

public Map<NamespacedKey, V> getValues() {
return values;
}

@Override
public <T> DataResult<Pair<V, T>> decode(DynamicOps<T> ops, T input) {
return KEY_GODEC.
decode(ops, input).
flatMap(result -> get(result.getFirst()).
map(v -> DataResult.success(Pair.of(v, result.getSecond()), Lifecycle.experimental())).
orElseGet(() -> DataResult.error("No value for key " + result.getFirst() + " registerd")));
}

@Override
public <T> DataResult<T> encode(V input, DynamicOps<T> ops, T prefix) {
return ops.mergeToPrimitive(prefix, ops.createString(input.getKey().toString())).setLifecycle(Lifecycle.experimental());
}
}
40 changes: 40 additions & 0 deletions api/src/main/java/de/derfrzocker/feature/api/Value.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.api;

import org.bukkit.generator.LimitedRegion;
import org.bukkit.generator.WorldInfo;
import org.bukkit.util.BlockVector;
import org.jetbrains.annotations.NotNull;

import java.util.Random;

public interface Value<V extends Value<V, T, O>, T extends ValueType<V, T, O>, O> {

T getValueType();

O getValue(@NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion);
}
36 changes: 36 additions & 0 deletions api/src/main/java/de/derfrzocker/feature/api/ValueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.api;

import com.mojang.serialization.Codec;
import org.bukkit.Keyed;

public interface ValueType<V extends Value<V, T, O>, T extends ValueType<V, T, O>, O> extends Keyed {

Codec<V> getCodec();

Class<O> getTypeClass();
}
Loading

0 comments on commit 5c63b42

Please sign in to comment.