2019-12-17 22:39:07 +00:00
From a0b808cc25884976a9235109a107fa6f2e6916a2 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
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/BlockAccessAir.java b/src/main/java/net/minecraft/server/BlockAccessAir.java
2019-12-11 00:56:03 +00:00
index eff6ebcd3..30cbfc8ea 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/BlockAccessAir.java
+++ b/src/main/java/net/minecraft/server/BlockAccessAir.java
@@ -14,6 +14,18 @@ public enum BlockAccessAir implements IBlockAccess {
return null;
}
+ // Paper start - If loaded util
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ return this.getFluid(blockposition);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ return this.getType(blockposition);
+ }
+ // Paper end
+
@Override
public IBlockData getType(BlockPosition blockposition) {
return Blocks.AIR.getBlockData();
2019-05-27 04:36:37 +00:00
diff --git a/src/main/java/net/minecraft/server/BlockDataAbstract.java b/src/main/java/net/minecraft/server/BlockDataAbstract.java
2019-12-17 22:39:07 +00:00
index 1cf97cefc..2040f1834 100644
2019-05-27 04:36:37 +00:00
--- a/src/main/java/net/minecraft/server/BlockDataAbstract.java
+++ b/src/main/java/net/minecraft/server/BlockDataAbstract.java
2019-12-17 22:39:07 +00:00
@@ -78,6 +78,7 @@ public abstract class BlockDataAbstract<O, S> implements IBlockDataHolder<S> {
2019-05-27 04:36:37 +00:00
return Collections.unmodifiableCollection(this.d.keySet());
}
+ public final <T extends Comparable<T>> boolean hasProperty(IBlockState<T> iblockstate) { return this.b(iblockstate); } // Paper - OBFHELPER
public <T extends Comparable<T>> boolean b(IBlockState<T> iblockstate) {
return this.d.containsKey(iblockstate);
}
2018-07-17 15:14:23 +00:00
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
2019-12-11 00:56:03 +00:00
index c88a62f6b..1cdf0346f 100644
2018-07-17 15:14:23 +00:00
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
2019-04-23 04:47:07 +00:00
@@ -120,6 +120,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
2019-01-01 03:15:55 +00:00
return d0 == 0.0D && d1 == 0.0D && d2 == 0.0D ? this : new BlockPosition((double) this.getX() + d0, (double) this.getY() + d1, (double) this.getZ() + d2);
2018-07-18 23:31:45 +00:00
}
2019-04-23 04:47:07 +00:00
+ public BlockPosition add(int i, int j, int k) {return b(i, j, k);} // Paper - OBFHELPER
public BlockPosition b(int i, int j, int k) {
2019-01-01 03:15:55 +00:00
return i == 0 && j == 0 && k == 0 ? this : new BlockPosition(this.getX() + i, this.getY() + j, this.getZ() + k);
2018-07-18 23:31:45 +00:00
}
2019-12-11 00:56:03 +00:00
@@ -210,6 +211,8 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
2019-04-23 04:47:07 +00:00
return new BlockPosition(this.getY() * baseblockposition.getZ() - this.getZ() * baseblockposition.getY(), this.getZ() * baseblockposition.getX() - this.getX() * baseblockposition.getZ(), this.getX() * baseblockposition.getY() - this.getY() * baseblockposition.getX());
2018-10-05 03:18:46 +00:00
}
2019-04-23 04:47:07 +00:00
+ @Deprecated // We'll replace this...
+ public BlockPosition asImmutable() { return immutableCopy(); } // Paper - OBFHELPER
public BlockPosition immutableCopy() {
2018-10-05 03:18:46 +00:00
return this;
}
2019-12-11 00:56:03 +00:00
@@ -402,6 +405,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
2018-07-19 04:42:43 +00:00
return this.d;
}
2019-04-23 04:47:07 +00:00
+ public BlockPosition.MutableBlockPosition setValues(int i, int j, int k) { return d(i, j, k);} // Paper - OBFHELPER
public BlockPosition.MutableBlockPosition d(int i, int j, int k) {
2018-07-19 04:42:43 +00:00
this.b = i;
this.c = j;
2019-12-11 00:56:03 +00:00
@@ -413,6 +417,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
return this.c(entity.locX(), entity.locY(), entity.locZ());
2018-07-19 04:42:43 +00:00
}
+ public BlockPosition.MutableBlockPosition setValues(double d0, double d1, double d2) { return c(d0, d1, d2);} // Paper - OBFHELPER
public BlockPosition.MutableBlockPosition c(double d0, double d1, double d2) {
2019-04-23 04:47:07 +00:00
return this.d(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2));
2018-07-19 04:42:43 +00:00
}
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
2019-12-11 00:56:03 +00:00
index 55373cae0..cfffbd031 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
2019-05-26 01:56:30 +00:00
@@ -25,7 +25,7 @@ import org.apache.logging.log4j.Logger;
2018-07-15 01:53:17 +00:00
public class Chunk implements IChunkAccess {
2017-10-05 13:38:21 +00:00
2019-04-25 06:53:51 +00:00
private static final Logger LOGGER = LogManager.getLogger();
2017-10-05 13:38:21 +00:00
- public static final ChunkSection a = null;
+ public static final ChunkSection a = null; public static final ChunkSection EMPTY_CHUNK_SECTION = Chunk.a; // Paper - OBFHELPER
private final ChunkSection[] sections;
2019-12-11 00:56:03 +00:00
private BiomeStorage d;
2019-04-23 04:47:07 +00:00
private final Map<BlockPosition, NBTTagCompound> e;
2019-05-27 06:14:14 +00:00
@@ -213,6 +213,18 @@ public class Chunk implements IChunkAccess {
}
}
+ // Paper start - If loaded util
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ return this.getFluid(blockposition);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ return this.getType(blockposition);
+ }
+ // Paper end
+
@Override
public Fluid getFluid(BlockPosition blockposition) {
return this.a(blockposition.getX(), blockposition.getY(), blockposition.getZ());
2019-12-11 00:56:03 +00:00
@@ -395,6 +407,7 @@ public class Chunk implements IChunkAccess {
2018-07-15 01:53:17 +00:00
return this.a(blockposition, Chunk.EnumTileEntityState.CHECK);
2016-06-18 06:03:40 +00:00
}
+ @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
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkCache.java b/src/main/java/net/minecraft/server/ChunkCache.java
2019-12-13 01:18:18 +00:00
index 11c4d23ba..53c15c1c0 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/ChunkCache.java
+++ b/src/main/java/net/minecraft/server/ChunkCache.java
2019-12-13 01:18:18 +00:00
@@ -8,7 +8,7 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
protected final int b;
protected final IChunkAccess[][] c;
protected boolean d;
- protected final World e;
+ protected final World e; protected final World getWorld() { return e; } // Paper - OBFHELPER
public ChunkCache(World world, BlockPosition blockposition, BlockPosition blockposition1) {
this.e = world;
@@ -71,6 +71,20 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
2019-12-11 00:56:03 +00:00
return this.a(i, j);
2019-05-27 06:14:14 +00:00
}
+ // Paper start - if loaded util
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
2019-12-13 01:18:18 +00:00
+ IChunkAccess chunk = getWorld().getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
2019-05-27 06:14:14 +00:00
+ return chunk == null ? null : chunk.getFluid(blockposition);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
2019-12-13 01:18:18 +00:00
+ IChunkAccess chunk = getWorld().getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
2019-05-27 06:14:14 +00:00
+ return chunk == null ? null : chunk.getType(blockposition);
+ }
+ // Paper end
+
@Nullable
@Override
2019-12-11 00:56:03 +00:00
public TileEntity getTileEntity(BlockPosition blockposition) {
2017-11-11 23:47:30 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
2019-12-11 00:56:03 +00:00
index 260644bf0..f2a19acd8 100644
2017-11-11 23:47:30 +00:00
--- a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
+++ b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
2019-04-23 04:47:07 +00:00
@@ -31,7 +31,9 @@ public class ChunkCoordIntPair {
return pair(this.x, this.z);
2017-11-11 23:47:30 +00:00
}
2019-04-23 04:47:07 +00:00
- public static long pair(int i, int j) {
+ public static long asLong(final BlockPosition pos) { return pair(pos.getX() >> 4, pos.getZ() >> 4); } // Paper - OBFHELPER
+ public static long asLong(int x, int z) { return pair(x, z); } // Paper - OBFHELPER
+ public static long pair(int i, int j) {
2019-01-01 03:15:55 +00:00
return (long) i & 4294967295L | ((long) j & 4294967295L) << 32;
2017-11-11 23:47:30 +00:00
}
2018-08-26 02:37:58 +00:00
2019-06-11 00:29:30 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-12-11 00:56:03 +00:00
index 2e8a087bd..c5121d369 100644
2019-06-11 00:29:30 +00:00
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-07-26 01:36:26 +00:00
@@ -77,6 +77,37 @@ public class ChunkProviderServer extends IChunkProvider {
2019-07-20 04:01:24 +00:00
this.cacheChunk[0] = ichunkaccess;
2019-06-11 00:29:30 +00:00
}
+ // Paper start - "real" get chunk if loaded
+ // Note: Partially copied from the getChunkAt method below
+ @Nullable
2019-06-14 02:27:40 +00:00
+ public Chunk getChunkAtIfCachedImmediately(int x, int z) {
2019-06-11 00:29:30 +00:00
+ long k = ChunkCoordIntPair.pair(x, z);
+
2019-07-26 01:36:26 +00:00
+ // Note: Bypass cache to make this MT-Safe
2019-06-11 00:29:30 +00:00
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
+ return null;
+ }
+
2019-06-14 02:27:40 +00:00
+ return playerChunk.getFullChunkIfCached();
+ }
+
+ @Nullable
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
+ long k = ChunkCoordIntPair.pair(x, z);
+
2019-07-26 01:36:26 +00:00
+ // Note: Bypass cache since we need to check ticket level, and to make this MT-Safe
2019-06-14 02:27:40 +00:00
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
+ return null;
+ }
+
2019-06-11 00:29:30 +00:00
+ return playerChunk.getFullChunk();
+ }
+ // Paper end
+
@Nullable
@Override
public IChunkAccess getChunkAt(int i, int j, ChunkStatus chunkstatus, boolean flag) {
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java
2019-12-11 00:56:03 +00:00
index 7ca3a1d0c..2edd9b871 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataBits.java
+++ b/src/main/java/net/minecraft/server/DataBits.java
2019-07-20 04:01:24 +00:00
@@ -83,6 +83,7 @@ public class DataBits {
2018-08-26 02:37:58 +00:00
}
}
+ public long[] getDataBits() { return this.a(); } // Paper - OBFHELPER
public long[] a() {
return this.a;
}
diff --git a/src/main/java/net/minecraft/server/DataPalette.java b/src/main/java/net/minecraft/server/DataPalette.java
2019-12-11 00:56:03 +00:00
index 75ba69886..45403fbe3 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataPalette.java
+++ b/src/main/java/net/minecraft/server/DataPalette.java
2019-04-23 04:47:07 +00:00
@@ -4,10 +4,12 @@ import javax.annotation.Nullable;
2018-08-26 02:37:58 +00:00
public interface DataPalette<T> {
2019-01-01 03:15:55 +00:00
2018-09-01 04:30:04 +00:00
+ default int getOrCreateIdFor(T object) { return this.a(object); } // Paper - OBFHELPER
2019-01-01 03:15:55 +00:00
int a(T t0);
2018-08-26 02:37:58 +00:00
2019-04-23 04:47:07 +00:00
boolean b(T t0);
2018-08-26 02:37:58 +00:00
+ @Nullable default T getObject(int dataBits) { return this.a(dataBits); } // Paper - OBFHELPER
2019-01-01 03:15:55 +00:00
@Nullable
T a(int i);
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/DataPaletteBlock.java b/src/main/java/net/minecraft/server/DataPaletteBlock.java
2019-12-11 00:56:03 +00:00
index 774a8f543..d5f5a5187 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataPaletteBlock.java
+++ b/src/main/java/net/minecraft/server/DataPaletteBlock.java
2019-07-20 04:01:24 +00:00
@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
2018-08-26 02:37:58 +00:00
public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
2019-01-01 03:15:55 +00:00
2018-08-26 02:37:58 +00:00
- private final DataPalette<T> b;
2019-01-01 03:15:55 +00:00
+ private final DataPalette<T> b; private final DataPalette<T> getDataPaletteGlobal() { return this.b; } // Paper - OBFHELPER
private final DataPaletteExpandable<T> c = (i, object) -> {
2018-08-26 02:37:58 +00:00
return 0;
};
2019-07-20 04:01:24 +00:00
@@ -19,9 +19,9 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
2018-08-26 02:37:58 +00:00
private final Function<NBTTagCompound, T> e;
private final Function<T, NBTTagCompound> f;
private final T g;
- protected DataBits a;
- private DataPalette<T> h;
- private int i;
+ protected DataBits a; protected DataBits getDataBits() { return this.a; } // Paper - OBFHELPER
+ private DataPalette<T> h; private DataPalette<T> getDataPalette() { return this.h; } // Paper - OBFHELPER
+ private int i; private int getBitsPerObject() { return this.i; } // Paper - OBFHELPER
private final ReentrantLock j = new ReentrantLock();
2019-04-23 04:47:07 +00:00
public void a() {
2019-07-20 04:01:24 +00:00
@@ -56,6 +56,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
2019-01-01 03:15:55 +00:00
return j << 8 | k << 4 | i;
2018-08-26 02:37:58 +00:00
}
+ private void initialize(int bitsPerObject) { this.b(bitsPerObject); } // Paper - OBFHELPER
2019-01-01 03:15:55 +00:00
private void b(int i) {
if (i != this.i) {
this.i = i;
2019-07-20 04:01:24 +00:00
@@ -133,6 +134,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
2019-01-01 03:15:55 +00:00
return t0 == null ? this.g : t0;
2018-08-26 02:37:58 +00:00
}
+ public void writeDataPaletteBlock(PacketDataSerializer packetDataSerializer) { this.b(packetDataSerializer); } // Paper - OBFHELPER
public void b(PacketDataSerializer packetdataserializer) {
2019-04-23 04:47:07 +00:00
this.a();
2018-08-26 02:37:58 +00:00
packetdataserializer.writeByte(this.i);
2018-08-04 21:03:53 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java
2019-12-11 00:56:03 +00:00
index fe69161e5..b40c8d2f8 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityCreature.java
+++ b/src/main/java/net/minecraft/server/EntityCreature.java
2019-04-23 04:47:07 +00:00
@@ -6,6 +6,8 @@ import org.bukkit.event.entity.EntityUnleashEvent;
2018-08-04 21:03:53 +00:00
public abstract class EntityCreature extends EntityInsentient {
2018-08-31 22:56:57 +00:00
+ public org.bukkit.craftbukkit.entity.CraftCreature getBukkitCreature() { return (org.bukkit.craftbukkit.entity.CraftCreature) super.getBukkitEntity(); } // Paper
2019-04-23 04:47:07 +00:00
+
protected EntityCreature(EntityTypes<? extends EntityCreature> entitytypes, World world) {
super(entitytypes, world);
}
2018-08-31 22:56:57 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
2019-12-17 22:39:07 +00:00
index e1398652a..7ee5eb987 100644
2018-08-31 22:56:57 +00:00
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
2019-06-25 01:47:58 +00:00
@@ -144,6 +144,7 @@ public abstract class EntityInsentient extends EntityLiving {
2018-08-31 22:56:57 +00:00
return this.goalTarget;
}
+ public org.bukkit.craftbukkit.entity.CraftMob getBukkitMob() { return (org.bukkit.craftbukkit.entity.CraftMob) super.getBukkitEntity(); } // Paper
public void setGoalTarget(@Nullable EntityLiving entityliving) {
// CraftBukkit start - fire event
setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
2018-08-04 21:03:53 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-11 00:56:03 +00:00
index 0f6fd2d70..138bc38e6 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-11 00:56:03 +00:00
@@ -129,6 +129,7 @@ public abstract class EntityLiving extends Entity {
2018-08-04 21:03:53 +00:00
public org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
public boolean collides = true;
public boolean canPickUpLoot;
2018-08-31 22:56:57 +00:00
+ public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper
2018-08-04 21:03:53 +00:00
@Override
public float getBukkitYaw() {
diff --git a/src/main/java/net/minecraft/server/EntityMonster.java b/src/main/java/net/minecraft/server/EntityMonster.java
2019-12-11 00:56:03 +00:00
index 00c3b666d..e5322fbae 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityMonster.java
+++ b/src/main/java/net/minecraft/server/EntityMonster.java
2019-06-25 01:47:58 +00:00
@@ -5,6 +5,7 @@ import java.util.function.Predicate;
2018-08-04 21:03:53 +00:00
public abstract class EntityMonster extends EntityCreature implements IMonster {
2019-01-01 03:15:55 +00:00
2018-08-31 22:56:57 +00:00
+ public org.bukkit.craftbukkit.entity.CraftMonster getBukkitMonster() { return (org.bukkit.craftbukkit.entity.CraftMonster) super.getBukkitEntity(); } // Paper
2019-04-23 04:47:07 +00:00
protected EntityMonster(EntityTypes<? extends EntityMonster> entitytypes, World world) {
2018-08-04 21:03:53 +00:00
super(entitytypes, world);
2019-04-23 04:47:07 +00:00
this.f = 5;
2018-01-14 22:02:38 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
2019-12-11 00:56:03 +00:00
index cf9612d17..755d34e61 100644
2018-01-14 22:02:38 +00:00
--- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
2019-07-20 04:01:24 +00:00
@@ -4,6 +4,7 @@ import com.mojang.datafixers.DataFixUtils;
2019-04-23 04:47:07 +00:00
import java.util.Collections;
import java.util.Optional;
import java.util.Set; // Paper
+import java.util.Map; // Paper
2018-07-15 01:53:17 +00:00
import java.util.UUID;
import java.util.function.Function;
2019-04-23 04:47:07 +00:00
import java.util.stream.Stream;
2019-12-11 00:56:03 +00:00
@@ -290,8 +291,8 @@ public class EntityTypes<T extends Entity> {
return this.bj.height;
2019-05-06 00:57:14 +00:00
}
- @Nullable
- public T a(World world) {
+ public T create(World world) { return this.a(world); } // Paper - OBFHELPER
+ @Nullable public T a(World world) { // Paper - OBFHELPER
2019-12-11 00:56:03 +00:00
return this.ba.create(this, world);
2019-05-06 00:57:14 +00:00
}
2019-05-10 17:42:33 +00:00
diff --git a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
2019-12-11 00:56:03 +00:00
index b098d86e3..721021791 100644
2019-05-10 17:42:33 +00:00
--- a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
+++ b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
2019-07-20 04:01:24 +00:00
@@ -68,6 +68,15 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
2019-05-10 17:42:33 +00:00
}
+ // Paper start
+ public void scheduleOnMain(Runnable r0) {
+ // postToMainThread does not work the same as older versions of mc
+ // This method is actually used to create a TickTask, which can then be posted onto main
+ this.addTask(this.postToMainThread(r0));
+ }
+ // Paper end
+
+ public void addTask(R r0) { a(r0); }; // Paper - OBFHELPER
public void a(R r0) {
this.d.add(r0);
LockSupport.unpark(this.getThread());
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/IBlockAccess.java b/src/main/java/net/minecraft/server/IBlockAccess.java
2019-12-11 00:56:03 +00:00
index 3b0877080..0dff02352 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/IBlockAccess.java
+++ b/src/main/java/net/minecraft/server/IBlockAccess.java
@@ -9,10 +9,24 @@ public interface IBlockAccess {
@Nullable
TileEntity getTileEntity(BlockPosition blockposition);
+ IBlockData getTypeIfLoaded(BlockPosition blockposition); // Paper - if loaded util
IBlockData getType(BlockPosition blockposition);
+ Fluid getFluidIfLoaded(BlockPosition blockposition); // Paper - if loaded util
Fluid getFluid(BlockPosition blockposition);
+ // Paper start - if loaded util
+ default Material getMaterialIfLoaded(BlockPosition blockposition) {
+ IBlockData type = this.getTypeIfLoaded(blockposition);
+ return type == null ? null : type.getMaterial();
+ }
+
+ default Block getBlockIfLoaded(BlockPosition blockposition) {
+ IBlockData type = this.getTypeIfLoaded(blockposition);
+ return type == null ? null : type.getBlock();
+ }
+ // Paper end
+
default int h(BlockPosition blockposition) {
return this.getType(blockposition).h();
}
2019-12-12 20:58:07 +00:00
diff --git a/src/main/java/net/minecraft/server/IOWorker.java b/src/main/java/net/minecraft/server/IOWorker.java
index c5658c077..b90baef0f 100644
--- a/src/main/java/net/minecraft/server/IOWorker.java
+++ b/src/main/java/net/minecraft/server/IOWorker.java
@@ -22,7 +22,7 @@ public class IOWorker implements AutoCloseable {
private final Thread b;
private final AtomicBoolean c = new AtomicBoolean();
private final Queue<Runnable> d = Queues.newConcurrentLinkedQueue();
- private final RegionFileCache e;
+ private final RegionFileCache e; public RegionFileCache getRegionFileCache() { return e; } // Paper - OBFHELPER
private final Map<ChunkCoordIntPair, IOWorker.a> f = Maps.newLinkedHashMap();
private boolean g = true;
private CompletableFuture<Void> h = new CompletableFuture();
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/IWorldReader.java b/src/main/java/net/minecraft/server/IWorldReader.java
2019-12-11 00:56:03 +00:00
index ba315131e..cbe2aa4c0 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/IWorldReader.java
+++ b/src/main/java/net/minecraft/server/IWorldReader.java
2019-12-11 00:56:03 +00:00
@@ -4,6 +4,7 @@ import javax.annotation.Nullable;
2019-05-27 06:14:14 +00:00
2019-12-11 00:56:03 +00:00
public interface IWorldReader extends IBlockLightAccess, ICollisionAccess, BiomeManager.Provider {
2019-05-27 06:14:14 +00:00
+ @Nullable IChunkAccess getChunkIfLoadedImmediately(int x, int z); // Paper - ifLoaded api (we need this since current impl blocks if the chunk is loading)
@Nullable
IChunkAccess getChunkAt(int i, int j, ChunkStatus chunkstatus, boolean flag);
2018-06-29 04:55:29 +00:00
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
2019-12-17 22:39:07 +00:00
index b5d45b43c..766b1fe13 100644
2018-06-29 04:55:29 +00:00
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
2019-04-23 04:47:07 +00:00
@@ -37,10 +37,19 @@ import org.bukkit.event.world.StructureGrowEvent;
2019-03-28 04:58:05 +00:00
public final class ItemStack {
2019-04-25 06:53:51 +00:00
private static final Logger LOGGER = LogManager.getLogger();
2019-03-28 04:58:05 +00:00
- public static final ItemStack a = new ItemStack((Item) null);
+ public static final ItemStack a = new ItemStack((Item) null);public static final ItemStack NULL_ITEM = a; // Paper - OBFHELPER
2019-12-11 00:56:03 +00:00
public static final DecimalFormat b = H();
2019-03-28 04:58:05 +00:00
private int count;
private int e;
+ // Paper start
+ private org.bukkit.craftbukkit.inventory.CraftItemStack bukkitStack;
+ public org.bukkit.inventory.ItemStack getBukkitStack() {
+ if (bukkitStack == null || bukkitStack.getHandle() != this) {
+ bukkitStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this);
+ }
+ return bukkitStack;
+ }
+ // Paper end
@Deprecated
private Item item;
private NBTTagCompound tag;
2019-12-11 00:56:03 +00:00
@@ -593,6 +602,17 @@ public final class ItemStack {
2018-07-15 01:53:17 +00:00
return this.tag != null ? this.tag.getList("Enchantments", 10) : new NBTTagList();
2018-06-29 04:55:29 +00:00
}
+ // Paper start - (this is just a good no conflict location)
+ public org.bukkit.inventory.ItemStack asBukkitMirror() {
+ return CraftItemStack.asCraftMirror(this);
+ }
+ public org.bukkit.inventory.ItemStack asBukkitCopy() {
+ return CraftItemStack.asCraftMirror(this.cloneItemStack());
+ }
+ public static ItemStack fromBukkitCopy(org.bukkit.inventory.ItemStack itemstack) {
+ return CraftItemStack.asNMSCopy(itemstack);
+ }
+ // Paper end
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
this.tag = nbttagcompound;
2019-12-17 22:39:07 +00:00
if (this.getItem().usesDurability()) {
@@ -685,6 +705,7 @@ public final class ItemStack {
2019-01-06 17:48:24 +00:00
return this.tag != null && this.tag.hasKeyOfType("Enchantments", 9) ? !this.tag.getList("Enchantments", 10).isEmpty() : false;
}
+ public void getOrCreateTagAndSet(String s, NBTBase nbtbase) { a(s, nbtbase);} // Paper - OBFHELPER
public void a(String s, NBTBase nbtbase) {
this.getOrCreateTag().set(s, nbtbase);
}
2019-12-17 22:39:07 +00:00
@@ -761,6 +782,7 @@ public final class ItemStack {
2019-03-28 04:58:05 +00:00
// CraftBukkit start
@Deprecated
public void setItem(Item item) {
+ this.bukkitStack = null; // Paper
this.item = item;
}
// CraftBukkit end
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
2019-12-12 18:45:00 +00:00
index 000000000..628b73a12
2016-03-29 01:01:42 +00:00
--- /dev/null
+++ b/src/main/java/net/minecraft/server/MCUtil.java
2018-10-05 03:18:46 +00:00
@@ -0,0 +1,316 @@
2016-03-29 01:01:42 +00:00
+package net.minecraft.server;
+
2018-09-03 23:59:54 +00:00
+import com.destroystokyo.paper.block.TargetBlockInfo;
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;
2018-09-03 23:59:54 +00:00
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.CraftWorld;
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
+
2018-09-03 23:59:54 +00:00
+import javax.annotation.Nonnull;
2016-05-13 05:34:37 +00:00
+import javax.annotation.Nullable;
2018-07-22 04:45:49 +00:00
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
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;
2018-07-22 04:45:49 +00:00
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
2016-05-28 02:28:23 +00:00
+import java.util.function.Supplier;
2016-03-29 01:01:42 +00:00
+
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() {}
+
+
2018-07-22 04:45:49 +00:00
+ public static boolean isMainThread() {
+ return MinecraftServer.getServer().isMainThread();
+ }
+
2018-07-22 23:39:56 +00:00
+ private static class DelayedRunnable implements Runnable {
+
+ private final int ticks;
+ private final Runnable run;
+
+ private DelayedRunnable(int ticks, Runnable run) {
+ this.ticks = ticks;
+ this.run = run;
+ }
+
+ @Override
+ public void run() {
+ if (ticks <= 0) {
+ run.run();
+ } else {
+ scheduleTask(ticks-1, run);
+ }
+ }
+ }
+
+ public static void scheduleTask(int ticks, Runnable runnable) {
+ // We use post to main instead of process queue as we don't want to process these mid tick if
+ // Someone uses processQueueWhileWaiting
2019-05-10 17:42:33 +00:00
+ MinecraftServer.getServer().scheduleOnMain(new DelayedRunnable(ticks, runnable));
2018-07-22 23:39:56 +00:00
+ }
+
2018-07-22 04:45:49 +00:00
+ public static void processQueue() {
+ Runnable runnable;
+ Queue<Runnable> processQueue = getProcessQueue();
+ while ((runnable = processQueue.poll()) != null) {
+ try {
+ runnable.run();
+ } catch (Exception e) {
+ MinecraftServer.LOGGER.error("Error executing task", e);
+ }
+ }
+ }
+ public static <T> T processQueueWhileWaiting(CompletableFuture <T> future) {
+ try {
+ if (isMainThread()) {
+ while (!future.isDone()) {
+ try {
+ return future.get(1, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException ignored) {
+ processQueue();
+ }
+ }
+ }
+ return future.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void ensureMain(Runnable run) {
+ ensureMain(null, run);
+ }
+ /**
+ * Ensures the target code is running on the main thread
+ * @param reason
+ * @param run
+ * @return
+ */
+ public static void ensureMain(String reason, Runnable run) {
2019-05-05 23:24:37 +00:00
+ if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread) {
2018-07-22 04:45:49 +00:00
+ if (reason != null) {
+ new IllegalStateException("Asynchronous " + reason + "!").printStackTrace();
+ }
+ getProcessQueue().add(run);
+ return;
+ }
+ run.run();
+ }
+
+ private static Queue<Runnable> getProcessQueue() {
+ return MinecraftServer.getServer().processQueue;
+ }
+
+ public static <T> T ensureMain(Supplier<T> run) {
+ return ensureMain(null, run);
+ }
2016-03-29 01:01:42 +00:00
+ /**
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) {
2019-05-05 23:24:37 +00:00
+ if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread) {
2018-07-22 04:45:49 +00:00
+ if (reason != null) {
+ new IllegalStateException("Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace();
+ }
2016-05-28 02:28:23 +00:00
+ Waitable<T> wait = new Waitable<T>() {
+ @Override
+ protected T evaluate() {
+ return run.get();
+ }
+ };
2018-07-22 04:45:49 +00:00
+ getProcessQueue().add(wait);
2016-05-28 02:28:23 +00:00
+ 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) {
2019-12-12 18:45:00 +00:00
+ return distanceSq(e1.locX(),e1.locY(),e1.locZ(), e2.locX(),e2.locY(),e2.locZ());
2016-03-29 01:01:42 +00:00
+ }
+
+ /**
+ * 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
2018-01-14 22:02:38 +00:00
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ public static Location toLocation(World world, double x, double y, double z) {
+ return new Location(world.getWorld(), x, y, z);
+ }
+
+ /**
+ * Converts a NMS World/BlockPosition to Bukkit Location
+ * @param world
2016-03-29 01:01:42 +00:00
+ * @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) {
2019-12-12 18:45:00 +00:00
+ return new Location(entity.getWorld().getWorld(), entity.locX(), entity.locY(), entity.locZ());
2016-03-29 01:01:42 +00:00
+ }
2016-03-31 23:29:06 +00:00
+
2018-08-26 18:11:49 +00:00
+ public static org.bukkit.block.Block toBukkitBlock(World world, BlockPosition pos) {
+ return world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ }
+
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
+
+ /**
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);
2019-05-05 23:24:37 +00:00
+ if (chunk != null && chunk.getType(new BlockPosition(pos.getX(), pos.getY(), pos.getZ())).getBlock() == Blocks.HOPPER) {
2016-06-18 06:03:40 +00:00
+ TileEntity tileEntity = chunk.getTileEntityImmediately(pos);
+ if (tileEntity instanceof TileEntityHopper) {
+ return (TileEntityHopper) tileEntity;
+ }
+ }
+ return null;
+ }
2018-09-03 23:59:54 +00:00
+
+ @Nonnull
+ public static World getNMSWorld(@Nonnull org.bukkit.World world) {
+ return ((CraftWorld) world).getHandle();
+ }
+
+ public static World getNMSWorld(@Nonnull org.bukkit.entity.Entity entity) {
+ return getNMSWorld(entity.getWorld());
+ }
+
2019-05-05 23:24:37 +00:00
+ public static RayTrace.FluidCollisionOption getNMSFluidCollisionOption(TargetBlockInfo.FluidMode fluidMode) {
2018-09-03 23:59:54 +00:00
+ if (fluidMode == TargetBlockInfo.FluidMode.NEVER) {
2019-05-05 23:24:37 +00:00
+ return RayTrace.FluidCollisionOption.NONE;
2018-09-03 23:59:54 +00:00
+ }
+ if (fluidMode == TargetBlockInfo.FluidMode.SOURCE_ONLY) {
2019-05-05 23:24:37 +00:00
+ return RayTrace.FluidCollisionOption.SOURCE_ONLY;
2018-09-03 23:59:54 +00:00
+ }
+ if (fluidMode == TargetBlockInfo.FluidMode.ALWAYS) {
2019-05-05 23:24:37 +00:00
+ return RayTrace.FluidCollisionOption.ANY;
2018-09-03 23:59:54 +00:00
+ }
+ return null;
+ }
+
+ public static BlockFace toBukkitBlockFace(EnumDirection enumDirection) {
+ switch (enumDirection) {
+ case DOWN:
+ return BlockFace.DOWN;
+ case UP:
+ return BlockFace.UP;
+ case NORTH:
+ return BlockFace.NORTH;
+ case SOUTH:
+ return BlockFace.SOUTH;
+ case WEST:
+ return BlockFace.WEST;
+ case EAST:
+ return BlockFace.EAST;
+ default:
+ 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
2019-12-11 00:56:03 +00:00
index e85b24a32..75604dbc6 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
2019-12-11 00:56:03 +00:00
@@ -60,7 +60,7 @@ public class NBTTagCompound implements NBTBase {
return "TAG_Compound";
}
};
- private final Map<String, NBTBase> map;
+ public final Map<String, NBTBase> map; // Paper
2019-01-01 03:15:55 +00:00
2019-12-11 00:56:03 +00:00
private NBTTagCompound(Map<String, NBTBase> map) {
this.map = map;
@@ -123,11 +123,15 @@ public class NBTTagCompound implements NBTBase {
this.map.put(s, NBTTagLong.a(i));
2016-05-02 03:54:08 +00:00
}
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());
}
2019-04-23 04:47:07 +00:00
+
+ @Nullable public UUID getUUID(String prefix) { return a(prefix); } // Paper - OBFHELPER
+ @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"));
2019-04-23 04:47:07 +00:00
}
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
2019-12-11 00:56:03 +00:00
index 6700582e3..3ccf16636 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
2019-07-20 04:01:24 +00:00
@@ -159,6 +159,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
2018-08-26 02:37:58 +00:00
}
+ private void dispatchPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericFutureListener) { this.b(packet, genericFutureListener); } // Paper - OBFHELPER
private void b(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
EnumProtocol enumprotocol = EnumProtocol.a(packet);
EnumProtocol enumprotocol1 = (EnumProtocol) this.channel.attr(NetworkManager.c).get();
2019-07-20 04:01:24 +00:00
@@ -199,6 +200,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
2018-08-26 02:37:58 +00:00
}
+ private void sendPacketQueue() { this.o(); } // Paper - OBFHELPER
private void o() {
if (this.channel != null && this.channel.isOpen()) {
2019-07-20 04:01:24 +00:00
Queue queue = this.packetQueue;
@@ -327,9 +329,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
2018-08-26 02:37:58 +00:00
static class QueuedPacket {
- private final Packet<?> a;
+ private final Packet<?> a; private final Packet<?> getPacket() { return this.a; } // Paper - OBFHELPER
@Nullable
- private final GenericFutureListener<? extends Future<? super Void>> b;
+ private final GenericFutureListener<? extends Future<? super Void>> b; private final GenericFutureListener<? extends Future<? super Void>> getGenericFutureListener() { return this.b; } // Paper - OBFHELPER
public QueuedPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
this.a = packet;
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
2019-12-11 00:56:03 +00:00
index 81b6f4581..d9574a9ac 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -33,6 +33,7 @@ public class PacketDataSerializer extends ByteBuf {
this.a = bytebuf;
}
+ public static int countBytes(int i) { return PacketDataSerializer.a(i); } // Paper - OBFHELPER
public static int a(int i) {
for (int j = 1; j < 5; ++j) {
if ((i & -1 << j * 7) == 0) {
2018-10-03 02:53:27 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketEncoder.java b/src/main/java/net/minecraft/server/PacketEncoder.java
2019-12-11 00:56:03 +00:00
index 90223deae..63c4dbd32 100644
2018-10-03 02:53:27 +00:00
--- a/src/main/java/net/minecraft/server/PacketEncoder.java
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
2019-01-01 03:15:55 +00:00
@@ -42,6 +42,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
2018-10-03 02:53:27 +00:00
packet.b(packetdataserializer);
} catch (Throwable throwable) {
2019-04-25 06:53:51 +00:00
PacketEncoder.LOGGER.error(throwable);
2018-10-03 02:53:27 +00:00
+ throwable.printStackTrace(); // Paper - WHAT WAS IT? WHO DID THIS TO YOU? WHAT DID YOU SEE?
if (packet.a()) {
throw new SkipEncodeException(throwable);
} else {
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
2019-12-11 00:56:03 +00:00
index 677e3e5f6..3a1d0deb0 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
2019-12-11 00:56:03 +00:00
@@ -17,7 +17,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
2019-04-23 04:47:07 +00:00
private NBTTagCompound d;
2019-12-11 00:56:03 +00:00
@Nullable
private BiomeStorage e;
- private byte[] f;
+ private byte[] f; private byte[] getData() { return this.f; } // Paper - OBFHELPER
private List<NBTTagCompound> g;
private boolean h;
2018-08-26 02:37:58 +00:00
2019-12-11 00:56:03 +00:00
@@ -129,6 +129,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
2018-08-26 02:37:58 +00:00
return bytebuf;
}
2019-04-23 04:47:07 +00:00
+ public int writeChunk(PacketDataSerializer packetDataSerializer, Chunk chunk, int chunkSectionSelector) { return this.a(packetDataSerializer, chunk, chunkSectionSelector); } // Paper - OBFHELPER
public int a(PacketDataSerializer packetdataserializer, Chunk chunk, int i) {
2018-08-26 02:37:58 +00:00
int j = 0;
ChunkSection[] achunksection = chunk.getSections();
2019-06-14 02:27:40 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
2019-12-11 00:56:03 +00:00
index 775359146..3c6fe0596 100644
2019-06-14 02:27:40 +00:00
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -63,6 +63,14 @@ public class PlayerChunk {
return either == null ? null : (Chunk) either.left().orElse(null);
}
// CraftBukkit end
+ // Paper start - "real" get full chunk immediately
+ public Chunk getFullChunkIfCached() {
+ // Note: Copied from above without ticket level check
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> statusFuture = this.getStatusFutureUnchecked(ChunkStatus.FULL);
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either<IChunkAccess, PlayerChunk.Failure>) statusFuture.getNow(null);
+ return either == null ? null : (Chunk) either.left().orElse(null);
+ }
+ // Paper end
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.statusFutures.get(chunkstatus.c());
2017-10-15 13:00:42 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2019-12-11 00:56:03 +00:00
index ba0293512..b257e1c4e 100644
2017-10-15 13:00:42 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2019-05-06 02:58:04 +00:00
@@ -67,9 +67,9 @@ public class PlayerConnection implements PacketListenerPlayIn {
2017-10-15 13:00:42 +00:00
private final MinecraftServer minecraftServer;
public EntityPlayer player;
private int e;
2018-12-17 05:18:06 +00:00
- private long lastKeepAlive;
- private boolean awaitingKeepAlive;
2017-10-15 13:00:42 +00:00
- private long h;
2018-12-17 05:18:06 +00:00
+ private long lastKeepAlive; private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
+ private boolean awaitingKeepAlive; private void setPendingPing(boolean isPending) { this.awaitingKeepAlive = isPending;}; private boolean isPendingPing() { return this.awaitingKeepAlive;}; // Paper - OBFHELPER
2017-10-15 13:00:42 +00:00
+ private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER
// CraftBukkit start - multithreaded fields
private volatile int chatThrottle;
private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle");
2019-03-28 04:58:05 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerInventory.java b/src/main/java/net/minecraft/server/PlayerInventory.java
2019-12-11 00:56:03 +00:00
index c2b2237c8..d117578f2 100644
2019-03-28 04:58:05 +00:00
--- a/src/main/java/net/minecraft/server/PlayerInventory.java
+++ b/src/main/java/net/minecraft/server/PlayerInventory.java
2019-04-23 04:47:07 +00:00
@@ -17,7 +17,7 @@ public class PlayerInventory implements IInventory, INamableTileEntity {
2019-03-28 04:58:05 +00:00
public final NonNullList<ItemStack> items;
public final NonNullList<ItemStack> armor;
public final NonNullList<ItemStack> extraSlots;
- private final List<NonNullList<ItemStack>> f;
+ private final List<NonNullList<ItemStack>> f;List<NonNullList<ItemStack>> getComponents() { return f; } // Paper - OBFHELPER
public int itemInHandIndex;
2019-04-23 04:47:07 +00:00
public final EntityHuman player;
2019-03-28 04:58:05 +00:00
private ItemStack carried;
2018-10-19 03:24:09 +00:00
diff --git a/src/main/java/net/minecraft/server/PotionUtil.java b/src/main/java/net/minecraft/server/PotionUtil.java
2019-12-11 00:56:03 +00:00
index b3824898d..bf4172be5 100644
2018-10-19 03:24:09 +00:00
--- a/src/main/java/net/minecraft/server/PotionUtil.java
+++ b/src/main/java/net/minecraft/server/PotionUtil.java
2019-01-01 03:15:55 +00:00
@@ -110,6 +110,7 @@ public class PotionUtil {
2018-10-19 03:24:09 +00:00
return nbttagcompound == null ? Potions.EMPTY : PotionRegistry.a(nbttagcompound.getString("Potion"));
}
+ public static ItemStack addPotionToItemStack(ItemStack itemstack, PotionRegistry potionregistry) { return a(itemstack, potionregistry); } // Paper - OBFHELPER
public static ItemStack a(ItemStack itemstack, PotionRegistry potionregistry) {
MinecraftKey minecraftkey = IRegistry.POTION.getKey(potionregistry);
2019-01-01 03:15:55 +00:00
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/ProtoChunk.java b/src/main/java/net/minecraft/server/ProtoChunk.java
2019-12-11 00:56:03 +00:00
index 6e65306a2..39339fa27 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/ProtoChunk.java
+++ b/src/main/java/net/minecraft/server/ProtoChunk.java
2019-12-11 00:56:03 +00:00
@@ -80,6 +80,18 @@ public class ProtoChunk implements IChunkAccess {
2019-05-27 06:14:14 +00:00
}
+ // Paper start - If loaded util
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ return this.getFluid(blockposition);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ return this.getType(blockposition);
+ }
+ // Paper end
+
@Override
public IBlockData getType(BlockPosition blockposition) {
int i = blockposition.getY();
2019-12-13 16:29:51 +00:00
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
2019-12-17 22:39:07 +00:00
index 7b6e0e86b..187c4e0f5 100644
2019-12-13 16:29:51 +00:00
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -88,6 +88,7 @@ public class RegionFile implements AutoCloseable {
return this.d.resolve(s);
}
+ @Nullable public synchronized DataInputStream getReadStream(ChunkCoordIntPair chunkCoordIntPair) throws IOException { return a(chunkCoordIntPair);} // Paper - OBFHELPER
@Nullable
public synchronized DataInputStream a(ChunkCoordIntPair chunkcoordintpair) throws IOException {
int i = this.getOffset(chunkcoordintpair);
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/net/minecraft/server/RegionLimitedWorldAccess.java b/src/main/java/net/minecraft/server/RegionLimitedWorldAccess.java
2019-12-11 00:56:03 +00:00
index 8c123f265..9d0e8c2d4 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/net/minecraft/server/RegionLimitedWorldAccess.java
+++ b/src/main/java/net/minecraft/server/RegionLimitedWorldAccess.java
2019-12-11 00:56:03 +00:00
@@ -108,6 +108,26 @@ public class RegionLimitedWorldAccess implements GeneratorAccess {
2019-05-27 06:14:14 +00:00
return i >= ichunkaccess.getPos().x && i <= ichunkaccess1.getPos().x && j >= ichunkaccess.getPos().z && j <= ichunkaccess1.getPos().z;
}
+ // Paper start - if loaded util
+ @Nullable
+ @Override
+ public IChunkAccess getChunkIfLoadedImmediately(int x, int z) {
+ return this.getChunkAt(x, z, ChunkStatus.FULL, false);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ IChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ return chunk == null ? null : chunk.getType(blockposition);
+ }
+
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ IChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ return chunk == null ? null : chunk.getFluid(blockposition);
+ }
+ // Paper end
+
@Override
public IBlockData getType(BlockPosition blockposition) {
return this.getChunkAt(blockposition.getX() >> 4, blockposition.getZ() >> 4).getType(blockposition);
2018-07-19 04:42:43 +00:00
diff --git a/src/main/java/net/minecraft/server/RegistryBlockID.java b/src/main/java/net/minecraft/server/RegistryBlockID.java
2019-12-11 00:56:03 +00:00
index 4efcb8b59..60948afa4 100644
2018-07-19 04:42:43 +00:00
--- a/src/main/java/net/minecraft/server/RegistryBlockID.java
+++ b/src/main/java/net/minecraft/server/RegistryBlockID.java
2019-04-23 04:47:07 +00:00
@@ -57,6 +57,7 @@ public class RegistryBlockID<T> implements Registry<T> {
2018-08-26 02:37:58 +00:00
return Iterators.filter(this.c.iterator(), Predicates.notNull());
}
+ public int size() { return this.a(); } // Paper - OBFHELPER
public int a() {
return this.b.size();
}
2018-10-04 05:45:11 +00:00
diff --git a/src/main/java/net/minecraft/server/SystemUtils.java b/src/main/java/net/minecraft/server/SystemUtils.java
2019-12-11 00:56:03 +00:00
index 7b92ecfff..7e224ebef 100644
2018-10-04 05:45:11 +00:00
--- a/src/main/java/net/minecraft/server/SystemUtils.java
+++ b/src/main/java/net/minecraft/server/SystemUtils.java
2019-05-05 21:39:51 +00:00
@@ -58,7 +58,7 @@ public class SystemUtils {
2018-10-04 05:45:11 +00:00
}
2018-12-17 05:18:06 +00:00
public static long getMonotonicNanos() {
2019-01-01 03:15:55 +00:00
- return SystemUtils.a.getAsLong();
2018-10-04 05:45:11 +00:00
+ return System.nanoTime(); // Paper
}
2018-12-17 05:18:06 +00:00
public static long getTimeMillis() {
2019-05-06 19:30:27 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2019-12-17 22:39:07 +00:00
index 5c3226dd7..3122a02ab 100644
2019-05-06 19:30:27 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-12-11 00:56:03 +00:00
@@ -196,6 +196,40 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-05-27 06:14:14 +00:00
return (Chunk) this.getChunkAt(i, j, ChunkStatus.FULL);
}
+ // Paper start - if loaded
+ @Nullable
+ @Override
+ public IChunkAccess getChunkIfLoadedImmediately(int x, int z) {
2019-06-11 00:29:30 +00:00
+ return ((ChunkProviderServer)this.chunkProvider).getChunkAtIfLoadedImmediately(x, z);
2019-05-27 06:14:14 +00:00
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
+ for (CraftBlockState previous : capturedBlockStates) {
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) {
+ return previous.getHandle();
+ }
+ }
+ }
+ // CraftBukkit end
+ if (!isValidLocation(blockposition)) {
+ return Blocks.AIR.getBlockData();
+ }
+ IChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+
+ return chunk == null ? null : chunk.getType(blockposition);
+ }
+
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ IChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+
+ return chunk == null ? null : chunk.getFluid(blockposition);
+ }
+ // Paper end
+
@Override
public IChunkAccess getChunkAt(int i, int j, ChunkStatus chunkstatus, boolean flag) {
IChunkAccess ichunkaccess = this.chunkProvider.getChunkAt(i, j, chunkstatus, flag);
2019-12-11 00:56:03 +00:00
@@ -357,8 +391,9 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-05-06 19:30:27 +00:00
public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
- @Override
- public boolean a(BlockPosition blockposition, boolean flag) {
+ public boolean setAir(BlockPosition blockposition) { return this.a(blockposition, false); } // Paper - OBFHELPER
+ public boolean setAir(BlockPosition blockposition, boolean moved) { return this.a(blockposition, moved); } // Paper - OBFHELPER
+ @Override public boolean a(BlockPosition blockposition, boolean flag) { // Paper - OBFHELPER
Fluid fluid = this.getFluid(blockposition);
return this.setTypeAndData(blockposition, fluid.getBlockData(), 3 | (flag ? 64 : 0));
2019-03-28 04:58:05 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
2019-12-13 16:29:51 +00:00
index e181df6f4..4a9132c70 100644
2019-03-28 04:58:05 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
2019-04-24 01:00:24 +00:00
@@ -85,6 +85,7 @@ public final class CraftItemStack extends ItemStack {
2019-03-28 04:58:05 +00:00
}
net.minecraft.server.ItemStack handle;
+ public net.minecraft.server.ItemStack getHandle() { return handle; } // Paper
/**
* Mirror
2019-05-27 06:14:14 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
2019-12-11 00:56:03 +00:00
index d8358a0f0..d0b813008 100644
2019-05-27 06:14:14 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
2019-12-11 00:56:03 +00:00
@@ -196,4 +196,22 @@ public class DummyGeneratorAccess implements GeneratorAccess {
public boolean a(BlockPosition blockposition, boolean flag, Entity entity) {
2019-05-27 06:14:14 +00:00
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ // Paper start - if loaded util
+ @javax.annotation.Nullable
+ @Override
+ public IChunkAccess getChunkIfLoadedImmediately(int x, int z) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ // Paper end
}
2016-03-29 01:01:42 +00:00
--
2019-12-13 16:29:51 +00:00
2.24.1
2016-03-29 01:01:42 +00:00