mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
add CraftEngine data provider
This commit is contained in:
@@ -195,6 +195,7 @@ allprojects {
|
|||||||
maven("https://mvn.lumine.io/repository/maven-public/") // mythic
|
maven("https://mvn.lumine.io/repository/maven-public/") // mythic
|
||||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/") //MMOItems
|
maven("https://nexus.phoenixdevt.fr/repository/maven-public/") //MMOItems
|
||||||
maven("https://repo.onarandombox.com/content/groups/public/") //Multiverse Core
|
maven("https://repo.onarandombox.com/content/groups/public/") //Multiverse Core
|
||||||
|
maven("https://repo.momirealms.net/releases/") //CraftEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ dependencies {
|
|||||||
isTransitive = false
|
isTransitive = false
|
||||||
}
|
}
|
||||||
compileOnly(libs.multiverseCore)
|
compileOnly(libs.multiverseCore)
|
||||||
|
compileOnly(libs.craftengine.core)
|
||||||
|
compileOnly(libs.craftengine.bukkit)
|
||||||
|
//compileOnly(libs.sparrowNbt)
|
||||||
|
|
||||||
// Shaded
|
// Shaded
|
||||||
implementation(slimjarHelper("spigot"))
|
implementation(slimjarHelper("spigot"))
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ public abstract class ExternalDataProvider implements Listener {
|
|||||||
protected static List<BlockProperty> YAW_FACE_BIOME_PROPERTIES = List.of(
|
protected static List<BlockProperty> YAW_FACE_BIOME_PROPERTIES = List.of(
|
||||||
BlockProperty.ofEnum(BiomeColor.class, "matchBiome", null),
|
BlockProperty.ofEnum(BiomeColor.class, "matchBiome", null),
|
||||||
BlockProperty.ofBoolean("randomYaw", false),
|
BlockProperty.ofBoolean("randomYaw", false),
|
||||||
BlockProperty.ofFloat("yaw", 0, 0, 360f, false, true),
|
BlockProperty.ofDouble("yaw", 0, 0, 360f, false, true),
|
||||||
BlockProperty.ofBoolean("randomFace", true),
|
BlockProperty.ofBoolean("randomFace", true),
|
||||||
new BlockProperty(
|
new BlockProperty(
|
||||||
"face",
|
"face",
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
|
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||||
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import com.volmit.iris.util.data.IrisCustomData;
|
||||||
|
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||||
|
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||||
|
import net.momirealms.craftengine.bukkit.api.CraftEngineItems;
|
||||||
|
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||||
|
import net.momirealms.craftengine.core.block.properties.BooleanProperty;
|
||||||
|
import net.momirealms.craftengine.core.block.properties.IntegerProperty;
|
||||||
|
import net.momirealms.craftengine.core.block.properties.Property;
|
||||||
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class CraftEngineDataProvider extends ExternalDataProvider {
|
||||||
|
|
||||||
|
public CraftEngineDataProvider() {
|
||||||
|
super("CraftEngine");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
||||||
|
var block = CraftEngineBlocks.byId(Key.of(blockId.namespace(), blockId.key()));
|
||||||
|
if (block == null) throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
return block.properties()
|
||||||
|
.stream()
|
||||||
|
.map(CraftEngineDataProvider::convert)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
|
var item = CraftEngineItems.byId(Key.of(itemId.namespace(), itemId.key()));
|
||||||
|
if (item == null) throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
|
return item.buildItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
|
var key = Key.of(blockId.namespace(), blockId.key());
|
||||||
|
if (CraftEngineBlocks.byId(key) == null && CraftEngineFurniture.byId(key) == null)
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
return new IrisCustomData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
|
var pair = ExternalDataSVC.parseState(blockId);
|
||||||
|
var key = Key.of(blockId.namespace(), blockId.key());
|
||||||
|
var state = pair.getB();
|
||||||
|
|
||||||
|
var customBlock = CraftEngineBlocks.byId(key);
|
||||||
|
if (customBlock != null) {
|
||||||
|
ImmutableBlockState blockState = customBlock.defaultState();
|
||||||
|
|
||||||
|
for (var entry : state.entrySet()) {
|
||||||
|
var property = customBlock.getProperty(entry.getKey());
|
||||||
|
if (property == null) continue;
|
||||||
|
var tag = property.optional(entry.getValue()).orElse(null);
|
||||||
|
if (tag == null) continue;
|
||||||
|
blockState = ImmutableBlockState.with(blockState, property, tag);
|
||||||
|
}
|
||||||
|
CraftEngineBlocks.place(block.getLocation(), blockState, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var furniture = CraftEngineFurniture.byId(key);
|
||||||
|
if (furniture == null) return;
|
||||||
|
CraftEngineFurniture.place(block.getLocation(), furniture, furniture.getAnyAnchorType(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
|
return (switch (dataType) {
|
||||||
|
case ENTITY -> Stream.<Key>empty();
|
||||||
|
case ITEM -> CraftEngineItems.loadedItems().keySet().stream();
|
||||||
|
case BLOCK -> Stream.concat(CraftEngineBlocks.loadedBlocks().keySet().stream(),
|
||||||
|
CraftEngineFurniture.loadedFurniture().keySet().stream());
|
||||||
|
}).map(key -> new Identifier(key.namespace(), key.value())).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
|
Key key = Key.of(id.namespace(), id.key());
|
||||||
|
return switch (dataType) {
|
||||||
|
case ENTITY -> false;
|
||||||
|
case ITEM -> CraftEngineItems.byId(key) != null;
|
||||||
|
case BLOCK -> (CraftEngineBlocks.byId(key) != null || CraftEngineFurniture.byId(key) != null);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends Comparable<T>> BlockProperty convert(Property<T> raw) {
|
||||||
|
return switch (raw) {
|
||||||
|
case BooleanProperty property -> BlockProperty.ofBoolean(property.name(), property.defaultValue());
|
||||||
|
case IntegerProperty property -> BlockProperty.ofLong(property.name(), property.defaultValue(), property.min, property.max, false, false);
|
||||||
|
default -> new BlockProperty(raw.name(), raw.valueClass(), raw.defaultValue(), raw.possibleValues(), raw::valueName);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ public class BlockProperty {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockProperty ofFloat(String name, float defaultValue, float min, float max, boolean exclusiveMin, boolean exclusiveMax) {
|
public static BlockProperty ofDouble(String name, float defaultValue, float min, float max, boolean exclusiveMin, boolean exclusiveMax) {
|
||||||
return new BoundedDouble(
|
return new BoundedDouble(
|
||||||
name,
|
name,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
@@ -54,6 +54,18 @@ public class BlockProperty {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BlockProperty ofLong(String name, long defaultValue, long min, long max, boolean exclusiveMin, boolean exclusiveMax) {
|
||||||
|
return new BoundedLong(
|
||||||
|
name,
|
||||||
|
defaultValue,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
exclusiveMin,
|
||||||
|
exclusiveMax,
|
||||||
|
(l) -> Long.toString(l)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static BlockProperty ofBoolean(String name, boolean defaultValue) {
|
public static BlockProperty ofBoolean(String name, boolean defaultValue) {
|
||||||
return new BlockProperty(
|
return new BlockProperty(
|
||||||
name,
|
name,
|
||||||
@@ -122,6 +134,36 @@ public class BlockProperty {
|
|||||||
return Objects.hash(name, values, type);
|
return Objects.hash(name, values, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class BoundedLong extends BlockProperty {
|
||||||
|
private final long min, max;
|
||||||
|
private final boolean exclusiveMin, exclusiveMax;
|
||||||
|
|
||||||
|
public BoundedLong(
|
||||||
|
String name,
|
||||||
|
long defaultValue,
|
||||||
|
long min,
|
||||||
|
long max,
|
||||||
|
boolean exclusiveMin,
|
||||||
|
boolean exclusiveMax,
|
||||||
|
Function<Long, String> nameFunction
|
||||||
|
) {
|
||||||
|
super(name, Long.class, defaultValue, List.of(), nameFunction);
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
this.exclusiveMin = exclusiveMin;
|
||||||
|
this.exclusiveMax = exclusiveMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject buildJson() {
|
||||||
|
return super.buildJson()
|
||||||
|
.put("minimum", min)
|
||||||
|
.put("maximum", max)
|
||||||
|
.put("exclusiveMinimum", exclusiveMin)
|
||||||
|
.put("exclusiveMaximum", exclusiveMax);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class BoundedDouble extends BlockProperty {
|
private static class BoundedDouble extends BlockProperty {
|
||||||
private final double min, max;
|
private final double min, max;
|
||||||
private final boolean exclusiveMin, exclusiveMax;
|
private final boolean exclusiveMin, exclusiveMax;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ mythic = "5.9.5"
|
|||||||
mythic-chrucible = "2.1.0"
|
mythic-chrucible = "2.1.0"
|
||||||
kgenerators = "7.3" # https://repo.codemc.io/repository/maven-public/me/kryniowesegryderiusz/kgenerators-core/maven-metadata.xml
|
kgenerators = "7.3" # https://repo.codemc.io/repository/maven-public/me/kryniowesegryderiusz/kgenerators-core/maven-metadata.xml
|
||||||
multiverseCore = "5.1.0"
|
multiverseCore = "5.1.0"
|
||||||
|
craftengine = "0.0.63" # https://github.com/Xiao-MoMi/craft-engine/releases
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
# Core Libraries
|
# Core Libraries
|
||||||
@@ -110,6 +111,8 @@ mythic = { module = "io.lumine:Mythic-Dist", version.ref = "mythic" }
|
|||||||
mythicChrucible = { module = "io.lumine:MythicCrucible-Dist", version.ref = "mythic-chrucible" }
|
mythicChrucible = { module = "io.lumine:MythicCrucible-Dist", version.ref = "mythic-chrucible" }
|
||||||
kgenerators = { module = "me.kryniowesegryderiusz:kgenerators-core", version.ref = "kgenerators" }
|
kgenerators = { module = "me.kryniowesegryderiusz:kgenerators-core", version.ref = "kgenerators" }
|
||||||
multiverseCore = { module = "org.mvplugins.multiverse.core:multiverse-core", version.ref = "multiverseCore" }
|
multiverseCore = { module = "org.mvplugins.multiverse.core:multiverse-core", version.ref = "multiverseCore" }
|
||||||
|
craftengine-core = { module = "net.momirealms:craft-engine-core", version.ref = "craftengine" }
|
||||||
|
craftengine-bukkit = { module = "net.momirealms:craft-engine-bukkit", version.ref = "craftengine" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
|
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
|
||||||
|
|||||||
Reference in New Issue
Block a user