Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.minecraft.server.v1_15_R1.BlockPosition;
- import net.minecraft.server.v1_15_R1.NBTTagCompound;
- import net.minecraft.server.v1_15_R1.TileEntity;
- import org.bukkit.block.Block;
- import org.bukkit.block.data.BlockData;
- import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
- import javax.annotation.Nonnull;
- public class RawBlockInfo {
- private final BlockData data;
- private final NBTTagCompound nbt;
- public RawBlockInfo(@Nonnull Block source) {
- this.data = source.getBlockData().clone();
- TileEntity sourceTile = ((CraftWorld) source.getWorld()).getHandle()
- .getTileEntity(new BlockPosition(source.getX(), source.getY(), source.getZ()));
- if (sourceTile == null)
- this.nbt = null;
- else {
- this.nbt = new NBTTagCompound();
- sourceTile.save(this.nbt);
- }
- }
- public void apply(@Nonnull Block target) {
- target.setBlockData(this.data, false); // applyPhysics
- if (this.nbt == null) return;
- TileEntity targetTile = ((CraftWorld) target.getWorld()).getHandle()
- .getTileEntity(new BlockPosition(target.getX(), target.getY(), target.getZ()));
- if (targetTile == null) throw new NullPointerException();
- this.nbt.setInt("x", target.getX());
- this.nbt.setInt("y", target.getY());
- this.nbt.setInt("z", target.getZ());
- targetTile.load(this.nbt);
- targetTile.update();
- target.getState().update(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment