mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 04:46:37 +00:00
一点小更改
This commit is contained in:
@@ -2,18 +2,55 @@ package net.momirealms.craftengine.bukkit.compatibility.skript.classes;
|
||||
|
||||
import ch.njol.skript.classes.ClassInfo;
|
||||
import ch.njol.skript.classes.Parser;
|
||||
import ch.njol.skript.classes.Serializer;
|
||||
import ch.njol.skript.lang.ParseContext;
|
||||
import ch.njol.skript.registrations.Classes;
|
||||
import ch.njol.yggdrasil.Fields;
|
||||
import net.momirealms.craftengine.core.block.BlockStateParser;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.StreamCorruptedException;
|
||||
|
||||
public class CraftEngineClasses {
|
||||
|
||||
public static void register() {
|
||||
Classes.registerClass(new ClassInfo<>(ImmutableBlockState.class, "customblockstate")
|
||||
.user("custom block state")
|
||||
.name("Custom Block State")
|
||||
.serializer(new Serializer<>() {
|
||||
@Override
|
||||
public Fields serialize(ImmutableBlockState o) {
|
||||
Fields f = new Fields();
|
||||
f.putObject("customblockstate", o.toString());
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ImmutableBlockState o, Fields f) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableBlockState deserialize(Fields f) throws StreamCorruptedException {
|
||||
String data = f.getObject("customblockstate", String.class);
|
||||
assert data != null;
|
||||
try {
|
||||
return BlockStateParser.deserialize(data);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new StreamCorruptedException("Invalid block data: " + data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustSyncDeserialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canBeInstantiated() {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.parser(new Parser<>() {
|
||||
@Override
|
||||
public String toString(ImmutableBlockState o, int flags) {
|
||||
@@ -31,5 +68,26 @@ public class CraftEngineClasses {
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Classes.registerClass(new ClassInfo<>(CustomBlock.class, "customblocks")
|
||||
// .user("custom block")
|
||||
// .name("Custom Block")
|
||||
// .parser(new Parser<>() {
|
||||
// @Override
|
||||
// public String toString(CustomBlock o, int flags) {
|
||||
// return o.id().toString();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toVariableNameString(CustomBlock o) {
|
||||
// return "customblock:" + o.id();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @Nullable CustomBlock parse(String s, ParseContext context) {
|
||||
// return BuiltInRegistries.BLOCK.getValue(Key.of(s));
|
||||
// }
|
||||
// })
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ public class ExprBlockCustomBlockID extends SimplePropertyExpression<Object, Str
|
||||
|
||||
@Override
|
||||
public @Nullable String convert(Object object) {
|
||||
System.out.println(object.getClass());
|
||||
if (object instanceof ImmutableBlockState immutableBlockState)
|
||||
return immutableBlockState.owner().value().id().toString();
|
||||
if (object instanceof CustomBlock customBlock)
|
||||
|
||||
@@ -22,6 +22,10 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
||||
this.item.setAmount(count);
|
||||
}
|
||||
|
||||
public void removeComponent(Object type) {
|
||||
FastNMS.INSTANCE.removeComponent(this.getLiteralObject(), ensureDataComponentType(type));
|
||||
}
|
||||
|
||||
public void resetComponent(Object type) {
|
||||
FastNMS.INSTANCE.resetComponent(this.getLiteralObject(), ensureDataComponentType(type));
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected void removeComponent(ComponentItemWrapper item, Object type) {
|
||||
item.resetComponent(type);
|
||||
item.removeComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||
import net.momirealms.craftengine.bukkit.advancement.BukkitAdvancementManager;
|
||||
import net.momirealms.craftengine.bukkit.api.event.CraftEngineReloadEvent;
|
||||
|
||||
Reference in New Issue
Block a user