Add base of sendFakeBlock to Sponge and Forge impls

This commit is contained in:
Matthew Miller 2018-08-18 19:35:53 +10:00
parent 20b67db48d
commit 0cbfc9308e
2 changed files with 40 additions and 0 deletions

View File

@ -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());

View File

@ -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<World> 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());