mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
添加方块参数
This commit is contained in:
@@ -11,11 +11,13 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||||
import net.momirealms.craftengine.core.block.EmptyBlock;
|
import net.momirealms.craftengine.core.block.EmptyBlock;
|
||||||
|
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
import net.momirealms.craftengine.core.world.CEWorld;
|
import net.momirealms.craftengine.core.world.CEWorld;
|
||||||
import net.momirealms.craftengine.core.world.ChunkPos;
|
import net.momirealms.craftengine.core.world.ChunkPos;
|
||||||
@@ -24,20 +26,21 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
|
public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
|
||||||
private final Set<CEChunk> needSaveChunks;
|
private final Set<CEChunk> chunksToSave;
|
||||||
private final CEWorld ceWorld;
|
private final CEWorld ceWorld;
|
||||||
|
|
||||||
protected FastAsyncWorldEditDelegate(EditSessionEvent event) {
|
protected FastAsyncWorldEditDelegate(EditSessionEvent event) {
|
||||||
super(event.getExtent());
|
super(event.getExtent());
|
||||||
this.needSaveChunks = new HashSet<>();
|
this.chunksToSave = new HashSet<>();
|
||||||
var weWorld = event.getWorld();
|
World weWorld = event.getWorld();
|
||||||
var world = Bukkit.getWorld(requireNonNull(weWorld).getName());
|
org.bukkit.World world = Bukkit.getWorld(requireNonNull(weWorld).getName());
|
||||||
var ceWorld = CraftEngine.instance().worldManager().getWorld(requireNonNull(world).getUID());
|
CEWorld ceWorld = CraftEngine.instance().worldManager().getWorld(requireNonNull(world).getUID());
|
||||||
this.ceWorld = requireNonNull(ceWorld);
|
this.ceWorld = requireNonNull(ceWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +68,6 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
|
|||||||
return super.setBlocks(region, pattern);
|
return super.setBlocks(region, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
|
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
|
||||||
this.processBlocks(region, block);
|
this.processBlocks(region, block);
|
||||||
@@ -77,6 +79,7 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
|
|||||||
this.processBlocks(region, pattern);
|
this.processBlocks(region, pattern);
|
||||||
return super.replaceBlocks(region, mask, pattern);
|
return super.replaceBlocks(region, mask, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> int replaceBlocks(final Region region, final Set<BaseBlock> filter, final B replacement) {
|
public <B extends BlockStateHolder<B>> int replaceBlocks(final Region region, final Set<BaseBlock> filter, final B replacement) {
|
||||||
this.processBlocks(region, replacement);
|
this.processBlocks(region, replacement);
|
||||||
@@ -136,28 +139,27 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
|
|||||||
private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException {
|
private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException {
|
||||||
int chunkX = blockX >> 4;
|
int chunkX = blockX >> 4;
|
||||||
int chunkZ = blockZ >> 4;
|
int chunkZ = blockZ >> 4;
|
||||||
int stateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(blockState.getAsString()));
|
int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(blockState.getAsString()));
|
||||||
int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString()));
|
// int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString()));
|
||||||
if (BlockStateUtils.isVanillaBlock(stateId) && BlockStateUtils.isVanillaBlock(oldStateId)) return;
|
if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */)
|
||||||
var ceChunk = this.ceWorld.getChunkAtIfLoaded(chunkX, chunkZ);
|
return;
|
||||||
if (ceChunk == null) {
|
CEChunk ceChunk = Optional.ofNullable(this.ceWorld.getChunkAtIfLoaded(chunkX, chunkZ))
|
||||||
ceChunk = this.ceWorld.worldDataStorage().readChunkAt(this.ceWorld, new ChunkPos(chunkX, chunkZ));
|
.orElse(this.ceWorld.worldDataStorage().readChunkAt(this.ceWorld, new ChunkPos(chunkX, chunkZ)));
|
||||||
}
|
ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(newStateId);
|
||||||
var immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId);
|
|
||||||
if (immutableBlockState == null) {
|
if (immutableBlockState == null) {
|
||||||
ceChunk.setBlockState(blockX, blockY, blockZ, EmptyBlock.STATE);
|
ceChunk.setBlockState(blockX, blockY, blockZ, EmptyBlock.STATE);
|
||||||
} else {
|
} else {
|
||||||
ceChunk.setBlockState(blockX, blockY, blockZ, immutableBlockState);
|
ceChunk.setBlockState(blockX, blockY, blockZ, immutableBlockState);
|
||||||
}
|
}
|
||||||
this.needSaveChunks.add(ceChunk);
|
this.chunksToSave.add(ceChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveAllChunks() {
|
private void saveAllChunks() {
|
||||||
try {
|
try {
|
||||||
for (CEChunk ceChunk : this.needSaveChunks) {
|
for (CEChunk ceChunk : this.chunksToSave) {
|
||||||
this.ceWorld.worldDataStorage().writeChunkAt(ceChunk.chunkPos(), ceChunk, true);
|
this.ceWorld.worldDataStorage().writeChunkAt(ceChunk.chunkPos(), ceChunk, true);
|
||||||
}
|
}
|
||||||
this.needSaveChunks.clear();
|
this.chunksToSave.clear();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CraftEngine.instance().logger().warn("Error when recording FastAsyncWorldEdit operation chunks", e);
|
CraftEngine.instance().logger().warn("Error when recording FastAsyncWorldEdit operation chunks", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package net.momirealms.craftengine.bukkit.world;
|
package net.momirealms.craftengine.bukkit.world;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||||
import net.momirealms.craftengine.bukkit.item.behavior.BlockItemBehavior;
|
import net.momirealms.craftengine.bukkit.item.behavior.BlockItemBehavior;
|
||||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||||
|
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||||
@@ -78,7 +80,25 @@ public class BukkitBlockInWorld implements BlockInWorld {
|
|||||||
return this.block.getZ();
|
return this.block.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAsString() {
|
||||||
|
ImmutableBlockState state = CraftEngineBlocks.getCustomBlockState(this.block);
|
||||||
|
if (state != null) {
|
||||||
|
return state.toString();
|
||||||
|
}
|
||||||
|
return this.block.getBlockData().getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Key owner() {
|
||||||
|
ImmutableBlockState state = CraftEngineBlocks.getCustomBlockState(this.block);
|
||||||
|
if (state != null) {
|
||||||
|
return state.owner().value().id();
|
||||||
|
}
|
||||||
|
return KeyUtils.namespacedKey2Key(this.block.getType().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
public Block block() {
|
public Block block() {
|
||||||
return block;
|
return this.block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -454,11 +454,17 @@ public abstract class AbstractFontManager implements FontManager {
|
|||||||
return it.toCharArray();
|
return it.toCharArray();
|
||||||
}
|
}
|
||||||
}).toList();
|
}).toList();
|
||||||
|
if (chars.isEmpty()) {
|
||||||
|
throw new LocalizedResourceConfigException("warning.config.image.missing_char", path, id);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (charsObj instanceof Integer integer) {
|
if (charsObj instanceof Integer integer) {
|
||||||
chars = List.of(new char[]{(char) integer.intValue()});
|
chars = List.of(new char[]{(char) integer.intValue()});
|
||||||
} else {
|
} else {
|
||||||
String character = charsObj.toString();
|
String character = charsObj.toString();
|
||||||
|
if (character.isEmpty()) {
|
||||||
|
throw new LocalizedResourceConfigException("warning.config.image.missing_char", path, id);
|
||||||
|
}
|
||||||
if (character.length() == 1) {
|
if (character.length() == 1) {
|
||||||
chars = List.of(character.toCharArray());
|
chars = List.of(character.toCharArray());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,18 +27,18 @@ public class ResolutionMergeAltas implements Resolution {
|
|||||||
JsonArray ja3 = new JsonArray();
|
JsonArray ja3 = new JsonArray();
|
||||||
HashSet<String> elements = new HashSet<>();
|
HashSet<String> elements = new HashSet<>();
|
||||||
for (JsonElement je : ja1) {
|
for (JsonElement je : ja1) {
|
||||||
if (elements.add(je.getAsString())) {
|
if (elements.add(je.toString())) {
|
||||||
ja3.add(je);
|
ja3.add(je);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (JsonElement je : ja2) {
|
for (JsonElement je : ja2) {
|
||||||
if (elements.add(je.getAsString())) {
|
if (elements.add(je.toString())) {
|
||||||
ja3.add(je);
|
ja3.add(je);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j3.add("sources", ja3);
|
j3.add("sources", ja3);
|
||||||
GsonHelper.writeJsonFile(j3, existing.path());
|
GsonHelper.writeJsonFile(j3, existing.path());
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
CraftEngine.instance().logger().severe("Failed to merge json when resolving file conflicts", e);
|
CraftEngine.instance().logger().severe("Failed to merge json when resolving file conflicts", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.regex.Pattern;
|
|||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class CharacterUtils {
|
public class CharacterUtils {
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("[\\p{Mn}\\p{Me}\\p{Mc}\\p{Cf}]");
|
||||||
|
|
||||||
private CharacterUtils() {}
|
private CharacterUtils() {}
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ public class CharacterUtils {
|
|||||||
type == Character.CONTROL ||
|
type == Character.CONTROL ||
|
||||||
type == Character.SURROGATE ||
|
type == Character.SURROGATE ||
|
||||||
type == Character.PRIVATE_USE ||
|
type == Character.PRIVATE_USE ||
|
||||||
Pattern.compile("[\\p{Mn}\\p{Me}\\p{Mc}\\p{Cf}]").matcher(new String(Character.toChars(codePoint))).find()
|
PATTERN.matcher(new String(Character.toChars(codePoint))).find()
|
||||||
) return true;
|
) return true;
|
||||||
if (i < input.length()) {
|
if (i < input.length()) {
|
||||||
int nextCodePoint = input.codePointAt(i);
|
int nextCodePoint = input.codePointAt(i);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.momirealms.craftengine.core.util.context.parameter;
|
package net.momirealms.craftengine.core.util.context.parameter;
|
||||||
|
|
||||||
import net.momirealms.craftengine.core.util.MCUtils;
|
|
||||||
import net.momirealms.craftengine.core.util.context.ContextKey;
|
import net.momirealms.craftengine.core.util.context.ContextKey;
|
||||||
import net.momirealms.craftengine.core.util.context.LazyContextParameterProvider;
|
import net.momirealms.craftengine.core.util.context.LazyContextParameterProvider;
|
||||||
import net.momirealms.craftengine.core.world.BlockInWorld;
|
import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||||
@@ -15,9 +14,14 @@ import java.util.function.Function;
|
|||||||
public class BlockParameterProvider implements LazyContextParameterProvider {
|
public class BlockParameterProvider implements LazyContextParameterProvider {
|
||||||
private static final Map<ContextKey<?>, Function<BlockInWorld, Object>> CONTEXT_FUNCTIONS = new HashMap<>();
|
private static final Map<ContextKey<?>, Function<BlockInWorld, Object>> CONTEXT_FUNCTIONS = new HashMap<>();
|
||||||
static {
|
static {
|
||||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_X, b -> MCUtils.fastFloor(b.x()));
|
CONTEXT_FUNCTIONS.put(BlockParameters.X, BlockInWorld::x);
|
||||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Y, b -> MCUtils.fastFloor(b.y()));
|
CONTEXT_FUNCTIONS.put(BlockParameters.Y, BlockInWorld::y);
|
||||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Z, b -> MCUtils.fastFloor(b.z()));
|
CONTEXT_FUNCTIONS.put(BlockParameters.Z, BlockInWorld::z);
|
||||||
|
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_X, BlockInWorld::x);
|
||||||
|
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Y, BlockInWorld::y);
|
||||||
|
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Z, BlockInWorld::z);
|
||||||
|
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_OWNER, BlockInWorld::owner);
|
||||||
|
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_STATE, BlockInWorld::getAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BlockInWorld block;
|
private final BlockInWorld block;
|
||||||
|
|||||||
@@ -17,5 +17,4 @@ public final class BlockParameters {
|
|||||||
public static final ContextKey<Integer> BLOCK_Z = new ContextKey<>(Key.of("craftengine:block.block_z"));
|
public static final ContextKey<Integer> BLOCK_Z = new ContextKey<>(Key.of("craftengine:block.block_z"));
|
||||||
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block.state"));
|
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block.state"));
|
||||||
public static final ContextKey<Key> BLOCK_OWNER = new ContextKey<>(Key.of("craftengine:block.owner"));
|
public static final ContextKey<Key> BLOCK_OWNER = new ContextKey<>(Key.of("craftengine:block.owner"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.momirealms.craftengine.core.world;
|
package net.momirealms.craftengine.core.world;
|
||||||
|
|
||||||
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
|
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
|
||||||
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
|
||||||
public interface BlockInWorld {
|
public interface BlockInWorld {
|
||||||
|
|
||||||
@@ -12,6 +13,10 @@ public interface BlockInWorld {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Key owner();
|
||||||
|
|
||||||
|
String getAsString();
|
||||||
|
|
||||||
int x();
|
int x();
|
||||||
|
|
||||||
int y();
|
int y();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=0.0.53-beta.1
|
project_version=0.0.53-beta.2
|
||||||
config_version=31
|
config_version=31
|
||||||
lang_version=10
|
lang_version=10
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
|
|||||||
ahocorasick_version=0.6.3
|
ahocorasick_version=0.6.3
|
||||||
snake_yaml_version=2.4
|
snake_yaml_version=2.4
|
||||||
anti_grief_version=0.15
|
anti_grief_version=0.15
|
||||||
nms_helper_version=0.64.3
|
nms_helper_version=0.64.4
|
||||||
reactive_streams_version=1.0.4
|
reactive_streams_version=1.0.4
|
||||||
amazon_awssdk_version=2.31.23
|
amazon_awssdk_version=2.31.23
|
||||||
amazon_awssdk_eventstream_version=1.0.1
|
amazon_awssdk_eventstream_version=1.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user