Create default TileEntity data where required.

Fixes #1093
Fixes #1042
Dieser Commit ist enthalten in:
dordsor21 2021-06-10 13:39:36 +01:00
Ursprung 71130025e8
Commit 7ef8b2f95e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
13 geänderte Dateien mit 134 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,8 @@
package com.boydti.fawe.bukkit.adapter.mc1_15_2; package com.boydti.fawe.bukkit.adapter.mc1_15_2;
import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil; import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_15_R1.Block; import net.minecraft.server.v1_15_R1.Block;
@ -9,6 +12,8 @@ import net.minecraft.server.v1_15_R1.EnumPistonReaction;
import net.minecraft.server.v1_15_R1.IBlockData; import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.ITileEntity; import net.minecraft.server.v1_15_R1.ITileEntity;
import net.minecraft.server.v1_15_R1.Material; import net.minecraft.server.v1_15_R1.Material;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.TileEntity;
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
public class BlockMaterial_1_15_2 implements BlockMaterial { public class BlockMaterial_1_15_2 implements BlockMaterial {
@ -19,6 +24,7 @@ public class BlockMaterial_1_15_2 implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile;
public BlockMaterial_1_15_2(Block block) { public BlockMaterial_1_15_2(Block block) {
this(block, block.getBlockData()); this(block, block.getBlockData());
@ -32,6 +38,8 @@ public class BlockMaterial_1_15_2 implements BlockMaterial {
this.craftMaterial = craftBlockData.getMaterial(); this.craftMaterial = craftBlockData.getMaterial();
this.isTranslucent = !(boolean) ReflectionUtil.getField(Block.class, block, "v"); this.isTranslucent = !(boolean) ReflectionUtil.getField(Block.class, block, "v");
opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO);
TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null);
tile = new LazyCompoundTag_1_15_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
} }
public Block getBlock() { public Block getBlock() {
@ -150,6 +158,16 @@ public class BlockMaterial_1_15_2 implements BlockMaterial {
return block instanceof ITileEntity; return block instanceof ITileEntity;
} }
@Override
public boolean isTile() {
return block.isTileEntity();
}
@Override
public CompoundTag getDefaultTile() {
return tile;
}
@Override @Override
public int getMapColor() { public int getMapColor() {
return material.i().rgb; return material.i().rgb;

Datei anzeigen

@ -1,5 +1,8 @@
package com.boydti.fawe.bukkit.adapter.mc1_16_1; package com.boydti.fawe.bukkit.adapter.mc1_16_1;
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil; import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R1.Block; import net.minecraft.server.v1_16_R1.Block;
@ -10,6 +13,8 @@ import net.minecraft.server.v1_16_R1.EnumPistonReaction;
import net.minecraft.server.v1_16_R1.IBlockData; import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.ITileEntity; import net.minecraft.server.v1_16_R1.ITileEntity;
import net.minecraft.server.v1_16_R1.Material; import net.minecraft.server.v1_16_R1.Material;
import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.TileEntity;
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
public class BlockMaterial_1_16_1 implements BlockMaterial { public class BlockMaterial_1_16_1 implements BlockMaterial {
@ -20,6 +25,7 @@ public class BlockMaterial_1_16_1 implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile;
public BlockMaterial_1_16_1(Block block) { public BlockMaterial_1_16_1(Block block) {
this(block, block.getBlockData()); this(block, block.getBlockData());
@ -34,6 +40,8 @@ public class BlockMaterial_1_16_1 implements BlockMaterial {
BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB"); BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB");
this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n");
opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO);
TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null);
tile = new LazyCompoundTag_1_16_1(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
} }
public Block getBlock() { public Block getBlock() {
@ -153,6 +161,16 @@ public class BlockMaterial_1_16_1 implements BlockMaterial {
return block instanceof ITileEntity; return block instanceof ITileEntity;
} }
@Override
public boolean isTile() {
return block.isTileEntity();
}
@Override
public CompoundTag getDefaultTile() {
return tile;
}
@Override @Override
public int getMapColor() { public int getMapColor() {
return material.h().rgb; return material.h().rgb;

Datei anzeigen

@ -1,5 +1,8 @@
package com.boydti.fawe.bukkit.adapter.mc1_16_2; package com.boydti.fawe.bukkit.adapter.mc1_16_2;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.nbt.LazyCompoundTag_1_16_2;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil; import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R2.Block; import net.minecraft.server.v1_16_R2.Block;
@ -10,6 +13,8 @@ import net.minecraft.server.v1_16_R2.EnumPistonReaction;
import net.minecraft.server.v1_16_R2.IBlockData; import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.ITileEntity; import net.minecraft.server.v1_16_R2.ITileEntity;
import net.minecraft.server.v1_16_R2.Material; import net.minecraft.server.v1_16_R2.Material;
import net.minecraft.server.v1_16_R2.NBTTagCompound;
import net.minecraft.server.v1_16_R2.TileEntity;
import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData;
public class BlockMaterial_1_16_2 implements BlockMaterial { public class BlockMaterial_1_16_2 implements BlockMaterial {
@ -20,6 +25,7 @@ public class BlockMaterial_1_16_2 implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile;
public BlockMaterial_1_16_2(Block block) { public BlockMaterial_1_16_2(Block block) {
this(block, block.getBlockData()); this(block, block.getBlockData());
@ -34,6 +40,8 @@ public class BlockMaterial_1_16_2 implements BlockMaterial {
BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB"); BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB");
this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n");
opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO);
TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null);
tile = new LazyCompoundTag_1_16_2(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
} }
public Block getBlock() { public Block getBlock() {
@ -153,6 +161,16 @@ public class BlockMaterial_1_16_2 implements BlockMaterial {
return block instanceof ITileEntity; return block instanceof ITileEntity;
} }
@Override
public boolean isTile() {
return block.isTileEntity();
}
@Override
public CompoundTag getDefaultTile() {
return tile;
}
@Override @Override
public int getMapColor() { public int getMapColor() {
return material.h().rgb; return material.h().rgb;

Datei anzeigen

@ -1,5 +1,8 @@
package com.boydti.fawe.bukkit.adapter.mc1_16_5; package com.boydti.fawe.bukkit.adapter.mc1_16_5;
import com.boydti.fawe.bukkit.adapter.mc1_16_5.nbt.LazyCompoundTag_1_16_5;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil; import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R3.Block; import net.minecraft.server.v1_16_R3.Block;
@ -10,6 +13,8 @@ import net.minecraft.server.v1_16_R3.EnumPistonReaction;
import net.minecraft.server.v1_16_R3.IBlockData; import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.ITileEntity; import net.minecraft.server.v1_16_R3.ITileEntity;
import net.minecraft.server.v1_16_R3.Material; import net.minecraft.server.v1_16_R3.Material;
import net.minecraft.server.v1_16_R3.NBTTagCompound;
import net.minecraft.server.v1_16_R3.TileEntity;
import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData;
public class BlockMaterial_1_16_5 implements BlockMaterial { public class BlockMaterial_1_16_5 implements BlockMaterial {
@ -20,6 +25,7 @@ public class BlockMaterial_1_16_5 implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile;
public BlockMaterial_1_16_5(Block block) { public BlockMaterial_1_16_5(Block block) {
this(block, block.getBlockData()); this(block, block.getBlockData());
@ -34,6 +40,8 @@ public class BlockMaterial_1_16_5 implements BlockMaterial {
BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB"); BlockBase.Info blockInfo = ReflectionUtil.getField(BlockBase.class, block, "aB");
this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n"); this.isTranslucent = !(boolean)ReflectionUtil.getField(BlockBase.Info.class, blockInfo, "n");
opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO); opacity = defaultState.b(BlockAccessAir.INSTANCE, BlockPosition.ZERO);
TileEntity tileEntity = !block.isTileEntity() ? null : ((ITileEntity)block).createTile(null);
tile = new LazyCompoundTag_1_16_5(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
} }
public Block getBlock() { public Block getBlock() {
@ -153,6 +161,16 @@ public class BlockMaterial_1_16_5 implements BlockMaterial {
return block instanceof ITileEntity; return block instanceof ITileEntity;
} }
@Override
public boolean isTile() {
return block.isTileEntity();
}
@Override
public CompoundTag getDefaultTile() {
return tile;
}
@Override @Override
public int getMapColor() { public int getMapColor() {
return material.h().rgb; return material.h().rgb;

Datei anzeigen

@ -69,7 +69,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
*/ */
public BaseBlock(BlockState blockState) { public BaseBlock(BlockState blockState) {
this.blockState = blockState; this.blockState = blockState;
nbtData = null; this.nbtData = null;
} }
/** /**

Datei anzeigen

@ -62,12 +62,12 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
private final BaseBlock emptyBaseBlock; private final BaseBlock emptyBaseBlock;
private CompoundInput compoundInput = CompoundInput.NULL; private CompoundInput compoundInput = CompoundInput.NULL;
protected BlockState(BlockType blockType, int internalId, int ordinal) { protected BlockState(BlockType blockType, int internalId, int ordinal, CompoundTag tile) {
this.blockType = blockType; this.blockType = blockType;
this.internalId = internalId; this.internalId = internalId;
this.ordinal = ordinal; this.ordinal = ordinal;
this.ordinalChar = (char) ordinal; this.ordinalChar = (char) ordinal;
this.emptyBaseBlock = new ImmutableBaseBlock(this); this.emptyBaseBlock = new ImmutableBaseBlock(this, tile);
} }
/** /**

Datei anzeigen

@ -186,7 +186,7 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*/ */
@Nullable @Nullable
default CompoundTag getNbtData() { default CompoundTag getNbtData() {
return null; return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
} }
/** /**

Datei anzeigen

@ -98,7 +98,7 @@ public class BlockTypesCache {
int ordinal = this.stateOrdinals[propId]; int ordinal = this.stateOrdinals[propId];
if (ordinal != -1) { if (ordinal != -1) {
int stateId = internalId + (propId << BIT_OFFSET); int stateId = internalId + (propId << BIT_OFFSET);
BlockState state = new BlockState(type, stateId, ordinal); BlockState state = new BlockState(type, stateId, ordinal, blockMaterial.getDefaultTile());
states.add(state); states.add(state);
} }
} }
@ -106,7 +106,7 @@ public class BlockTypesCache {
this.defaultState = states.get(this.stateOrdinals[defaultPropId]); this.defaultState = states.get(this.stateOrdinals[defaultPropId]);
} else { } else {
this.defaultState = new BlockState(type, internalId, states.size()); this.defaultState = new BlockState(type, internalId, states.size(), blockMaterial.getDefaultTile());
states.add(this.defaultState); states.add(this.defaultState);
} }
} }

Datei anzeigen

@ -48,7 +48,7 @@ public class FuzzyBlockState extends BlockState {
} }
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) { private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {
super(state.getBlockType(), state.getInternalId(), state.getOrdinal()); super(state.getBlockType(), state.getInternalId(), state.getOrdinal(), null);
if (values == null || values.isEmpty()) { if (values == null || values.isEmpty()) {
props = Collections.emptyMap(); props = Collections.emptyMap();
this.values = Collections.emptyMap(); this.values = Collections.emptyMap();

Datei anzeigen

@ -13,16 +13,19 @@ public final class ImmutableBaseBlock extends BaseBlock {
public ImmutableBaseBlock(BlockState blockState) { public ImmutableBaseBlock(BlockState blockState) {
super(blockState); super(blockState);
} }
public ImmutableBaseBlock(BlockState blockState, CompoundTag tile) {
super(blockState, tile);
}
@Nullable @Nullable
@Override @Override
public CompoundTag getNbtData() { public CompoundTag getNbtData() {
return null; return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
} }
@Override @Override
public boolean hasNbtData() { public boolean hasNbtData() {
return false; return getBlockType().getMaterial().isTile();
} }
@Override @Override

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.sk89q.jnbt.CompoundTag;
/** /**
* Describes the material for a block. * Describes the material for a block.
*/ */
@ -165,6 +167,20 @@ public interface BlockMaterial {
*/ */
boolean hasContainer(); boolean hasContainer();
/**
* Gets whether the block is a tile entity.
*
* @return If it is a tile entity
*/
boolean isTile();
/**
* Gets the default (empty) tile entity data
*
* @return default tile entity data
*/
CompoundTag getDefaultTile();
/** /**
* Get the map color. * Get the map color.
* @return or 0 * @return or 0

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.sk89q.jnbt.CompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;
@ -151,4 +153,14 @@ public class PassthroughBlockMaterial implements BlockMaterial {
public boolean hasContainer() { public boolean hasContainer() {
return blockMaterial.hasContainer(); return blockMaterial.hasContainer();
} }
@Override
public boolean isTile() {
return blockMaterial.isTile();
}
@Override
public CompoundTag getDefaultTile() {
return blockMaterial.getDefaultTile();
}
} }

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.sk89q.jnbt.CompoundTag;
class SimpleBlockMaterial implements BlockMaterial { class SimpleBlockMaterial implements BlockMaterial {
private boolean isAir; private boolean isAir;
@ -42,6 +44,8 @@ class SimpleBlockMaterial implements BlockMaterial {
private boolean hasContainer; private boolean hasContainer;
private int lightOpacity; private int lightOpacity;
private int mapColor; private int mapColor;
private boolean isTile;
private CompoundTag tile = null;
@Override @Override
public boolean isAir() { public boolean isAir() {
@ -228,6 +232,24 @@ class SimpleBlockMaterial implements BlockMaterial {
return this.hasContainer; return this.hasContainer;
} }
public void setIsTile(boolean isTile) {
this.isTile = isTile;
}
@Override
public boolean isTile() {
return isTile;
}
public void setDefaultTile(CompoundTag tile) {
this.tile = tile;
}
@Override
public CompoundTag getDefaultTile() {
return tile;
}
public void setHasContainer(boolean hasContainer) { public void setHasContainer(boolean hasContainer) {
this.hasContainer = hasContainer; this.hasContainer = hasContainer;
} }