9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-29 03:49:15 +00:00

添加方块参数

This commit is contained in:
XiaoMoMi
2025-05-03 14:42:22 +08:00
parent ad0a1b8380
commit 2b7b218bd3
9 changed files with 66 additions and 29 deletions

View File

@@ -11,11 +11,13 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
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.BlockStateHolder;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
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.world.CEWorld;
import net.momirealms.craftengine.core.world.ChunkPos;
@@ -24,20 +26,21 @@ import org.bukkit.Bukkit;
import java.io.IOException;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import static java.util.Objects.requireNonNull;
public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
private final Set<CEChunk> needSaveChunks;
private final Set<CEChunk> chunksToSave;
private final CEWorld ceWorld;
protected FastAsyncWorldEditDelegate(EditSessionEvent event) {
super(event.getExtent());
this.needSaveChunks = new HashSet<>();
var weWorld = event.getWorld();
var world = Bukkit.getWorld(requireNonNull(weWorld).getName());
var ceWorld = CraftEngine.instance().worldManager().getWorld(requireNonNull(world).getUID());
this.chunksToSave = new HashSet<>();
World weWorld = event.getWorld();
org.bukkit.World world = Bukkit.getWorld(requireNonNull(weWorld).getName());
CEWorld ceWorld = CraftEngine.instance().worldManager().getWorld(requireNonNull(world).getUID());
this.ceWorld = requireNonNull(ceWorld);
}
@@ -65,7 +68,6 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
return super.setBlocks(region, pattern);
}
@Override
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
this.processBlocks(region, block);
@@ -77,6 +79,7 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
this.processBlocks(region, pattern);
return super.replaceBlocks(region, mask, pattern);
}
@Override
public <B extends BlockStateHolder<B>> int replaceBlocks(final Region region, final Set<BaseBlock> filter, final B 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 {
int chunkX = blockX >> 4;
int chunkZ = blockZ >> 4;
int stateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(blockState.getAsString()));
int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString()));
if (BlockStateUtils.isVanillaBlock(stateId) && BlockStateUtils.isVanillaBlock(oldStateId)) return;
var ceChunk = this.ceWorld.getChunkAtIfLoaded(chunkX, chunkZ);
if (ceChunk == null) {
ceChunk = this.ceWorld.worldDataStorage().readChunkAt(this.ceWorld, new ChunkPos(chunkX, chunkZ));
}
var immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId);
int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(blockState.getAsString()));
// int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString()));
if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */)
return;
CEChunk ceChunk = Optional.ofNullable(this.ceWorld.getChunkAtIfLoaded(chunkX, chunkZ))
.orElse(this.ceWorld.worldDataStorage().readChunkAt(this.ceWorld, new ChunkPos(chunkX, chunkZ)));
ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(newStateId);
if (immutableBlockState == null) {
ceChunk.setBlockState(blockX, blockY, blockZ, EmptyBlock.STATE);
} else {
ceChunk.setBlockState(blockX, blockY, blockZ, immutableBlockState);
}
this.needSaveChunks.add(ceChunk);
this.chunksToSave.add(ceChunk);
}
private void saveAllChunks() {
try {
for (CEChunk ceChunk : this.needSaveChunks) {
for (CEChunk ceChunk : this.chunksToSave) {
this.ceWorld.worldDataStorage().writeChunkAt(ceChunk.chunkPos(), ceChunk, true);
}
this.needSaveChunks.clear();
this.chunksToSave.clear();
} catch (Exception e) {
CraftEngine.instance().logger().warn("Error when recording FastAsyncWorldEdit operation chunks", e);
}

View File

@@ -1,10 +1,12 @@
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.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.item.behavior.BlockItemBehavior;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
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.Reflections;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
@@ -78,7 +80,25 @@ public class BukkitBlockInWorld implements BlockInWorld {
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() {
return block;
return this.block;
}
}

View File

@@ -454,11 +454,17 @@ public abstract class AbstractFontManager implements FontManager {
return it.toCharArray();
}
}).toList();
if (chars.isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char", path, id);
}
} else {
if (charsObj instanceof Integer integer) {
chars = List.of(new char[]{(char) integer.intValue()});
} else {
String character = charsObj.toString();
if (character.isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char", path, id);
}
if (character.length() == 1) {
chars = List.of(character.toCharArray());
} else {

View File

@@ -27,18 +27,18 @@ public class ResolutionMergeAltas implements Resolution {
JsonArray ja3 = new JsonArray();
HashSet<String> elements = new HashSet<>();
for (JsonElement je : ja1) {
if (elements.add(je.getAsString())) {
if (elements.add(je.toString())) {
ja3.add(je);
}
}
for (JsonElement je : ja2) {
if (elements.add(je.getAsString())) {
if (elements.add(je.toString())) {
ja3.add(je);
}
}
j3.add("sources", ja3);
GsonHelper.writeJsonFile(j3, existing.path());
} catch (IOException e) {
} catch (Exception e) {
CraftEngine.instance().logger().severe("Failed to merge json when resolving file conflicts", e);
}
}

View File

@@ -6,6 +6,7 @@ import java.util.regex.Pattern;
import java.util.stream.IntStream;
public class CharacterUtils {
private static final Pattern PATTERN = Pattern.compile("[\\p{Mn}\\p{Me}\\p{Mc}\\p{Cf}]");
private CharacterUtils() {}
@@ -87,7 +88,7 @@ public class CharacterUtils {
type == Character.CONTROL ||
type == Character.SURROGATE ||
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;
if (i < input.length()) {
int nextCodePoint = input.codePointAt(i);

View File

@@ -1,6 +1,5 @@
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.LazyContextParameterProvider;
import net.momirealms.craftengine.core.world.BlockInWorld;
@@ -15,9 +14,14 @@ import java.util.function.Function;
public class BlockParameterProvider implements LazyContextParameterProvider {
private static final Map<ContextKey<?>, Function<BlockInWorld, Object>> CONTEXT_FUNCTIONS = new HashMap<>();
static {
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_X, b -> MCUtils.fastFloor(b.x()));
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Y, b -> MCUtils.fastFloor(b.y()));
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Z, b -> MCUtils.fastFloor(b.z()));
CONTEXT_FUNCTIONS.put(BlockParameters.X, BlockInWorld::x);
CONTEXT_FUNCTIONS.put(BlockParameters.Y, BlockInWorld::y);
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;

View File

@@ -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<ImmutableBlockState> BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block.state"));
public static final ContextKey<Key> BLOCK_OWNER = new ContextKey<>(Key.of("craftengine:block.owner"));
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.util.Key;
public interface BlockInWorld {
@@ -12,6 +13,10 @@ public interface BlockInWorld {
return false;
}
Key owner();
String getAsString();
int x();
int y();

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.53-beta.1
project_version=0.0.53-beta.2
config_version=31
lang_version=10
project_group=net.momirealms
@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.15
nms_helper_version=0.64.3
nms_helper_version=0.64.4
reactive_streams_version=1.0.4
amazon_awssdk_version=2.31.23
amazon_awssdk_eventstream_version=1.0.1