Fix legacy block wrappers with new NBT API (#2361)

This commit is contained in:
Maddy Miller 2023-07-15 18:47:24 +10:00 committed by GitHub
parent 19db609bcc
commit 5b674745f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 6 deletions

View File

@ -0,0 +1,48 @@
/*
* 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.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
@Deprecated
public class LegacyBaseBlockWrapper extends BaseBlock {
protected LegacyBaseBlockWrapper(BlockState blockState) {
super(blockState);
}
// These two methods force the legacy blocks to use the old NBT methods.
@Nullable
@Override
public LazyReference<LinCompoundTag> getNbtReference() {
CompoundTag nbtData = getNbtData();
return nbtData == null ? null : LazyReference.from(nbtData::toLinTag);
}
@Override
public void setNbtReference(@Nullable LazyReference<LinCompoundTag> nbtData) {
setNbtData(nbtData == null ? null : new CompoundTag(nbtData.getValue()));
}
}

View File

@ -28,7 +28,6 @@ import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
@ -42,7 +41,7 @@ import java.util.Map;
* deprecated for removal without replacement
*/
@Deprecated
public class MobSpawnerBlock extends BaseBlock {
public class MobSpawnerBlock extends LegacyBaseBlockWrapper {
private String mobType;
private short delay = -1;

View File

@ -27,7 +27,6 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.util.gson.GsonUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Arrays;
@ -42,7 +41,7 @@ import java.util.stream.Collectors;
* deprecated for removal without replacement
*/
@Deprecated
public class SignBlock extends BaseBlock {
public class SignBlock extends LegacyBaseBlockWrapper {
private String[] text;

View File

@ -23,7 +23,6 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.HashMap;
@ -36,7 +35,7 @@ import java.util.Map;
* deprecated for removal without replacement
*/
@Deprecated
public class SkullBlock extends BaseBlock {
public class SkullBlock extends LegacyBaseBlockWrapper {
private String owner = ""; // notchian