-
-
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
234 changed files
with
3,611 additions
and
26,381 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
api/src/main/java/de/derfrzocker/feature/api/FeatureGenerator.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,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); | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
api/src/main/java/de/derfrzocker/feature/api/PlacementModifierConfiguration.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,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
53
api/src/main/java/de/derfrzocker/feature/api/Registries.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,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
81
api/src/main/java/de/derfrzocker/feature/api/Registry.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,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()); | ||
} | ||
} |
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,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
36
api/src/main/java/de/derfrzocker/feature/api/ValueType.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,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(); | ||
} |
Oops, something went wrong.