mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +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.ClassInfo;
|
||||||
import ch.njol.skript.classes.Parser;
|
import ch.njol.skript.classes.Parser;
|
||||||
|
import ch.njol.skript.classes.Serializer;
|
||||||
import ch.njol.skript.lang.ParseContext;
|
import ch.njol.skript.lang.ParseContext;
|
||||||
import ch.njol.skript.registrations.Classes;
|
import ch.njol.skript.registrations.Classes;
|
||||||
|
import ch.njol.yggdrasil.Fields;
|
||||||
import net.momirealms.craftengine.core.block.BlockStateParser;
|
import net.momirealms.craftengine.core.block.BlockStateParser;
|
||||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.StreamCorruptedException;
|
||||||
|
|
||||||
public class CraftEngineClasses {
|
public class CraftEngineClasses {
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
Classes.registerClass(new ClassInfo<>(ImmutableBlockState.class, "customblockstate")
|
Classes.registerClass(new ClassInfo<>(ImmutableBlockState.class, "customblockstate")
|
||||||
.user("custom block state")
|
.user("custom block state")
|
||||||
.name("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<>() {
|
.parser(new Parser<>() {
|
||||||
@Override
|
@Override
|
||||||
public String toString(ImmutableBlockState o, int flags) {
|
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
|
@Override
|
||||||
public @Nullable String convert(Object object) {
|
public @Nullable String convert(Object object) {
|
||||||
System.out.println(object.getClass());
|
|
||||||
if (object instanceof ImmutableBlockState immutableBlockState)
|
if (object instanceof ImmutableBlockState immutableBlockState)
|
||||||
return immutableBlockState.owner().value().id().toString();
|
return immutableBlockState.owner().value().id().toString();
|
||||||
if (object instanceof CustomBlock customBlock)
|
if (object instanceof CustomBlock customBlock)
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
|||||||
this.item.setAmount(count);
|
this.item.setAmount(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeComponent(Object type) {
|
||||||
|
FastNMS.INSTANCE.removeComponent(this.getLiteralObject(), ensureDataComponentType(type));
|
||||||
|
}
|
||||||
|
|
||||||
public void resetComponent(Object type) {
|
public void resetComponent(Object type) {
|
||||||
FastNMS.INSTANCE.resetComponent(this.getLiteralObject(), ensureDataComponentType(type));
|
FastNMS.INSTANCE.resetComponent(this.getLiteralObject(), ensureDataComponentType(type));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void removeComponent(ComponentItemWrapper item, Object type) {
|
protected void removeComponent(ComponentItemWrapper item, Object type) {
|
||||||
item.resetComponent(type);
|
item.removeComponent(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.momirealms.craftengine.bukkit.plugin;
|
package net.momirealms.craftengine.bukkit.plugin;
|
||||||
|
|
||||||
import ch.njol.skript.Skript;
|
|
||||||
import net.momirealms.antigrieflib.AntiGriefLib;
|
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||||
import net.momirealms.craftengine.bukkit.advancement.BukkitAdvancementManager;
|
import net.momirealms.craftengine.bukkit.advancement.BukkitAdvancementManager;
|
||||||
import net.momirealms.craftengine.bukkit.api.event.CraftEngineReloadEvent;
|
import net.momirealms.craftengine.bukkit.api.event.CraftEngineReloadEvent;
|
||||||
|
|||||||
@@ -234,6 +234,10 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
|||||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||||
return new ComponentModifier<>(data);
|
return new ComponentModifier<>(data);
|
||||||
}, "components", "component");
|
}, "components", "component");
|
||||||
|
registerDataFunction((obj) -> {
|
||||||
|
List<String> data = MiscUtils.getAsStringList(obj);
|
||||||
|
return new RemoveComponentModifier<>(data);
|
||||||
|
}, "remove-components", "remove-component");
|
||||||
}
|
}
|
||||||
if (VersionHelper.isVersionNewerThan1_21()) {
|
if (VersionHelper.isVersionNewerThan1_21()) {
|
||||||
registerDataFunction((obj) -> {
|
registerDataFunction((obj) -> {
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.momirealms.craftengine.core.item.modifier;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.core.item.Item;
|
||||||
|
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RemoveComponentModifier<I> implements ItemDataModifier<I> {
|
||||||
|
private final List<String> arguments;
|
||||||
|
|
||||||
|
public RemoveComponentModifier(List<String> arguments) {
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> arguments() {
|
||||||
|
return Collections.unmodifiableList(this.arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "remove-components";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Item<I> item, ItemBuildContext context) {
|
||||||
|
for (String argument : arguments) {
|
||||||
|
item.removeComponent(argument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Item<I> item) {
|
||||||
|
// I can't guess
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user