This commit is contained in:
Jesse Boyd 2017-09-13 18:18:14 +10:00
parent eddb4d8b2d
commit 671dc29c94
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 67 additions and 61 deletions

View File

@ -19,7 +19,7 @@ public class CUIListener implements Listener {
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2) {
if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2 || (int) from.getY() >> 2 != (int) to.getY() >> 2) {
FawePlayer<Object> player = FawePlayer.wrap(event.getPlayer());
CUI cui = player.getMeta("CUI");
if (cui instanceof StructureCUI) {

View File

@ -9,6 +9,7 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.sk89q.worldedit.Vector;
@ -17,6 +18,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -31,6 +33,7 @@ public class StructureCUI extends CUI {
private Vector pos2;
private Vector remove;
private NbtCompound removeTag;
private int combined;
public StructureCUI(FawePlayer player) {
@ -74,51 +77,7 @@ public class StructureCUI extends CUI {
update();
}
public synchronized void update() {
Player player = this.<Player>getPlayer().parent;
Location playerLoc = player.getLocation();
if (remove != null) {
int cx = playerLoc.getBlockX() >> 4;
int cz = playerLoc.getBlockZ() >> 4;
int viewDistance = viewDistance();
if (Math.abs(cx - (remove.getBlockX() >> 4)) <= viewDistance && Math.abs(cz - (remove.getBlockZ() >> 4)) <= viewDistance) {
Location removeLoc = new Location(player.getWorld(), remove.getX(), remove.getY(), remove.getZ());
player.sendBlockChange(removeLoc, FaweCache.getId(combined), (byte) FaweCache.getData(combined));
}
remove = null;
}
if (pos1 == null || pos2 == null) return;
Vector min = Vector.getMinimum(pos1, pos2);
Vector max = Vector.getMaximum(pos1, pos2);
// Position
double rotX = playerLoc.getYaw();
double rotY = playerLoc.getPitch();
double xz = Math.cos(Math.toRadians(rotY));
int x = (int) (playerLoc.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 3);
int z = (int) (playerLoc.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 3);
int y = Math.min(Math.min(255, max.getBlockY() + 32), playerLoc.getBlockY() + 3);
int minX = Math.max(Math.min(32, min.getBlockX() - x), -32);
int maxX = Math.max(Math.min(32, max.getBlockX() - x + 1), -32);
int minY = Math.max(Math.min(32, min.getBlockY() - y), -32);
int maxY = Math.max(Math.min(32, max.getBlockY() - y + 1), -32);
int minZ = Math.max(Math.min(32, min.getBlockZ() - z), -32);
int maxZ = Math.max(Math.min(32, max.getBlockZ() - z + 1), -32);
int sizeX = Math.min(32, maxX - minX);
int sizeY = Math.min(32, maxY - minY);
int sizeZ = Math.min(32, maxZ - minZ);
if (sizeX == 0 || sizeY == 0 || sizeZ == 0) return;
int posX = Math.max(minX, maxX - 48);
int posY = Math.max(minY, maxY - 48);
int posZ = Math.max(minZ, maxZ - 48);
// NBT
private NbtCompound constructStructureNbt(int x, int y, int z, int posX, int posY, int posZ, int sizeX, int sizeY, int sizeZ) {
HashMap<String, Object> tag = new HashMap<>();
tag.put("name", UUID.randomUUID().toString());
tag.put("author", "Empire92"); // :D
@ -143,29 +102,76 @@ public class StructureCUI extends CUI {
tag.put("seed", 0);
tag.put("id", "minecraft:structure_block");
Object nmsTag = BukkitQueue_0.fromNative(FaweCache.asTag(tag));
NbtCompound compound = NbtFactory.fromNMSCompound(nmsTag);
return NbtFactory.fromNMSCompound(nmsTag);
}
// Type
int type = 7;
// Packet
private void sendNbt(Vector pos, NbtCompound compound) {
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
PacketContainer containter = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
containter.getBlockPositionModifier().write(0, new BlockPosition(x, y, z));
containter.getIntegers().write(0, type);
containter.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()));
containter.getIntegers().write(0, 7);
containter.getNbtModifier().write(0, compound);
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
Player player = this.<Player>getPlayer().parent;
try {
Block block = player.getWorld().getBlockAt(x, y, z);
remove = new Vector(x, y, z);
combined = FaweCache.getCombined(block.getTypeId(), block.getData());
Location blockLoc = new Location(player.getWorld(), x, y, z);
player.sendBlockChange(blockLoc, Material.STRUCTURE_BLOCK, (byte) 0);
manager.sendServerPacket(player, containter);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public synchronized void update() {
Player player = this.<Player>getPlayer().parent;
Location playerLoc = player.getLocation();
if (remove != null) {
int cx = playerLoc.getBlockX() >> 4;
int cz = playerLoc.getBlockZ() >> 4;
int viewDistance = viewDistance();
if (Math.abs(cx - (remove.getBlockX() >> 4)) <= viewDistance && Math.abs(cz - (remove.getBlockZ() >> 4)) <= viewDistance) {
Map<String, NbtBase<?>> map = removeTag.getValue();
map.put("sizeX", NbtFactory.of("sizeX", 0));
sendNbt(remove, removeTag);
Location removeLoc = new Location(player.getWorld(), remove.getX(), remove.getY(), remove.getZ());
player.sendBlockChange(removeLoc, FaweCache.getId(combined), (byte) FaweCache.getData(combined));
}
remove = null;
}
if (pos1 == null || pos2 == null) return;
Vector min = Vector.getMinimum(pos1, pos2);
Vector max = Vector.getMaximum(pos1, pos2);
// Position
double rotX = playerLoc.getYaw();
double rotY = playerLoc.getPitch();
double xz = Math.cos(Math.toRadians(rotY));
int x = (int) (playerLoc.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 3);
int z = (int) (playerLoc.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 3);
int y = Math.min(Math.min(255, max.getBlockY() + 32), playerLoc.getBlockY() + 3);
int minX = Math.max(Math.min(32, min.getBlockX() - x), -32);
int maxX = Math.max(Math.min(32, max.getBlockX() - x + 1), -32);
int minY = Math.max(Math.min(32, min.getBlockY() - y), -32);
int maxY = Math.max(Math.min(32, max.getBlockY() - y + 1), -32);
int minZ = Math.max(Math.min(32, min.getBlockZ() - z), -32);
int maxZ = Math.max(Math.min(32, max.getBlockZ() - z + 1), -32);
int sizeX = Math.min(32, maxX - minX);
int sizeY = Math.min(32, maxY - minY);
int sizeZ = Math.min(32, maxZ - minZ);
if (sizeX == 0 || sizeY == 0 || sizeZ == 0) return;
// maxX - 32;
int posX = Math.max(minX, Math.min(16, maxX) - 32);
int posY = Math.max(minY, Math.min(16, maxY) - 32);
int posZ = Math.max(minZ, Math.min(16, maxZ) - 32);
// NBT
NbtCompound compound = constructStructureNbt(x, y, z, posX, posY, posZ, sizeX, sizeY, sizeZ);
Block block = player.getWorld().getBlockAt(x, y, z);
remove = new Vector(x, y, z);
combined = FaweCache.getCombined(block.getTypeId(), block.getData());
removeTag = compound;
Location blockLoc = new Location(player.getWorld(), x, y, z);
player.sendBlockChange(blockLoc, Material.STRUCTURE_BLOCK, (byte) 0);
sendNbt(remove, compound);
}
}