mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 00:05:59 +00:00
implement auto completion for block properties
This commit is contained in:
parent
e5f3bbd69e
commit
d76affa005
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@ -36,9 +37,9 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
public interface INMSBinding {
|
||||
boolean hasTile(Material material);
|
||||
@ -133,4 +134,6 @@ public interface INMSBinding {
|
||||
default boolean injectBukkit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
KMap<Material, List<BlockProperty>> getBlockProperties();
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.volmit.iris.core.nms.container;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public record BlockProperty(String name, String defaultValue, Set<String> value) {
|
||||
public static <T> BlockProperty of(String name, T defaultValue, Collection<T> values, Function<T, String> nameFunction) {
|
||||
return new BlockProperty(name, nameFunction.apply(defaultValue), values.stream().map(nameFunction).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return name + "=" + defaultValue + " [" + String.join(",", value) + "]";
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ package com.volmit.iris.core.nms.v1X;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
@ -40,6 +41,7 @@ import org.bukkit.generator.structure.Structure;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class NMSBinding1X implements INMSBinding {
|
||||
@ -124,6 +126,15 @@ public class NMSBinding1X implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> map = new KMap<>();
|
||||
for (Material m : Material.values()) {
|
||||
if (m.isBlock()) map.put(m, List.of());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeEntity(Entity location) {
|
||||
return null;
|
||||
|
@ -39,8 +39,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SchemaBuilder {
|
||||
@ -113,6 +115,7 @@ public class SchemaBuilder {
|
||||
o.put("description", getDescription(c));
|
||||
o.put("type", getType(c));
|
||||
JSONArray required = new JSONArray();
|
||||
JSONArray extended = new JSONArray();
|
||||
|
||||
if (c.isAssignableFrom(IrisRegistrant.class) || IrisRegistrant.class.isAssignableFrom(c)) {
|
||||
for (Field k : IrisRegistrant.class.getDeclaredFields()) {
|
||||
@ -124,11 +127,15 @@ public class SchemaBuilder {
|
||||
|
||||
JSONObject property = buildProperty(k, c);
|
||||
|
||||
if (property.getBoolean("!required")) {
|
||||
if (Boolean.TRUE == property.remove("!required")) {
|
||||
required.put(k.getName());
|
||||
}
|
||||
|
||||
property.remove("!required");
|
||||
if (Boolean.TRUE == property.remove("!top")) {
|
||||
extended.put(property);
|
||||
continue;
|
||||
}
|
||||
|
||||
properties.put(k.getName(), property);
|
||||
}
|
||||
}
|
||||
@ -142,15 +149,24 @@ public class SchemaBuilder {
|
||||
|
||||
JSONObject property = buildProperty(k, c);
|
||||
|
||||
if (property.getBoolean("!required"))
|
||||
if (Boolean.TRUE == property.remove("!required")) {
|
||||
required.put(k.getName());
|
||||
property.remove("!required");
|
||||
}
|
||||
|
||||
if (Boolean.TRUE == property.remove("!top")) {
|
||||
extended.put(property);
|
||||
continue;
|
||||
}
|
||||
|
||||
properties.put(k.getName(), property);
|
||||
}
|
||||
|
||||
if (required.length() > 0) {
|
||||
o.put("required", required);
|
||||
}
|
||||
if (extended.length() > 0) {
|
||||
o.put("allOf", extended);
|
||||
}
|
||||
|
||||
o.put("properties", properties);
|
||||
|
||||
@ -343,13 +359,65 @@ public class SchemaBuilder {
|
||||
}
|
||||
}
|
||||
case "object" -> {
|
||||
fancyType = k.getType().getSimpleName().replaceAll("\\QIris\\E", "") + " (Object)";
|
||||
String key = "obj-" + k.getType().getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(k.getType()));
|
||||
//TODO add back descriptions
|
||||
if (k.isAnnotationPresent(RegistryMapBlockState.class)) {
|
||||
String blockType = k.getDeclaredAnnotation(RegistryMapBlockState.class).value();
|
||||
fancyType = "Block State";
|
||||
prop.put("!top", true);
|
||||
JSONArray any = new JSONArray();
|
||||
prop.put("anyOf", any);
|
||||
|
||||
B.getBlockStates().forEach((blocks, properties) -> {
|
||||
if (blocks.isEmpty()) return;
|
||||
|
||||
String raw = blocks.getFirst().replace(':', '_');
|
||||
String enumKey = "enum-block-state-" + raw;
|
||||
String propertiesKey = "obj-block-state-" + raw;
|
||||
|
||||
any.put(new JSONObject()
|
||||
.put("if", new JSONObject()
|
||||
.put("properties", new JSONObject()
|
||||
.put(blockType, new JSONObject()
|
||||
.put("type", "string")
|
||||
.put("$ref", "#/definitions/" + enumKey))))
|
||||
.put("then", new JSONObject()
|
||||
.put("properties", new JSONObject()
|
||||
.put(k.getName(), new JSONObject()
|
||||
.put("type", "object")
|
||||
.put("$ref", "#/definitions/" + propertiesKey))))
|
||||
.put("else", false));
|
||||
|
||||
if (!definitions.containsKey(enumKey)) {
|
||||
JSONArray filters = new JSONArray();
|
||||
blocks.forEach(filters::put);
|
||||
|
||||
definitions.put(enumKey, new JSONObject()
|
||||
.put("type", "string")
|
||||
.put("enum", filters));
|
||||
}
|
||||
|
||||
if (!definitions.containsKey(propertiesKey)) {
|
||||
JSONObject props = new JSONObject();
|
||||
properties.forEach(property -> {
|
||||
JSONArray values = new JSONArray();
|
||||
property.value().forEach(values::put);
|
||||
props.put(property.name(), new JSONObject().put("enum", values));
|
||||
});
|
||||
|
||||
definitions.put(propertiesKey, new JSONObject()
|
||||
.put("type", "object")
|
||||
.put("properties", props));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fancyType = k.getType().getSimpleName().replaceAll("\\QIris\\E", "") + " (Object)";
|
||||
String key = "obj-" + k.getType().getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(k.getType()));
|
||||
}
|
||||
prop.put("$ref", "#/definitions/" + key);
|
||||
}
|
||||
prop.put("$ref", "#/definitions/" + key);
|
||||
}
|
||||
case "array" -> {
|
||||
fancyType = "List of Something...?";
|
||||
|
@ -61,8 +61,13 @@ public class IrisBlockData extends IrisRegistrant {
|
||||
private int weight = 1;
|
||||
@Desc("If the block cannot be created on this version, Iris will attempt to use this backup block data instead.")
|
||||
private IrisBlockData backup = null;
|
||||
@RegistryMapBlockState("block")
|
||||
@Desc("Optional properties for this block data such as 'waterlogged': true")
|
||||
private KMap<String, Object> data = new KMap<>();
|
||||
@RegistryMapBlockState("block")
|
||||
@ArrayType(type = KMap.class)
|
||||
@Desc("Optional properties for this block data such as 'waterlogged': true")
|
||||
private KList<KMap<String, Object>> altData = new KList<>();
|
||||
@Desc("Optional tile data for this block data")
|
||||
private KMap<String, Object> tileData = new KMap<>();
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.volmit.iris.engine.object.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface RegistryMapBlockState {
|
||||
String value();
|
||||
}
|
@ -22,6 +22,8 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.link.Identifier;
|
||||
import com.volmit.iris.core.link.data.DataType;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
@ -35,10 +37,7 @@ import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Leaves;
|
||||
import org.bukkit.block.data.type.PointedDripstone;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.bukkit.Material.*;
|
||||
@ -681,6 +680,26 @@ public class B {
|
||||
return bt.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public synchronized static KMap<List<String>, List<BlockProperty>> getBlockStates() {
|
||||
KMap<List<BlockProperty>, List<String>> flipped = new KMap<>();
|
||||
INMS.get().getBlockProperties().forEach((k, v) -> {
|
||||
flipped.computeIfAbsent(v, $ -> new KList<>()).add(k.getKey().toString());
|
||||
});
|
||||
|
||||
var emptyStates = flipped.computeIfAbsent(new KList<>(0), $ -> new KList<>());
|
||||
for (Identifier id : Iris.service(ExternalDataSVC.class).getAllIdentifiers(DataType.BLOCK))
|
||||
emptyStates.add(id.toString());
|
||||
emptyStates.addAll(custom.k());
|
||||
|
||||
KMap<List<String>, List<BlockProperty>> states = new KMap<>();
|
||||
flipped.forEach((k, v) -> {
|
||||
var old = states.put(v, k);
|
||||
if (old != null) Iris.error("Duplicate block state: " + v + " (" + old + " and " + k + ")");
|
||||
});
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
public static String[] getItemTypes() {
|
||||
KList<String> bt = new KList<>();
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@ -47,6 +48,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
@ -68,6 +70,7 @@ import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
@ -679,6 +682,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().registryOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@ -48,6 +49,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
@ -68,6 +70,7 @@ import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -682,6 +685,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().registryOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@ -48,6 +49,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
@ -68,6 +70,7 @@ import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -683,6 +686,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().registryOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -49,6 +50,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -69,6 +71,7 @@ import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R4.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_20_R4.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -701,6 +704,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().registryOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -52,6 +53,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -73,6 +75,7 @@ import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -712,6 +715,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().registryOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -4,6 +4,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -49,6 +50,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -70,6 +72,7 @@ import org.bukkit.craftbukkit.v1_21_R2.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -709,6 +712,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().lookupOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -4,6 +4,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -50,6 +51,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -71,6 +73,7 @@ import org.bukkit.craftbukkit.v1_21_R3.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -709,6 +712,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().lookupOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -4,6 +4,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -49,6 +50,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -71,6 +73,7 @@ import org.bukkit.craftbukkit.v1_21_R4.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -709,6 +712,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().lookupOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
@ -4,6 +4,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -49,6 +50,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
@ -70,6 +72,7 @@ import org.bukkit.craftbukkit.v1_21_R5.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_21_R5.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_21_R5.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_21_R5.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R5.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_21_R5.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -708,6 +711,28 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
for (var block : registry().lookupOrThrow(Registries.BLOCK)) {
|
||||
var state = block.defaultBlockState();
|
||||
if (state == null) state = block.getStateDefinition().any();
|
||||
final var finalState = state;
|
||||
|
||||
states.put(CraftMagicNumbers.getMaterial(block), block.getStateDefinition()
|
||||
.getProperties()
|
||||
.stream()
|
||||
.map(p -> createProperty(p, finalState))
|
||||
.toList());
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> BlockProperty createProperty(Property<T> property, BlockState state) {
|
||||
return BlockProperty.of(property.getName(), state.getValue(property), property.getPossibleValues(), property::getName);
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user