2017-03-25 05:22:02 +00:00
|
|
|
From a703dc3147918196659551ad173b9072f80e983c Mon Sep 17 00:00:00 2001
|
2016-03-29 01:01:42 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 28 Mar 2016 20:55:47 -0400
|
|
|
|
Subject: [PATCH] MC Utils
|
|
|
|
|
|
|
|
|
2016-06-18 06:03:40 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2016-12-29 13:29:09 +00:00
|
|
|
index b0aba6089..81fc04ed3 100644
|
2016-06-18 06:03:40 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2016-06-23 02:18:41 +00:00
|
|
|
@@ -675,6 +675,7 @@ public class Chunk {
|
2016-06-18 06:03:40 +00:00
|
|
|
return !block.isTileEntity() ? null : ((ITileEntity) block).a(this.world, iblockdata.getBlock().toLegacyData(iblockdata));
|
|
|
|
}
|
|
|
|
|
|
|
|
+ @Nullable public final TileEntity getTileEntityImmediately(BlockPosition pos) { return this.a(pos, EnumTileEntityState.IMMEDIATE); } // Paper - OBFHELPER
|
|
|
|
@Nullable
|
|
|
|
public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
|
|
|
|
// CraftBukkit start
|
2016-03-29 01:01:42 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
|
|
|
new file mode 100644
|
2016-12-29 13:29:09 +00:00
|
|
|
index 000000000..1159eea1a
|
2016-03-29 01:01:42 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
2016-12-29 13:29:09 +00:00
|
|
|
@@ -0,0 +1,189 @@
|
2016-03-29 01:01:42 +00:00
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
2016-05-17 00:50:09 +00:00
|
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
2016-03-29 01:01:42 +00:00
|
|
|
+import org.bukkit.Location;
|
2016-05-28 02:28:23 +00:00
|
|
|
+import org.bukkit.craftbukkit.util.Waitable;
|
|
|
|
+import org.spigotmc.AsyncCatcher;
|
2016-03-29 01:01:42 +00:00
|
|
|
+
|
2016-05-13 05:34:37 +00:00
|
|
|
+import javax.annotation.Nullable;
|
2016-05-28 02:28:23 +00:00
|
|
|
+import java.util.concurrent.ExecutionException;
|
2016-05-17 00:50:09 +00:00
|
|
|
+import java.util.concurrent.Executor;
|
|
|
|
+import java.util.concurrent.Executors;
|
2016-05-28 02:28:23 +00:00
|
|
|
+import java.util.function.Supplier;
|
2016-03-29 01:01:42 +00:00
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
2016-05-14 02:27:20 +00:00
|
|
|
+public final class MCUtil {
|
2016-05-23 02:14:17 +00:00
|
|
|
+ private static final Executor asyncExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Paper Async Task Handler Thread - %1$d").build());
|
2016-03-29 01:01:42 +00:00
|
|
|
+
|
|
|
|
+ private MCUtil() {}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
2016-05-28 02:28:23 +00:00
|
|
|
+ * Ensures the target code is running on the main thread
|
|
|
|
+ * @param reason
|
|
|
|
+ * @param run
|
|
|
|
+ * @param <T>
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static <T> T ensureMain(String reason, Supplier<T> run) {
|
|
|
|
+ if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().primaryThread) {
|
|
|
|
+ new IllegalStateException( "Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace();
|
|
|
|
+ Waitable<T> wait = new Waitable<T>() {
|
|
|
|
+ @Override
|
|
|
|
+ protected T evaluate() {
|
|
|
|
+ return run.get();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ MinecraftServer.getServer().processQueue.add(wait);
|
|
|
|
+ try {
|
|
|
|
+ return wait.get();
|
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return run.get();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2016-03-29 01:01:42 +00:00
|
|
|
+ * Calculates distance between 2 entities
|
|
|
|
+ * @param e1
|
|
|
|
+ * @param e2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distance(Entity e1, Entity e2) {
|
|
|
|
+ return Math.sqrt(distanceSq(e1, e2));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Calculates distance between 2 block positions
|
|
|
|
+ * @param e1
|
|
|
|
+ * @param e2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distance(BlockPosition e1, BlockPosition e2) {
|
|
|
|
+ return Math.sqrt(distanceSq(e1, e2));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the distance between 2 positions
|
|
|
|
+ * @param x1
|
|
|
|
+ * @param y1
|
|
|
|
+ * @param z1
|
|
|
|
+ * @param x2
|
|
|
|
+ * @param y2
|
|
|
|
+ * @param z2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
|
|
+ return Math.sqrt(distanceSq(x1, y1, z1, x2, y2, z2));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get's the distance squared between 2 entities
|
|
|
|
+ * @param e1
|
|
|
|
+ * @param e2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distanceSq(Entity e1, Entity e2) {
|
|
|
|
+ return distanceSq(e1.locX,e1.locY,e1.locZ, e2.locX,e2.locY,e2.locZ);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the distance sqaured between 2 block positions
|
|
|
|
+ * @param pos1
|
|
|
|
+ * @param pos2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distanceSq(BlockPosition pos1, BlockPosition pos2) {
|
|
|
|
+ return distanceSq(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the distance squared between 2 positions
|
|
|
|
+ * @param x1
|
|
|
|
+ * @param y1
|
|
|
|
+ * @param z1
|
|
|
|
+ * @param x2
|
|
|
|
+ * @param y2
|
|
|
|
+ * @param z2
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static double distanceSq(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
|
|
+ return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Converts a NMS World/BlockPosition to Bukkit Location
|
|
|
|
+ * @param world
|
|
|
|
+ * @param pos
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static Location toLocation(World world, BlockPosition pos) {
|
|
|
|
+ return new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Converts an NMS entity's current location to a Bukkit Location
|
|
|
|
+ * @param entity
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static Location toLocation(Entity entity) {
|
|
|
|
+ return new Location(entity.getWorld().getWorld(), entity.locX, entity.locY, entity.locZ);
|
|
|
|
+ }
|
2016-03-31 23:29:06 +00:00
|
|
|
+
|
2016-04-16 01:31:12 +00:00
|
|
|
+ public static BlockPosition toBlockPosition(Location loc) {
|
|
|
|
+ return new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
|
|
|
+ }
|
|
|
|
+
|
2016-03-31 23:29:06 +00:00
|
|
|
+ public static boolean isEdgeOfChunk(BlockPosition pos) {
|
2016-04-01 01:43:37 +00:00
|
|
|
+ final int modX = pos.getX() & 15;
|
|
|
|
+ final int modZ = pos.getZ() & 15;
|
|
|
|
+ return (modX == 0 || modX == 15 || modZ == 0 || modZ == 15);
|
2016-03-31 23:29:06 +00:00
|
|
|
+ }
|
2016-05-13 05:34:37 +00:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets a chunk without changing its boolean for should unload
|
|
|
|
+ * @param world
|
|
|
|
+ * @param x
|
|
|
|
+ * @param z
|
|
|
|
+ * @return
|
|
|
|
+ */
|
2016-06-18 06:03:40 +00:00
|
|
|
+ @Nullable
|
|
|
|
+ public static Chunk getLoadedChunkWithoutMarkingActive(World world, int x, int z) {
|
2016-05-13 05:34:37 +00:00
|
|
|
+ return ((ChunkProviderServer) world.chunkProvider).chunks.get(ChunkCoordIntPair.a(x, z));
|
|
|
|
+ }
|
2016-05-14 02:27:20 +00:00
|
|
|
+
|
2016-05-13 05:34:37 +00:00
|
|
|
+ /**
|
|
|
|
+ * Gets a chunk without changing its boolean for should unload
|
|
|
|
+ * @param provider
|
|
|
|
+ * @param x
|
|
|
|
+ * @param z
|
|
|
|
+ * @return
|
|
|
|
+ */
|
2016-06-18 06:03:40 +00:00
|
|
|
+ @Nullable
|
|
|
|
+ public static Chunk getLoadedChunkWithoutMarkingActive(IChunkProvider provider, int x, int z) {
|
2016-05-14 02:27:20 +00:00
|
|
|
+ return ((ChunkProviderServer)provider).chunks.get(ChunkCoordIntPair.a(x, z));
|
2016-05-13 05:34:37 +00:00
|
|
|
+ }
|
2016-05-17 00:50:09 +00:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Posts a task to be executed asynchronously
|
|
|
|
+ * @param run
|
|
|
|
+ */
|
|
|
|
+ public static void scheduleAsyncTask(Runnable run) {
|
|
|
|
+ asyncExecutor.execute(run);
|
|
|
|
+ }
|
2016-06-18 06:03:40 +00:00
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public static TileEntityHopper getHopper(World world, BlockPosition pos) {
|
|
|
|
+ Chunk chunk = world.getChunkIfLoaded(pos.getX() >> 4, pos.getZ() >> 4);
|
|
|
|
+ if (chunk != null && chunk.getBlockData(pos).getBlock() == Blocks.HOPPER) {
|
|
|
|
+ TileEntity tileEntity = chunk.getTileEntityImmediately(pos);
|
|
|
|
+ if (tileEntity instanceof TileEntityHopper) {
|
|
|
|
+ return (TileEntityHopper) tileEntity;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
2016-03-29 01:01:42 +00:00
|
|
|
+}
|
2016-05-02 03:54:08 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/NBTTagCompound.java b/src/main/java/net/minecraft/server/NBTTagCompound.java
|
2016-12-29 13:29:09 +00:00
|
|
|
index 90d18f489..2a2f53c82 100644
|
2016-05-02 03:54:08 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/NBTTagCompound.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NBTTagCompound.java
|
2016-12-20 22:34:27 +00:00
|
|
|
@@ -19,7 +19,7 @@ import org.apache.logging.log4j.Logger;
|
2016-05-02 03:54:08 +00:00
|
|
|
public class NBTTagCompound extends NBTBase {
|
|
|
|
|
2016-12-20 22:34:27 +00:00
|
|
|
private static final Logger b = LogManager.getLogger();
|
2016-06-09 03:57:14 +00:00
|
|
|
- private final Map<String, NBTBase> map = Maps.newHashMap();
|
|
|
|
+ public final Map<String, NBTBase> map = Maps.newHashMap(); // Paper
|
2016-05-02 03:54:08 +00:00
|
|
|
|
|
|
|
public NBTTagCompound() {}
|
|
|
|
|
2016-12-20 22:34:27 +00:00
|
|
|
@@ -91,11 +91,13 @@ public class NBTTagCompound extends NBTBase {
|
2016-05-02 03:54:08 +00:00
|
|
|
this.map.put(s, new NBTTagLong(i));
|
|
|
|
}
|
|
|
|
|
2016-07-27 22:46:02 +00:00
|
|
|
+ public void setUUID(String prefix, UUID uuid) { a(prefix, uuid); } // Paper - OBFHELPER
|
2016-05-02 03:54:08 +00:00
|
|
|
public void a(String s, UUID uuid) {
|
|
|
|
this.setLong(s + "Most", uuid.getMostSignificantBits());
|
|
|
|
this.setLong(s + "Least", uuid.getLeastSignificantBits());
|
|
|
|
}
|
|
|
|
|
2016-07-27 22:46:02 +00:00
|
|
|
+ public UUID getUUID(String prefix) { return a(prefix); } // Paper - OBFHELPER
|
2016-05-12 02:07:46 +00:00
|
|
|
@Nullable
|
2016-05-02 03:54:08 +00:00
|
|
|
public UUID a(String s) {
|
|
|
|
return new UUID(this.getLong(s + "Most"), this.getLong(s + "Least"));
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
|
2016-12-29 13:29:09 +00:00
|
|
|
index 370203b2d..ae7498c03 100644
|
2016-05-02 03:54:08 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/NBTTagList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
|
|
|
|
@@ -12,7 +12,7 @@ import org.apache.logging.log4j.Logger;
|
|
|
|
public class NBTTagList extends NBTBase {
|
|
|
|
|
|
|
|
private static final Logger b = LogManager.getLogger();
|
|
|
|
- private List<NBTBase> list = Lists.newArrayList();
|
|
|
|
+ public List<NBTBase> list = Lists.newArrayList(); // Paper
|
|
|
|
private byte type = 0;
|
|
|
|
|
|
|
|
public NBTTagList() {}
|
2016-03-29 01:01:42 +00:00
|
|
|
--
|
2017-03-25 05:22:02 +00:00
|
|
|
2.12.0.windows.1
|
2016-03-29 01:01:42 +00:00
|
|
|
|