Skip to content

Commit

Permalink
better get/set block nbt impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 2, 2020
1 parent ab3224f commit 962747d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 64 deletions.
Expand Up @@ -44,20 +44,24 @@ public TeleportCommand() {
// <EntityTag.location>
//
// @Usage
// Use to teleport a player to the location its cursor is pointing on
// Use to teleport a player to the location their cursor is pointing at.
// - teleport <player> <player.cursor_on>
//
// @Usage
// Use to teleport a player high above
// Use to teleport a player high above.
// - teleport <player> <player.location.add[0,200,0]>
//
// @Usage
// Use to teleport to a random online player
// Use to teleport to a random online player.
// - teleport <player> <server.online_players.random.location>
//
// @Usage
// Use to teleport all players to your location
// Use to teleport all players to your location.
// - teleport <server.online_players> <player.location>
//
// @Usage
// Use to teleport the NPC to a location that was noted wih the <@link commmand note> command.
// - teleport <npc> my_prenoted_location
// -->

@Override
Expand Down
@@ -1,10 +1,10 @@
package com.denizenscript.denizen.nms.v1_14.helpers;

import com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder;
import com.denizenscript.denizen.nms.v1_14.impl.jnbt.CompoundTagImpl;
import com.google.common.collect.Iterables;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.blocks.ModernBlockData;
import com.denizenscript.denizen.nms.interfaces.BlockHelper;
import com.denizenscript.denizen.nms.util.PlayerProfile;
Expand Down Expand Up @@ -104,27 +104,25 @@ public void setPlayerProfile(Skull skull, PlayerProfile playerProfile) {

@Override
public CompoundTag getNbtData(Block block) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return null;
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (te != null) {
NBTTagCompound compound = new NBTTagCompound();
te.save(compound);
return CompoundTagImpl.fromNMSTag(compound);
}
return CompoundTagImpl.fromNMSTag(tileEntity.b());
return null;
}

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return;
}
tileEntity.load(((CompoundTagImpl) compoundTag).toNMSTag());
tileEntity.update();
public void setNbtData(Block block, CompoundTag ctag) {
CompoundTagBuilder builder = ctag.createBuilder();
builder.putInt("x", block.getX());
builder.putInt("y", block.getY());
builder.putInt("z", block.getZ());
ctag = builder.build();
BlockPosition blockPos = new BlockPosition(block.getX(), block.getY(), block.getZ());
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(blockPos);
te.load(((CompoundTagImpl) ctag).toNMSTag());
}

private static net.minecraft.server.v1_14_R1.Block getBlockFrom(Material material) {
Expand Down
@@ -1,10 +1,10 @@
package com.denizenscript.denizen.nms.v1_15.helpers;

import com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder;
import com.denizenscript.denizen.nms.v1_15.impl.jnbt.CompoundTagImpl;
import com.google.common.collect.Iterables;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.blocks.ModernBlockData;
import com.denizenscript.denizen.nms.interfaces.BlockHelper;
import com.denizenscript.denizen.nms.util.PlayerProfile;
Expand Down Expand Up @@ -97,30 +97,25 @@ public void setPlayerProfile(Skull skull, PlayerProfile playerProfile) {

@Override
public CompoundTag getNbtData(Block block) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
if (!(state instanceof CraftBlockEntityState)) {
return null;
}
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return null;
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (te != null) {
NBTTagCompound compound = new NBTTagCompound();
te.save(compound);
return CompoundTagImpl.fromNMSTag(compound);
}
return CompoundTagImpl.fromNMSTag(tileEntity.b());
return null;
}

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return;
}
tileEntity.load(((CompoundTagImpl) compoundTag).toNMSTag());
tileEntity.update();
public void setNbtData(Block block, CompoundTag ctag) {
CompoundTagBuilder builder = ctag.createBuilder();
builder.putInt("x", block.getX());
builder.putInt("y", block.getY());
builder.putInt("z", block.getZ());
ctag = builder.build();
BlockPosition blockPos = new BlockPosition(block.getX(), block.getY(), block.getZ());
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(blockPos);
te.load(((CompoundTagImpl) ctag).toNMSTag());
}

private static net.minecraft.server.v1_15_R1.Block getBlockFrom(Material material) {
Expand Down
@@ -1,10 +1,10 @@
package com.denizenscript.denizen.nms.v1_16.helpers;

import com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder;
import com.denizenscript.denizen.nms.v1_16.impl.jnbt.CompoundTagImpl;
import com.google.common.collect.Iterables;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.blocks.ModernBlockData;
import com.denizenscript.denizen.nms.interfaces.BlockHelper;
import com.denizenscript.denizen.nms.util.PlayerProfile;
Expand Down Expand Up @@ -97,30 +97,25 @@ public void setPlayerProfile(Skull skull, PlayerProfile playerProfile) {

@Override
public CompoundTag getNbtData(Block block) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
if (!(state instanceof CraftBlockEntityState)) {
return null;
}
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return null;
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (te != null) {
NBTTagCompound compound = new NBTTagCompound();
te.save(compound);
return CompoundTagImpl.fromNMSTag(compound);
}
return CompoundTagImpl.fromNMSTag(tileEntity.b());
return null;
}

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
org.bukkit.block.BlockState state = block.getState();
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
TileEntity tileEntity = getTE((CraftBlockEntityState) state);
if (tileEntity == null) {
return;
}
tileEntity.load(((CraftBlockData) block.getBlockData()).getState(), ((CompoundTagImpl) compoundTag).toNMSTag());
tileEntity.update();
public void setNbtData(Block block, CompoundTag ctag) {
CompoundTagBuilder builder = ctag.createBuilder();
builder.putInt("x", block.getX());
builder.putInt("y", block.getY());
builder.putInt("z", block.getZ());
ctag = builder.build();
BlockPosition blockPos = new BlockPosition(block.getX(), block.getY(), block.getZ());
TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(blockPos);
te.load(((CraftBlockData) block.getBlockData()).getState(), ((CompoundTagImpl) ctag).toNMSTag());
}

private static net.minecraft.server.v1_16_R1.Block getBlockFrom(Material material) {
Expand Down

0 comments on commit 962747d

Please sign in to comment.