Guest User

Untitled

a guest
Jun 5th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import net.minecraft.server.v1_15_R1.BlockPosition;
  2. import net.minecraft.server.v1_15_R1.NBTTagCompound;
  3. import net.minecraft.server.v1_15_R1.TileEntity;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.block.data.BlockData;
  6. import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
  7.  
  8. import javax.annotation.Nonnull;
  9.  
  10. public class RawBlockInfo {
  11.     private final BlockData data;
  12.     private final NBTTagCompound nbt;
  13.  
  14.     public RawBlockInfo(@Nonnull Block source) {
  15.         this.data = source.getBlockData().clone();
  16.         TileEntity sourceTile = ((CraftWorld) source.getWorld()).getHandle()
  17.                 .getTileEntity(new BlockPosition(source.getX(), source.getY(), source.getZ()));
  18.         if (sourceTile == null)
  19.             this.nbt = null;
  20.         else {
  21.             this.nbt = new NBTTagCompound();
  22.             sourceTile.save(this.nbt);
  23.         }
  24.     }
  25.  
  26.     public void apply(@Nonnull Block target) {
  27.         target.setBlockData(this.data, false); // applyPhysics
  28.         if (this.nbt == null) return;
  29.         TileEntity targetTile = ((CraftWorld) target.getWorld()).getHandle()
  30.                 .getTileEntity(new BlockPosition(target.getX(), target.getY(), target.getZ()));
  31.         if (targetTile == null) throw new NullPointerException();
  32.         this.nbt.setInt("x", target.getX());
  33.         this.nbt.setInt("y", target.getY());
  34.         this.nbt.setInt("z", target.getZ());
  35.         targetTile.load(this.nbt);
  36.         targetTile.update();
  37.         target.getState().update(true);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment