9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 12:56:28 +00:00

修复部分光照问题,完善发包物品

This commit is contained in:
XiaoMoMi
2025-05-29 20:13:26 +08:00
parent 30c1affdc9
commit b459dfec1c
14 changed files with 175 additions and 30 deletions

View File

@@ -33,7 +33,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
public boolean setTag(Object value, Object... path) {
if (value instanceof Tag tag) {
try {
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, !VersionHelper.isOrAbove1_20_3()));
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, true));
return this.rtagItem.set(nmsTag, path);
} catch (IOException e) {
CraftEngine.instance().logger().warn("Failed to set NBT tag " + Arrays.toString(path), e);
@@ -49,7 +49,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
try {
// Incompatible DFU version
// return this.rtagItem.add(Reflections.instance$SPARROW_NBT_OPS.convertTo(Reflections.instance$NBT_OPS, tag), path);
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, !VersionHelper.isOrAbove1_20_3()));
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, true));
return this.rtagItem.add(nmsTag, path);
} catch (IOException e) {
CraftEngine.instance().logger().warn("Failed to add NBT tag " + Arrays.toString(path), e);
@@ -66,6 +66,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
public Tag getNBTTag(Object... path) {
Object tag = getExactTag(path);
if (tag == null) return null;
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(FastNMS.INSTANCE.method$NbtIo$toBytes(tag)))) {
return NBT.readUnnamedTag(dis, !VersionHelper.isOrAbove1_20_3());
} catch (IOException e) {

View File

@@ -5,6 +5,7 @@ import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemBuildContext;
import net.momirealms.craftengine.core.item.NetworkItemHandler;
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.util.AdventureHelper;
@@ -42,8 +43,30 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
if (optionalCustomItem.isEmpty()) {
if (!Config.interceptItem()) return Optional.empty();
return new OtherItem(wrapped).process();
} else {
CustomItem<ItemStack> customItem = optionalCustomItem.get();
if (!customItem.hasClientBoundDataModifier()) {
if (!Config.interceptItem()) return Optional.empty();
return new OtherItem(wrapped).process();
} else {
CompoundTag tag = new CompoundTag();
for (ItemDataModifier<ItemStack> modifier : customItem.clientBoundDataModifiers()) {
modifier.prepareNetworkItem(wrapped, context, tag);
modifier.apply(wrapped, context);
}
if (Config.interceptItem()) {
if (!tag.containsKey("display.Name")) {
processCustomName(wrapped, tag::put);
}
if (!tag.containsKey("display.Lore")) {
processLore(wrapped, tag::put);
}
}
if (tag.isEmpty()) return Optional.empty();
wrapped.setTag(tag, NETWORK_ITEM_TAG);
return Optional.of(wrapped);
}
}
return Optional.empty();
}
public static boolean processCustomName(Item<ItemStack> item, BiConsumer<String, CompoundTag> callback) {

View File

@@ -810,7 +810,7 @@ public class BukkitInjector {
if (!previous.isEmpty()) {
holder.ceChunk().setDirty(true);
if (Config.enableLightSystem()) {
updateLightIfChanged(holder, previous.vanillaBlockState().handle(), newState, y, z, x);
updateLightIfChanged(holder, previousState, newState, newState, x, y, z);
}
}
} else {
@@ -820,7 +820,7 @@ public class BukkitInjector {
holder.ceChunk().setDirty(true);
// 如果新方块的光照属性和客户端认为的不同
if (Config.enableLightSystem() && !immutableBlockState.isEmpty()) {
updateLightIfChanged(holder, immutableBlockState.vanillaBlockState().handle(), newState, y, z, x);
updateLightIfChanged(holder, previousState, immutableBlockState.vanillaBlockState().handle(), newState, x, y, z);
}
}
} catch (Exception e) {
@@ -828,9 +828,17 @@ public class BukkitInjector {
}
}
protected static void updateLightIfChanged(@This InjectedHolder thisObj, Object oldState, Object newState, int y, int z, int x) {
protected static void updateLightIfChanged(@This InjectedHolder thisObj, Object oldServerSideState, Object clientSideState, Object serverSideState, int x, int y, int z) {
CEWorld world = thisObj.ceChunk().world();
if (FastNMS.INSTANCE.method$LightEngine$hasDifferentLightProperties(oldState, newState, world.world().serverWorld(), LocationUtils.toBlockPos(x, y, z))) {
Object blockPos = LocationUtils.toBlockPos(x, y, z);
Object serverWorld = world.world().serverWorld();
if (clientSideState != serverSideState && FastNMS.INSTANCE.method$LightEngine$hasDifferentLightProperties(clientSideState, serverSideState, serverWorld, blockPos)) {
SectionPos sectionPos = thisObj.cePos();
List<SectionPos> pos = SectionPosUtils.calculateAffectedRegions((sectionPos.x() << 4) + x, (sectionPos.y() << 4) + y, (sectionPos.z() << 4) + z, 15);
world.sectionLightUpdated(pos);
return;
}
if (FastNMS.INSTANCE.method$LightEngine$hasDifferentLightProperties(oldServerSideState, serverSideState, serverWorld, blockPos)) {
SectionPos sectionPos = thisObj.cePos();
List<SectionPos> pos = SectionPosUtils.calculateAffectedRegions((sectionPos.x() << 4) + x, (sectionPos.y() << 4) + y, (sectionPos.z() << 4) + z, 15);
world.sectionLightUpdated(pos);

View File

@@ -2554,7 +2554,7 @@ public class Reflections {
public static final Method method$BlockBehaviour$getCollisionShape = requireNonNull(
ReflectionUtils.getDeclaredMethod(
clazz$BlockBehaviour, clazz$VoxelShape, new String[]{"getCollisionShape", "c"}, clazz$BlockState, clazz$BlockGetter, clazz$BlockPos, clazz$CollisionContext
clazz$BlockBehaviour, clazz$VoxelShape, new String[]{"getCollisionShape", VersionHelper.isOrAbove1_20_3() ? "b" : "c"}, clazz$BlockState, clazz$BlockGetter, clazz$BlockPos, clazz$CollisionContext
)
);