mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 11:59:11 +00:00
重置tick逻辑
This commit is contained in:
@@ -40,7 +40,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
private final EmojiParser emojiParser;
|
||||
private OffsetFont offsetFont;
|
||||
|
||||
protected Trie imageTagTrie;
|
||||
protected Trie networkTagTrie;
|
||||
protected Trie emojiKeywordTrie;
|
||||
protected Map<String, ComponentProvider> networkTagMapper;
|
||||
protected Map<String, Emoji> emojiMapper;
|
||||
@@ -67,9 +67,14 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
this.images.clear();
|
||||
this.illegalChars.clear();
|
||||
this.emojis.clear();
|
||||
this.networkTagTrie = null;
|
||||
this.emojiKeywordTrie = null;
|
||||
if (this.networkTagMapper != null) {
|
||||
this.networkTagMapper.clear();
|
||||
}
|
||||
if (this.emojiMapper != null) {
|
||||
this.emojiMapper.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +93,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
this.registerImageTags();
|
||||
this.registerShiftTags();
|
||||
this.registerGlobalTags();
|
||||
this.buildImageTagTrie();
|
||||
this.buildNetworkTagTrie();
|
||||
this.buildEmojiKeywordsTrie();
|
||||
this.emojiList = new ArrayList<>(this.emojis.values());
|
||||
this.allEmojiSuggestions = this.emojis.values().stream()
|
||||
@@ -131,11 +136,11 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
|
||||
@Override
|
||||
public Map<String, ComponentProvider> matchTags(String json) {
|
||||
if (this.imageTagTrie == null) {
|
||||
if (this.networkTagTrie == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, ComponentProvider> tags = new HashMap<>();
|
||||
for (Token token : this.imageTagTrie.tokenize(json)) {
|
||||
for (Token token : this.networkTagTrie.tokenize(json)) {
|
||||
if (token.isMatch()) {
|
||||
tags.put(token.getFragment(), this.networkTagMapper.get(token.getFragment()));
|
||||
}
|
||||
@@ -305,8 +310,8 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
.build();
|
||||
}
|
||||
|
||||
private void buildImageTagTrie() {
|
||||
this.imageTagTrie = Trie.builder()
|
||||
private void buildNetworkTagTrie() {
|
||||
this.networkTagTrie = Trie.builder()
|
||||
.ignoreOverlaps()
|
||||
.addKeywords(this.networkTagMapper.keySet())
|
||||
.build();
|
||||
|
||||
@@ -97,6 +97,7 @@ public class Config {
|
||||
protected Component resource_pack$send$prompt;
|
||||
|
||||
protected boolean light_system$force_update_light;
|
||||
protected boolean light_system$async_update;
|
||||
protected boolean light_system$enable;
|
||||
|
||||
protected int chunk_system$compression_method;
|
||||
@@ -314,6 +315,7 @@ public class Config {
|
||||
|
||||
// light
|
||||
light_system$force_update_light = config.getBoolean("light-system.force-update-light", false);
|
||||
light_system$async_update = config.getBoolean("light-system.async-update", true);
|
||||
light_system$enable = config.getBoolean("light-system.enable", true);
|
||||
|
||||
// chunk
|
||||
@@ -885,6 +887,10 @@ public class Config {
|
||||
return instance.block$chunk_relighter;
|
||||
}
|
||||
|
||||
public static boolean asyncLightUpdate() {
|
||||
return instance.light_system$async_update;
|
||||
}
|
||||
|
||||
public void setObf(boolean enable) {
|
||||
this.resource_pack$protection$obfuscation$enable = enable;
|
||||
}
|
||||
|
||||
@@ -365,6 +365,8 @@ public class AdventureHelper {
|
||||
return text.replaceText(builder ->
|
||||
builder.match(Pattern.compile(patternString))
|
||||
.replacement((result, b) ->
|
||||
replacements.get(result.group()).apply(context)));
|
||||
Optional.ofNullable(replacements.get(result.group())).orElseThrow(() -> new IllegalStateException("Could not find tag '" + result.group() + "'")).apply(context)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
import net.momirealms.craftengine.core.block.entity.tick.TickingBlockEntity;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
|
||||
import net.momirealms.craftengine.core.world.chunk.CEChunk;
|
||||
import net.momirealms.craftengine.core.world.chunk.storage.StorageAdaptor;
|
||||
import net.momirealms.craftengine.core.world.chunk.storage.WorldDataStorage;
|
||||
@@ -25,6 +27,8 @@ public abstract class CEWorld {
|
||||
protected final List<TickingBlockEntity> tickingBlockEntities = new ArrayList<>();
|
||||
protected final List<TickingBlockEntity> pendingTickingBlockEntities = new ArrayList<>();
|
||||
protected boolean isTickingBlockEntities = false;
|
||||
protected SchedulerTask syncTickTask;
|
||||
protected SchedulerTask asyncTickTask;
|
||||
|
||||
private CEChunk lastChunk;
|
||||
private long lastChunkPos;
|
||||
@@ -45,6 +49,24 @@ public abstract class CEWorld {
|
||||
this.lastChunkPos = ChunkPos.INVALID_CHUNK_POS;
|
||||
}
|
||||
|
||||
public void setTicking(boolean ticking) {
|
||||
if (ticking) {
|
||||
if (this.syncTickTask == null || this.syncTickTask.cancelled()) {
|
||||
this.syncTickTask = CraftEngine.instance().scheduler().sync().runRepeating(this::syncTick, 1, 1);
|
||||
}
|
||||
if (this.asyncTickTask == null || this.asyncTickTask.cancelled()) {
|
||||
this.asyncTickTask = CraftEngine.instance().scheduler().sync().runAsyncRepeating(this::asyncTick, 1, 1);
|
||||
}
|
||||
} else {
|
||||
if (this.syncTickTask != null && !this.syncTickTask.cancelled()) {
|
||||
this.syncTickTask.cancel();
|
||||
}
|
||||
if (this.asyncTickTask != null && !this.asyncTickTask.cancelled()) {
|
||||
this.asyncTickTask.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return this.world.name();
|
||||
}
|
||||
@@ -163,10 +185,21 @@ public abstract class CEWorld {
|
||||
return this.worldHeightAccessor;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
public void syncTick() {
|
||||
this.tickBlockEntities();
|
||||
if (!Config.asyncLightUpdate()) {
|
||||
this.updateLight();
|
||||
}
|
||||
}
|
||||
|
||||
public void asyncTick() {
|
||||
if (Config.asyncLightUpdate()) {
|
||||
this.updateLight();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void updateLight();
|
||||
|
||||
protected void tickBlockEntities() {
|
||||
this.isTickingBlockEntities = true;
|
||||
if (!this.pendingTickingBlockEntities.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user