diff --git a/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightAdapter.java index e03c20e07c..d6b518d93d 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightAdapter.java @@ -104,7 +104,6 @@ import net.minecraft.server.level.ChunkResult; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; import net.minecraft.util.StringRepresentable; import net.minecraft.util.Util; @@ -288,8 +287,11 @@ public DataFixer getDataFixer() { * @param tag the tag */ static void readTagIntoTileEntity(net.minecraft.nbt.CompoundTag tag, BlockEntity tileEntity) { - tileEntity.loadWithComponents(TagValueInput.create(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess(), tag)); - tileEntity.setChanged(); + PaperweightLoggingProblemReporter.with(() -> "loading tile entity at " + tileEntity.getBlockPos(), reporter -> { + tileEntity.loadWithComponents(TagValueInput.create(reporter, MinecraftServer.getServer().registryAccess(), tag)); + tileEntity.setChanged(); + return null; + }); } /** @@ -392,9 +394,14 @@ public BaseBlock getFullBlock(Location location) { // Read the NBT data BlockEntity te = chunk.getBlockEntity(blockPos); if (te != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess()); - te.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, MinecraftServer.getServer().registryAccess()); + te.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } @@ -493,13 +500,22 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) { String id = getEntityId(mcEntity); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, mcEntity.registryAccess()); - if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + mcEntity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, mcEntity.registryAccess()); + if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + return null; + } + return tagValueOutput.buildResult(); + } + ); + if (tag == null) { return null; } return new BaseEntity( - EntityTypes.get(id), - LazyReference.from(() -> (LinCompoundTag) toNative(tagValueOutput.buildResult())) + EntityTypes.get(id), + LazyReference.from(() -> (LinCompoundTag) toNative(tag)) ); } @@ -848,9 +864,14 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld Objects.requireNonNull(state); BlockEntity blockEntity = chunk.getBlockEntity(pos); if (blockEntity != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverWorld.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverWorld.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); state = state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } extent.setBlock(vec, state.toBaseBlock()); diff --git a/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightLoggingProblemReporter.java b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightLoggingProblemReporter.java new file mode 100644 index 0000000000..8af191512b --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21_11; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +final class PaperweightLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new PaperweightLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + PaperweightLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightServerLevelDelegateProxy.java b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightServerLevelDelegateProxy.java index 845d79e711..53ddbbbc26 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightServerLevelDelegateProxy.java +++ b/worldedit-bukkit/adapters/adapter-1.21.11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_11/PaperweightServerLevelDelegateProxy.java @@ -34,7 +34,6 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.Blocks; @@ -155,9 +154,14 @@ private boolean addEntity(Entity entity) { Identifier id = serverLevel.registryAccess().lookupOrThrow(Registries.ENTITY_TYPE).getKey(entity.getType()); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - entity.saveWithoutId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + entity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + entity.saveWithoutId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); BaseEntity baseEntity = new BaseEntity(EntityTypes.get(id.toString()), LazyReference.from(() -> (LinCompoundTag) adapter.toNative(tag))); @@ -170,9 +174,14 @@ public void close() throws MaxChangedBlocksException { BlockVector3 blockPos = entry.getKey(); BlockEntity blockEntity = entry.getValue(); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "saving block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); editSession.setBlock( blockPos, adapter.adapt(blockEntity.getBlockState()) diff --git a/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightAdapter.java index cb1707e82a..78345b9e07 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightAdapter.java @@ -106,7 +106,6 @@ import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.progress.ChunkProgressListener; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; import net.minecraft.util.StringRepresentable; import net.minecraft.util.thread.BlockableEventLoop; @@ -289,8 +288,11 @@ public DataFixer getDataFixer() { * @param tag the tag */ static void readTagIntoTileEntity(net.minecraft.nbt.CompoundTag tag, BlockEntity tileEntity) { - tileEntity.loadWithComponents(TagValueInput.create(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess(), tag)); - tileEntity.setChanged(); + PaperweightLoggingProblemReporter.with(() -> "loading tile entity at " + tileEntity.getBlockPos(), reporter -> { + tileEntity.loadWithComponents(TagValueInput.create(reporter, MinecraftServer.getServer().registryAccess(), tag)); + tileEntity.setChanged(); + return null; + }); } /** @@ -393,9 +395,14 @@ public BaseBlock getFullBlock(Location location) { // Read the NBT data BlockEntity te = chunk.getBlockEntity(blockPos); if (te != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess()); - te.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, MinecraftServer.getServer().registryAccess()); + te.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } @@ -494,13 +501,22 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) { String id = getEntityId(mcEntity); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, mcEntity.registryAccess()); - if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + mcEntity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, mcEntity.registryAccess()); + if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + return null; + } + return tagValueOutput.buildResult(); + } + ); + if (tag == null) { return null; } return new BaseEntity( EntityTypes.get(id), - LazyReference.from(() -> (LinCompoundTag) toNative(tagValueOutput.buildResult())) + LazyReference.from(() -> (LinCompoundTag) toNative(tag)) ); } @@ -850,9 +866,14 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld Objects.requireNonNull(state); BlockEntity blockEntity = chunk.getBlockEntity(pos); if (blockEntity != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverWorld.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverWorld.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); state = state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } extent.setBlock(vec, state.toBaseBlock()); diff --git a/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightLoggingProblemReporter.java b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightLoggingProblemReporter.java new file mode 100644 index 0000000000..3129866720 --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21_6; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +final class PaperweightLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new PaperweightLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + PaperweightLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightServerLevelDelegateProxy.java b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightServerLevelDelegateProxy.java index 290d714e17..0ea6e6321a 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightServerLevelDelegateProxy.java +++ b/worldedit-bukkit/adapters/adapter-1.21.6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_6/PaperweightServerLevelDelegateProxy.java @@ -34,7 +34,6 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.Blocks; @@ -155,9 +154,14 @@ private boolean addEntity(Entity entity) { ResourceLocation id = serverLevel.registryAccess().lookupOrThrow(Registries.ENTITY_TYPE).getKey(entity.getType()); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - entity.saveWithoutId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + entity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + entity.saveWithoutId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); BaseEntity baseEntity = new BaseEntity(EntityTypes.get(id.toString()), LazyReference.from(() -> (LinCompoundTag) adapter.toNative(tag))); @@ -170,9 +174,14 @@ public void close() throws MaxChangedBlocksException { BlockVector3 blockPos = entry.getKey(); BlockEntity blockEntity = entry.getValue(); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "saving block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); editSession.setBlock( blockPos, adapter.adapt(blockEntity.getBlockState()) diff --git a/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightAdapter.java index 441802391e..a8745f4504 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightAdapter.java @@ -105,7 +105,6 @@ import net.minecraft.server.level.ChunkResult; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; import net.minecraft.util.StringRepresentable; import net.minecraft.util.thread.BlockableEventLoop; @@ -288,8 +287,11 @@ public DataFixer getDataFixer() { * @param tag the tag */ static void readTagIntoTileEntity(net.minecraft.nbt.CompoundTag tag, BlockEntity tileEntity) { - tileEntity.loadWithComponents(TagValueInput.create(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess(), tag)); - tileEntity.setChanged(); + PaperweightLoggingProblemReporter.with(() -> "loading tile entity at " + tileEntity.getBlockPos(), reporter -> { + tileEntity.loadWithComponents(TagValueInput.create(reporter, MinecraftServer.getServer().registryAccess(), tag)); + tileEntity.setChanged(); + return null; + }); } /** @@ -392,9 +394,14 @@ public BaseBlock getFullBlock(Location location) { // Read the NBT data BlockEntity te = chunk.getBlockEntity(blockPos); if (te != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, MinecraftServer.getServer().registryAccess()); - te.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, MinecraftServer.getServer().registryAccess()); + te.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } @@ -493,13 +500,22 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) { String id = getEntityId(mcEntity); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, mcEntity.registryAccess()); - if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + mcEntity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, mcEntity.registryAccess()); + if (!readEntityIntoTag(mcEntity, tagValueOutput)) { + return null; + } + return tagValueOutput.buildResult(); + } + ); + if (tag == null) { return null; } return new BaseEntity( EntityTypes.get(id), - LazyReference.from(() -> (LinCompoundTag) toNative(tagValueOutput.buildResult())) + LazyReference.from(() -> (LinCompoundTag) toNative(tag)) ); } @@ -848,9 +864,14 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld Objects.requireNonNull(state); BlockEntity blockEntity = chunk.getBlockEntity(pos); if (blockEntity != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverWorld.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverWorld.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); state = state.toBaseBlock(LazyReference.from(() -> (LinCompoundTag) toNative(tag))); } extent.setBlock(vec, state.toBaseBlock()); diff --git a/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightLoggingProblemReporter.java b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightLoggingProblemReporter.java new file mode 100644 index 0000000000..6978e8c773 --- /dev/null +++ b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.bukkit.adapter.impl.v1_21_9; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +final class PaperweightLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new PaperweightLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + PaperweightLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightServerLevelDelegateProxy.java b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightServerLevelDelegateProxy.java index d4447595dd..ab54720450 100644 --- a/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightServerLevelDelegateProxy.java +++ b/worldedit-bukkit/adapters/adapter-1.21.9/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_9/PaperweightServerLevelDelegateProxy.java @@ -34,7 +34,6 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.Blocks; @@ -155,9 +154,14 @@ private boolean addEntity(Entity entity) { ResourceLocation id = serverLevel.registryAccess().lookupOrThrow(Registries.ENTITY_TYPE).getKey(entity.getType()); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - entity.saveWithoutId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "serializing entity " + entity.getStringUUID(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + entity.saveWithoutId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); BaseEntity baseEntity = new BaseEntity(EntityTypes.get(id.toString()), LazyReference.from(() -> (LinCompoundTag) adapter.toNative(tag))); @@ -170,9 +174,14 @@ public void close() throws MaxChangedBlocksException { BlockVector3 blockPos = entry.getKey(); BlockEntity blockEntity = entry.getValue(); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = PaperweightLoggingProblemReporter.with( + () -> "saving block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); editSession.setBlock( blockPos, adapter.adapt(blockEntity.getBlockState()) diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricAdapter.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricAdapter.java index 2f833143ad..34c3337634 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricAdapter.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricAdapter.java @@ -48,7 +48,6 @@ import net.minecraft.nbt.NbtOps; import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -211,9 +210,14 @@ public static BaseBlock adapt(BlockEntity blockEntity, RegistryAccess registries worldEdit = FabricTransmogrifier.transmogToWorldEdit(blockEntity.getBlockState()); } // Save this outside the reference to ensure it doesn't mutate - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, registries); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag savedNative = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag savedNative = com.sk89q.worldedit.fabric.internal.FabricLoggingProblemReporter.with( + () -> "serializing block entity " + blockEntity.getClass().getSimpleName(), + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, registries); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return worldEdit.toBaseBlock(LazyReference.from(() -> NBTConverter.fromNative(savedNative))); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java index c4d3c51173..f883509247 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java @@ -38,6 +38,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.fabric.internal.ExtendedMinecraftServer; import com.sk89q.worldedit.fabric.internal.FabricEntity; +import com.sk89q.worldedit.fabric.internal.FabricLoggingProblemReporter; import com.sk89q.worldedit.fabric.internal.FabricServerLevelDelegateProxy; import com.sk89q.worldedit.fabric.internal.FabricWorldNativeAccess; import com.sk89q.worldedit.fabric.internal.NBTConverter; @@ -80,7 +81,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; import net.minecraft.util.Util; import net.minecraft.world.Clearable; @@ -417,9 +417,14 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld BlockStateHolder state = FabricAdapter.adapt(chunk.getBlockState(pos)); BlockEntity blockEntity = chunk.getBlockEntity(pos); if (blockEntity != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, getWorld().registryAccess()); - blockEntity.saveWithId(tagValueOutput); - CompoundTag tag = tagValueOutput.buildResult(); + CompoundTag tag = FabricLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, getWorld().registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); state = state.toBaseBlock(LazyReference.from(() -> NBTConverter.fromNative(tag))); } extent.setBlock(vec, state.toBaseBlock()); @@ -679,9 +684,14 @@ public BaseBlock getFullBlock(BlockVector3 position) { BlockEntity tile = ((LevelChunk) getWorld().getChunk(pos)).getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK); if (tile != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, getWorld().registryAccess()); - tile.saveWithId(tagValueOutput); - CompoundTag tag = tagValueOutput.buildResult(); + CompoundTag tag = FabricLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, getWorld().registryAccess()); + tile.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return getBlock(position).toBaseBlock(LazyReference.from(() -> NBTConverter.fromNative(tag))); } else { return getBlock(position).toBaseBlock(); diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java index 2c7bd8d507..e02facd896 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java @@ -33,7 +33,6 @@ import com.sk89q.worldedit.world.entity.EntityTypes; import net.minecraft.core.registries.Registries; import net.minecraft.resources.Identifier; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.storage.TagValueOutput; import java.lang.ref.WeakReference; @@ -57,14 +56,21 @@ public BaseEntity getState() { return null; } - var tagValueOutput = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING); + net.minecraft.nbt.CompoundTag tag = FabricLoggingProblemReporter.with( + () -> "serializing entity " + entity.getStringUUID(), + reporter -> { + TagValueOutput tagValueOutput = TagValueOutput.createWithContext(reporter, entity.registryAccess()); + if (!entity.save(tagValueOutput)) { + return null; + } + return tagValueOutput.buildResult(); + } + ); - if (!entity.save(tagValueOutput)) { + if (tag == null) { return null; } - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); - Identifier id = FabricWorldEdit.getRegistry(Registries.ENTITY_TYPE).getKey(entity.getType()); return new BaseEntity( EntityTypes.get(id.toString()), diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricLoggingProblemReporter.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricLoggingProblemReporter.java new file mode 100644 index 0000000000..7f5afe5a7e --- /dev/null +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.fabric.internal; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +public final class FabricLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + public static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new FabricLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + FabricLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricWorldNativeAccess.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricWorldNativeAccess.java index 847930a8d8..881c6b954c 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricWorldNativeAccess.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricWorldNativeAccess.java @@ -28,7 +28,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.ServerChunkCache; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -113,10 +112,15 @@ public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) { if (tileEntity == null) { return false; } - var tagValueInput = TagValueInput.create(ProblemReporter.DISCARDING, level.registryAccess(), nativeTag); - tileEntity.loadWithComponents(tagValueInput); - tileEntity.setChanged(); - return true; + return FabricLoggingProblemReporter.with( + () -> "loading tile entity at " + position, + reporter -> { + var tagValueInput = TagValueInput.create(reporter, level.registryAccess(), nativeTag); + tileEntity.loadWithComponents(tagValueInput); + tileEntity.setChanged(); + return true; + } + ); } @Override diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java index c527e84cad..b0ae791551 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java @@ -44,6 +44,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.neoforge.internal.NBTConverter; import com.sk89q.worldedit.neoforge.internal.NeoForgeEntity; +import com.sk89q.worldedit.neoforge.internal.NeoForgeLoggingProblemReporter; import com.sk89q.worldedit.neoforge.internal.NeoForgeServerLevelDelegateProxy; import com.sk89q.worldedit.neoforge.internal.NeoForgeWorldNativeAccess; import com.sk89q.worldedit.regions.Region; @@ -75,7 +76,6 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; import net.minecraft.util.Util; import net.minecraft.util.thread.BlockableEventLoop; @@ -396,9 +396,14 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld BlockStateHolder state = NeoForgeAdapter.adapt(chunk.getBlockState(pos)); BlockEntity blockEntity = chunk.getBlockEntity(pos); if (blockEntity != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, getWorld().registryAccess()); - blockEntity.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = NeoForgeLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, getWorld().registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); state = state.toBaseBlock(LazyReference.from(() -> NBTConverter.fromNative(tag))); } extent.setBlock(vec, state.toBaseBlock()); @@ -658,9 +663,14 @@ public BaseBlock getFullBlock(BlockVector3 position) { BlockEntity tile = getWorld().getChunk(pos).getBlockEntity(pos); if (tile != null) { - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, getWorld().registryAccess()); - tile.saveWithId(tagValueOutput); - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = NeoForgeLoggingProblemReporter.with( + () -> "serializing block entity at " + pos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, getWorld().registryAccess()); + tile.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); return getBlock(position).toBaseBlock( LazyReference.from(() -> NBTConverter.fromNative(tag)) ); diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeEntity.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeEntity.java index 7d46479f5b..7f0ac7470f 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeEntity.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeEntity.java @@ -33,7 +33,6 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.storage.TagValueOutput; import java.lang.ref.WeakReference; @@ -57,14 +56,21 @@ public BaseEntity getState() { return null; } - var tagValueOutput = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING); + net.minecraft.nbt.CompoundTag tag = NeoForgeLoggingProblemReporter.with( + () -> "serializing entity " + entity.getStringUUID(), + reporter -> { + TagValueOutput tagValueOutput = TagValueOutput.createWithContext(reporter, entity.registryAccess()); + if (!entity.save(tagValueOutput)) { + return null; + } + return tagValueOutput.buildResult(); + } + ); - if (!entity.save(tagValueOutput)) { + if (tag == null) { return null; } - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); - Identifier id = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); return new BaseEntity( EntityTypes.get(id.toString()), diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeLoggingProblemReporter.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeLoggingProblemReporter.java new file mode 100644 index 0000000000..3d28207ea8 --- /dev/null +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.neoforge.internal; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +public final class NeoForgeLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + public static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new NeoForgeLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + NeoForgeLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeServerLevelDelegateProxy.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeServerLevelDelegateProxy.java index 941224914b..746ba6d121 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeServerLevelDelegateProxy.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeServerLevelDelegateProxy.java @@ -29,7 +29,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.Blocks; @@ -137,10 +136,14 @@ public void close() throws MaxChangedBlocksException { BlockVector3 blockPos = entry.getKey(); BlockEntity blockEntity = entry.getValue(); - var tagValueOutput = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, serverLevel.registryAccess()); - blockEntity.saveWithId(tagValueOutput); - - net.minecraft.nbt.CompoundTag tag = tagValueOutput.buildResult(); + net.minecraft.nbt.CompoundTag tag = NeoForgeLoggingProblemReporter.with( + () -> "saving block entity at " + blockPos, + reporter -> { + var tagValueOutput = TagValueOutput.createWithContext(reporter, serverLevel.registryAccess()); + blockEntity.saveWithId(tagValueOutput); + return tagValueOutput.buildResult(); + } + ); editSession.setBlock( blockPos, NeoForgeAdapter.adapt(blockEntity.getBlockState()) diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java index 596b4413dc..d04dd5887f 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java @@ -27,7 +27,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -113,10 +112,15 @@ public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) { if (tileEntity == null) { return false; } - var tagValueInput = TagValueInput.create(ProblemReporter.DISCARDING, level.registryAccess(), nativeTag); - tileEntity.loadWithComponents(tagValueInput); - tileEntity.setChanged(); - return true; + return NeoForgeLoggingProblemReporter.with( + () -> "loading tile entity at " + position, + reporter -> { + var tagValueInput = TagValueInput.create(reporter, level.registryAccess(), nativeTag); + tileEntity.loadWithComponents(tagValueInput); + tileEntity.setChanged(); + return true; + } + ); } @Override diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 84e2cc9847..5108163dc3 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.sponge.internal.NbtAdapter; +import com.sk89q.worldedit.sponge.internal.SpongeLoggingProblemReporter; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.Component; @@ -42,7 +43,6 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.block.entity.StructureBlockEntity; import net.minecraft.world.level.storage.TagValueInput; import org.enginehub.linbus.tree.LinCompoundTag; @@ -252,7 +252,13 @@ public > void sendFakeBlock(BlockVector3 pos, B bl StructureBlockEntity structureBlockEntity = new StructureBlockEntity(new BlockPos(pos.x(), pos.y(), pos.z()), nativeBlock); - structureBlockEntity.loadWithComponents(TagValueInput.create(ProblemReporter.DISCARDING, nativePlayer.level().registryAccess(), nativeNbtData)); + SpongeLoggingProblemReporter.with( + () -> "loading structure block entity for fake player " + player.uniqueId(), + reporter -> { + structureBlockEntity.loadWithComponents(TagValueInput.create(reporter, nativePlayer.level().registryAccess(), nativeNbtData)); + return null; + } + ); nativePlayer.connection.send( ClientboundBlockEntityDataPacket.create(structureBlockEntity, (be, ra) -> nativeNbtData)); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeLoggingProblemReporter.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeLoggingProblemReporter.java new file mode 100644 index 0000000000..60985c0d84 --- /dev/null +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeLoggingProblemReporter.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.sponge.internal; + +import net.minecraft.util.ProblemReporter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.function.Function; +import java.util.function.Supplier; + +public final class SpongeLoggingProblemReporter implements ProblemReporter, AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + + public static T with(Supplier contextSupplier, Function consumer) { + try (var problemReporter = new SpongeLoggingProblemReporter(contextSupplier)) { + return consumer.apply(problemReporter); + } + } + + SpongeLoggingProblemReporter(Supplier contextSupplier) { + this.contextSupplier = contextSupplier; + } + + private final Collector delegate = new Collector(); + private final Supplier contextSupplier; + + @Override + public ProblemReporter forChild(PathElement child) { + return delegate.forChild(child); + } + + @Override + public void report(Problem problem) { + delegate.report(problem); + } + + @Override + public void close() { + if (!delegate.isEmpty()) { + LOGGER.warn("Problems were reported during {}: {}", contextSupplier.get(), delegate.getTreeReport()); + } + } +} diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeWorldNativeAccess.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeWorldNativeAccess.java index c662725a5f..2a9b01ad96 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeWorldNativeAccess.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeWorldNativeAccess.java @@ -27,7 +27,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -108,7 +107,14 @@ public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) { return false; } tileEntity.setLevel(getWorld()); - tileEntity.loadWithComponents(TagValueInput.create(ProblemReporter.DISCARDING, getWorld().registryAccess(), nativeTag)); + SpongeLoggingProblemReporter.with( + () -> "loading tile entity at " + position, + reporter -> { + var input = TagValueInput.create(reporter, getWorld().registryAccess(), nativeTag); + tileEntity.loadWithComponents(input); + return null; + } + ); return true; }