From 0cbfc9308ec202b958fac6e55d4e0d5e873919e3 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 18 Aug 2018 19:35:53 +1000 Subject: [PATCH] Add base of sendFakeBlock to Sponge and Forge impls --- .../sk89q/worldedit/forge/ForgePlayer.java | 22 +++++++++++++++++++ .../sk89q/worldedit/sponge/SpongePlayer.java | 18 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index d4b906fc4..817315e92 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -29,6 +29,8 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemTypes; import io.netty.buffer.Unpooled; import net.minecraft.entity.player.EntityPlayerMP; @@ -36,7 +38,9 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.SPacketCustomPayload; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fml.common.registry.ForgeRegistries; @@ -164,6 +168,24 @@ public class ForgePlayer extends AbstractPlayerActor { return null; } + @Override + public void sendFakeBlock(Vector pos, BlockStateHolder block) { + BlockPos loc = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + if (block == null) { + // TODO +// player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); + } else { + // TODO +// player.sendBlockChange(loc, BukkitAdapter.adapt(block)); + if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { + player.connection.sendPacket(new SPacketUpdateTileEntity( + new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, + NBTConverter.toNative(((BaseBlock) block).getNbtData())) + ); + } + } + } + @Override public SessionKey getSessionKey() { return new SessionKeyImpl(player.getUniqueID(), player.getName()); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 37774dbc8..662d65e55 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemTypes; @@ -183,6 +184,23 @@ public class SpongePlayer extends AbstractPlayerActor { gameMode.getId()).get()); } + @Override + public void sendFakeBlock(Vector pos, BlockStateHolder block) { + org.spongepowered.api.world.Location loc = player.getWorld().getLocation(pos.getX(), pos.getY(), pos.getZ()); + if (block == null) { + player.sendBlockChange(loc.getBlockPosition(), loc.getBlock()); + } else { + // TODO +// player.sendBlockChange(loc, BukkitAdapter.adapt(block)); +// if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { +// BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); +// if (adapter != null) { +// adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData()); +// } +// } + } + } + @Override public SessionKey getSessionKey() { return new SessionKeyImpl(player.getUniqueId(), player.getName());