Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
}

/**
Expand Down Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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))
);
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

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> T with(Supplier<String> contextSupplier, Function<ProblemReporter, T> consumer) {
try (var problemReporter = new PaperweightLoggingProblemReporter(contextSupplier)) {
return consumer.apply(problemReporter);
}
}

PaperweightLoggingProblemReporter(Supplier<String> contextSupplier) {
this.contextSupplier = contextSupplier;
}

private final Collector delegate = new Collector();
private final Supplier<String> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));

Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
}

/**
Expand Down Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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))
);
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

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> T with(Supplier<String> contextSupplier, Function<ProblemReporter, T> consumer) {
try (var problemReporter = new PaperweightLoggingProblemReporter(contextSupplier)) {
return consumer.apply(problemReporter);
}
}

PaperweightLoggingProblemReporter(Supplier<String> contextSupplier) {
this.contextSupplier = contextSupplier;
}

private final Collector delegate = new Collector();
private final Supplier<String> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));

Expand All @@ -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())
Expand Down
Loading
Loading