mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 04:46:37 +00:00
简化部分代码实现
This commit is contained in:
@@ -19,10 +19,13 @@ import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.core.block.BlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.block.EmptyBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.UpdateOption;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
import net.momirealms.craftengine.core.util.SectionPosUtils;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
import net.momirealms.craftengine.core.world.SectionPos;
|
||||
import net.momirealms.craftengine.core.world.chunk.CEChunk;
|
||||
@@ -224,7 +227,20 @@ public final class WorldStorageInjector {
|
||||
ImmutableBlockState previous = section.setBlockState(x, y, z, EmptyBlock.STATE);
|
||||
// 处理 自定义块 -> 原版块
|
||||
if (!previous.isEmpty()) {
|
||||
holder.ceChunk().setDirty(true);
|
||||
CEChunk chunk = holder.ceChunk();
|
||||
chunk.setDirty(true);
|
||||
if (previous.hasBlockEntity()) {
|
||||
BlockPos pos = new BlockPos(
|
||||
chunk.chunkPos().x * 16 + x,
|
||||
section.sectionY() * 16 + y,
|
||||
chunk.chunkPos().z * 16 + z
|
||||
);
|
||||
BlockEntity blockEntity = chunk.getBlockEntity(pos);
|
||||
if (blockEntity != null) {
|
||||
blockEntity.preRemove();
|
||||
chunk.removeBlockEntity(pos);
|
||||
}
|
||||
}
|
||||
if (Config.enableLightSystem()) {
|
||||
// 自定义块到原版块,只需要判断旧块是否和客户端一直
|
||||
BlockStateWrapper wrapper = previous.vanillaBlockState();
|
||||
@@ -258,8 +274,8 @@ public final class WorldStorageInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
protected static void updateLight(@This InjectedHolder thisObj, Object clientState, Object serverState, int x, int y, int z) {
|
||||
CEWorld world = thisObj.ceChunk().world();
|
||||
private static void updateLight(@This InjectedHolder thisObj, Object clientState, Object serverState, int x, int y, int z) {
|
||||
CEWorld world = thisObj.ceChunk().world;
|
||||
Object blockPos = LocationUtils.toBlockPos(x, y, z);
|
||||
Object serverWorld = world.world().serverWorld();
|
||||
if (FastNMS.INSTANCE.method$LightEngine$hasDifferentLightProperties(serverState, clientState, serverWorld, blockPos)) {
|
||||
@@ -270,8 +286,8 @@ public final class WorldStorageInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
protected static void updateLight$complex(@This InjectedHolder thisObj, Object newClientState, Object newServerState, Object oldServerState, int x, int y, int z) {
|
||||
CEWorld world = thisObj.ceChunk().world();
|
||||
private static void updateLight$complex(@This InjectedHolder thisObj, Object newClientState, Object newServerState, Object oldServerState, int x, int y, int z) {
|
||||
CEWorld world = thisObj.ceChunk().world;
|
||||
Object blockPos = LocationUtils.toBlockPos(x, y, z);
|
||||
Object serverWorld = world.world().serverWorld();
|
||||
// 如果客户端新状态和服务端新状态光照属性不同
|
||||
|
||||
@@ -23,7 +23,7 @@ public final class LightUtils {
|
||||
if (chunkHolder == null) continue;
|
||||
List<Object> players = FastNMS.INSTANCE.method$ChunkHolder$getPlayers(chunkHolder);
|
||||
if (players.isEmpty()) continue;
|
||||
Object lightEngine = CoreReflections.field$ChunkHolder$lightEngine.get(chunkHolder);
|
||||
Object lightEngine = FastNMS.INSTANCE.method$ChunkSource$getLightEngine(chunkSource);
|
||||
Object chunkPos = FastNMS.INSTANCE.constructor$ChunkPos((int) chunkKey, (int) (chunkKey >> 32));
|
||||
Object lightPacket = FastNMS.INSTANCE.constructor$ClientboundLightUpdatePacket(chunkPos, lightEngine, entry.getValue(), entry.getValue());
|
||||
for (Object player : players) {
|
||||
|
||||
@@ -9,7 +9,8 @@ import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.chunk.storage.StorageAdaptor;
|
||||
import net.momirealms.craftengine.core.world.chunk.storage.WorldDataStorage;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCEWorld extends CEWorld {
|
||||
|
||||
@@ -23,17 +24,17 @@ public class BukkitCEWorld extends CEWorld {
|
||||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
HashSet<SectionPos> poses;
|
||||
List<SectionPos> poses;
|
||||
synchronized (super.updatedSectionSet) {
|
||||
poses = new HashSet<>(super.updatedSectionSet);
|
||||
poses = new ArrayList<>(super.updatedSectionSet);
|
||||
super.updatedSectionSet.clear();
|
||||
}
|
||||
if (Config.enableLightSystem()) {
|
||||
LightUtils.updateChunkLight(
|
||||
(org.bukkit.World) world.platformWorld(),
|
||||
(org.bukkit.World) this.world.platformWorld(),
|
||||
SectionPosUtils.toMap(poses,
|
||||
world.worldHeight().getMinSection() - 1,
|
||||
world.worldHeight().getMaxSection() + 1
|
||||
this.world.worldHeight().getMinSection() - 1,
|
||||
this.world.worldHeight().getMaxSection() + 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user