Skip to content

Commit bb17101

Browse files
TechcableZach Brown
authored andcommitted
Speedup BlockPos by fixing inlining
1 parent 972d71a commit bb17101

File tree

2 files changed

+515
-2
lines changed

2 files changed

+515
-2
lines changed

Spigot-Server-Patches/0003-mc-dev-imports.patch

Lines changed: 359 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,100 @@
1-
From ce5da7df48c5505249c2b932b66d5b45558c01c8 Mon Sep 17 00:00:00 2001
1+
From ef451696bb6004f2d3467750038f2010f52a04b2 Mon Sep 17 00:00:00 2001
22
From: Zach Brown <zach.brown@destroystokyo.com>
33
Date: Mon, 25 May 2015 15:37:00 -0500
44
Subject: [PATCH] mc-dev imports
55

66

7+
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
8+
new file mode 100644
9+
index 0000000..0b2277c
10+
--- /dev/null
11+
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
12+
@@ -0,0 +1,85 @@
13+
+package net.minecraft.server;
14+
+
15+
+import com.google.common.base.Objects;
16+
+
17+
+public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
18+
+
19+
+ public static final BaseBlockPosition ZERO = new BaseBlockPosition(0, 0, 0);
20+
+ private final int a;
21+
+ private final int c;
22+
+ private final int d;
23+
+
24+
+ public BaseBlockPosition(int i, int j, int k) {
25+
+ this.a = i;
26+
+ this.c = j;
27+
+ this.d = k;
28+
+ }
29+
+
30+
+ public BaseBlockPosition(double d0, double d1, double d2) {
31+
+ this(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2));
32+
+ }
33+
+
34+
+ public boolean equals(Object object) {
35+
+ if (this == object) {
36+
+ return true;
37+
+ } else if (!(object instanceof BaseBlockPosition)) {
38+
+ return false;
39+
+ } else {
40+
+ BaseBlockPosition baseblockposition = (BaseBlockPosition) object;
41+
+
42+
+ return this.getX() != baseblockposition.getX() ? false : (this.getY() != baseblockposition.getY() ? false : this.getZ() == baseblockposition.getZ());
43+
+ }
44+
+ }
45+
+
46+
+ public int hashCode() {
47+
+ return (this.getY() + this.getZ() * 31) * 31 + this.getX();
48+
+ }
49+
+
50+
+ public int g(BaseBlockPosition baseblockposition) {
51+
+ return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
52+
+ }
53+
+
54+
+ public int getX() {
55+
+ return this.a;
56+
+ }
57+
+
58+
+ public int getY() {
59+
+ return this.c;
60+
+ }
61+
+
62+
+ public int getZ() {
63+
+ return this.d;
64+
+ }
65+
+
66+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
67+
+ return new BaseBlockPosition(this.getY() * baseblockposition.getZ() - this.getZ() * baseblockposition.getY(), this.getZ() * baseblockposition.getX() - this.getX() * baseblockposition.getZ(), this.getX() * baseblockposition.getY() - this.getY() * baseblockposition.getX());
68+
+ }
69+
+
70+
+ public double c(double d0, double d1, double d2) {
71+
+ double d3 = (double) this.getX() - d0;
72+
+ double d4 = (double) this.getY() - d1;
73+
+ double d5 = (double) this.getZ() - d2;
74+
+
75+
+ return d3 * d3 + d4 * d4 + d5 * d5;
76+
+ }
77+
+
78+
+ public double d(double d0, double d1, double d2) {
79+
+ double d3 = (double) this.getX() + 0.5D - d0;
80+
+ double d4 = (double) this.getY() + 0.5D - d1;
81+
+ double d5 = (double) this.getZ() + 0.5D - d2;
82+
+
83+
+ return d3 * d3 + d4 * d4 + d5 * d5;
84+
+ }
85+
+
86+
+ public double i(BaseBlockPosition baseblockposition) {
87+
+ return this.c((double) baseblockposition.getX(), (double) baseblockposition.getY(), (double) baseblockposition.getZ());
88+
+ }
89+
+
90+
+ public String toString() {
91+
+ return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
92+
+ }
93+
+
94+
+ public int compareTo(Object object) {
95+
+ return this.g((BaseBlockPosition) object);
96+
+ }
97+
+}
798
diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java
899
new file mode 100644
9100
index 0000000..b1ae67a
@@ -1529,6 +1620,272 @@ index 0000000..b610450
15291620
+ }
15301621
+ }
15311622
+}
1623+
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
1624+
new file mode 100644
1625+
index 0000000..2bd5499
1626+
--- /dev/null
1627+
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
1628+
@@ -0,0 +1,260 @@
1629+
+package net.minecraft.server;
1630+
+
1631+
+import com.google.common.collect.AbstractIterator;
1632+
+import java.util.Iterator;
1633+
+
1634+
+public class BlockPosition extends BaseBlockPosition {
1635+
+
1636+
+ public static final BlockPosition ZERO = new BlockPosition(0, 0, 0);
1637+
+ private static final int c = 1 + MathHelper.c(MathHelper.b(30000000));
1638+
+ private static final int d = BlockPosition.c;
1639+
+ private static final int e = 64 - BlockPosition.c - BlockPosition.d;
1640+
+ private static final int f = 0 + BlockPosition.d;
1641+
+ private static final int g = BlockPosition.f + BlockPosition.e;
1642+
+ private static final long h = (1L << BlockPosition.c) - 1L;
1643+
+ private static final long i = (1L << BlockPosition.e) - 1L;
1644+
+ private static final long j = (1L << BlockPosition.d) - 1L;
1645+
+
1646+
+ public BlockPosition(int i, int j, int k) {
1647+
+ super(i, j, k);
1648+
+ }
1649+
+
1650+
+ public BlockPosition(double d0, double d1, double d2) {
1651+
+ super(d0, d1, d2);
1652+
+ }
1653+
+
1654+
+ public BlockPosition(Entity entity) {
1655+
+ this(entity.locX, entity.locY, entity.locZ);
1656+
+ }
1657+
+
1658+
+ public BlockPosition(Vec3D vec3d) {
1659+
+ this(vec3d.a, vec3d.b, vec3d.c);
1660+
+ }
1661+
+
1662+
+ public BlockPosition(BaseBlockPosition baseblockposition) {
1663+
+ this(baseblockposition.getX(), baseblockposition.getY(), baseblockposition.getZ());
1664+
+ }
1665+
+
1666+
+ public BlockPosition a(double d0, double d1, double d2) {
1667+
+ 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);
1668+
+ }
1669+
+
1670+
+ public BlockPosition a(int i, int j, int k) {
1671+
+ return i == 0 && j == 0 && k == 0 ? this : new BlockPosition(this.getX() + i, this.getY() + j, this.getZ() + k);
1672+
+ }
1673+
+
1674+
+ public BlockPosition a(BaseBlockPosition baseblockposition) {
1675+
+ return baseblockposition.getX() == 0 && baseblockposition.getY() == 0 && baseblockposition.getZ() == 0 ? this : new BlockPosition(this.getX() + baseblockposition.getX(), this.getY() + baseblockposition.getY(), this.getZ() + baseblockposition.getZ());
1676+
+ }
1677+
+
1678+
+ public BlockPosition b(BaseBlockPosition baseblockposition) {
1679+
+ return baseblockposition.getX() == 0 && baseblockposition.getY() == 0 && baseblockposition.getZ() == 0 ? this : new BlockPosition(this.getX() - baseblockposition.getX(), this.getY() - baseblockposition.getY(), this.getZ() - baseblockposition.getZ());
1680+
+ }
1681+
+
1682+
+ public BlockPosition up() {
1683+
+ return this.up(1);
1684+
+ }
1685+
+
1686+
+ public BlockPosition up(int i) {
1687+
+ return this.shift(EnumDirection.UP, i);
1688+
+ }
1689+
+
1690+
+ public BlockPosition down() {
1691+
+ return this.down(1);
1692+
+ }
1693+
+
1694+
+ public BlockPosition down(int i) {
1695+
+ return this.shift(EnumDirection.DOWN, i);
1696+
+ }
1697+
+
1698+
+ public BlockPosition north() {
1699+
+ return this.north(1);
1700+
+ }
1701+
+
1702+
+ public BlockPosition north(int i) {
1703+
+ return this.shift(EnumDirection.NORTH, i);
1704+
+ }
1705+
+
1706+
+ public BlockPosition south() {
1707+
+ return this.south(1);
1708+
+ }
1709+
+
1710+
+ public BlockPosition south(int i) {
1711+
+ return this.shift(EnumDirection.SOUTH, i);
1712+
+ }
1713+
+
1714+
+ public BlockPosition west() {
1715+
+ return this.west(1);
1716+
+ }
1717+
+
1718+
+ public BlockPosition west(int i) {
1719+
+ return this.shift(EnumDirection.WEST, i);
1720+
+ }
1721+
+
1722+
+ public BlockPosition east() {
1723+
+ return this.east(1);
1724+
+ }
1725+
+
1726+
+ public BlockPosition east(int i) {
1727+
+ return this.shift(EnumDirection.EAST, i);
1728+
+ }
1729+
+
1730+
+ public BlockPosition shift(EnumDirection enumdirection) {
1731+
+ return this.shift(enumdirection, 1);
1732+
+ }
1733+
+
1734+
+ public BlockPosition shift(EnumDirection enumdirection, int i) {
1735+
+ return i == 0 ? this : new BlockPosition(this.getX() + enumdirection.getAdjacentX() * i, this.getY() + enumdirection.getAdjacentY() * i, this.getZ() + enumdirection.getAdjacentZ() * i);
1736+
+ }
1737+
+
1738+
+ public BlockPosition c(BaseBlockPosition baseblockposition) {
1739+
+ 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());
1740+
+ }
1741+
+
1742+
+ public long asLong() {
1743+
+ return ((long) this.getX() & BlockPosition.h) << BlockPosition.g | ((long) this.getY() & BlockPosition.i) << BlockPosition.f | ((long) this.getZ() & BlockPosition.j) << 0;
1744+
+ }
1745+
+
1746+
+ public static BlockPosition fromLong(long i) {
1747+
+ int j = (int) (i << 64 - BlockPosition.g - BlockPosition.c >> 64 - BlockPosition.c);
1748+
+ int k = (int) (i << 64 - BlockPosition.f - BlockPosition.e >> 64 - BlockPosition.e);
1749+
+ int l = (int) (i << 64 - BlockPosition.d >> 64 - BlockPosition.d);
1750+
+
1751+
+ return new BlockPosition(j, k, l);
1752+
+ }
1753+
+
1754+
+ public static Iterable<BlockPosition> a(BlockPosition blockposition, BlockPosition blockposition1) {
1755+
+ final BlockPosition blockposition2 = new BlockPosition(Math.min(blockposition.getX(), blockposition1.getX()), Math.min(blockposition.getY(), blockposition1.getY()), Math.min(blockposition.getZ(), blockposition1.getZ()));
1756+
+ final BlockPosition blockposition3 = new BlockPosition(Math.max(blockposition.getX(), blockposition1.getX()), Math.max(blockposition.getY(), blockposition1.getY()), Math.max(blockposition.getZ(), blockposition1.getZ()));
1757+
+
1758+
+ return new Iterable() {
1759+
+ public Iterator<BlockPosition> iterator() {
1760+
+ return new AbstractIterator() {
1761+
+ private BlockPosition b = null;
1762+
+
1763+
+ protected BlockPosition a() {
1764+
+ if (this.b == null) {
1765+
+ this.b = blockposition;
1766+
+ return this.b;
1767+
+ } else if (this.b.equals(blockposition1)) {
1768+
+ return (BlockPosition) this.endOfData();
1769+
+ } else {
1770+
+ int i = this.b.getX();
1771+
+ int j = this.b.getY();
1772+
+ int k = this.b.getZ();
1773+
+
1774+
+ if (i < blockposition1.getX()) {
1775+
+ ++i;
1776+
+ } else if (j < blockposition1.getY()) {
1777+
+ i = blockposition.getX();
1778+
+ ++j;
1779+
+ } else if (k < blockposition1.getZ()) {
1780+
+ i = blockposition.getX();
1781+
+ j = blockposition.getY();
1782+
+ ++k;
1783+
+ }
1784+
+
1785+
+ this.b = new BlockPosition(i, j, k);
1786+
+ return this.b;
1787+
+ }
1788+
+ }
1789+
+
1790+
+ protected Object computeNext() {
1791+
+ return this.a();
1792+
+ }
1793+
+ };
1794+
+ }
1795+
+ };
1796+
+ }
1797+
+
1798+
+ public static Iterable<BlockPosition.MutableBlockPosition> b(BlockPosition blockposition, BlockPosition blockposition1) {
1799+
+ final BlockPosition blockposition2 = new BlockPosition(Math.min(blockposition.getX(), blockposition1.getX()), Math.min(blockposition.getY(), blockposition1.getY()), Math.min(blockposition.getZ(), blockposition1.getZ()));
1800+
+ final BlockPosition blockposition3 = new BlockPosition(Math.max(blockposition.getX(), blockposition1.getX()), Math.max(blockposition.getY(), blockposition1.getY()), Math.max(blockposition.getZ(), blockposition1.getZ()));
1801+
+
1802+
+ return new Iterable() {
1803+
+ public Iterator<BlockPosition.MutableBlockPosition> iterator() {
1804+
+ return new AbstractIterator() {
1805+
+ private BlockPosition.MutableBlockPosition b = null;
1806+
+
1807+
+ protected BlockPosition.MutableBlockPosition a() {
1808+
+ if (this.b == null) {
1809+
+ this.b = new BlockPosition.MutableBlockPosition(blockposition.getX(), blockposition.getY(), blockposition.getZ());
1810+
+ return this.b;
1811+
+ } else if (this.b.equals(blockposition1)) {
1812+
+ return (BlockPosition.MutableBlockPosition) this.endOfData();
1813+
+ } else {
1814+
+ int i = this.b.getX();
1815+
+ int j = this.b.getY();
1816+
+ int k = this.b.getZ();
1817+
+
1818+
+ if (i < blockposition1.getX()) {
1819+
+ ++i;
1820+
+ } else if (j < blockposition1.getY()) {
1821+
+ i = blockposition.getX();
1822+
+ ++j;
1823+
+ } else if (k < blockposition1.getZ()) {
1824+
+ i = blockposition.getX();
1825+
+ j = blockposition.getY();
1826+
+ ++k;
1827+
+ }
1828+
+
1829+
+ this.b.c = i;
1830+
+ this.b.d = j;
1831+
+ this.b.e = k;
1832+
+ return this.b;
1833+
+ }
1834+
+ }
1835+
+
1836+
+ protected Object computeNext() {
1837+
+ return this.a();
1838+
+ }
1839+
+ };
1840+
+ }
1841+
+ };
1842+
+ }
1843+
+
1844+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
1845+
+ return this.c(baseblockposition);
1846+
+ }
1847+
+
1848+
+ public static final class MutableBlockPosition extends BlockPosition {
1849+
+
1850+
+ private int c;
1851+
+ private int d;
1852+
+ private int e;
1853+
+
1854+
+ public MutableBlockPosition() {
1855+
+ this(0, 0, 0);
1856+
+ }
1857+
+
1858+
+ public MutableBlockPosition(int i, int j, int k) {
1859+
+ super(0, 0, 0);
1860+
+ this.c = i;
1861+
+ this.d = j;
1862+
+ this.e = k;
1863+
+ }
1864+
+
1865+
+ public int getX() {
1866+
+ return this.c;
1867+
+ }
1868+
+
1869+
+ public int getY() {
1870+
+ return this.d;
1871+
+ }
1872+
+
1873+
+ public int getZ() {
1874+
+ return this.e;
1875+
+ }
1876+
+
1877+
+ public BlockPosition.MutableBlockPosition c(int i, int j, int k) {
1878+
+ this.c = i;
1879+
+ this.d = j;
1880+
+ this.e = k;
1881+
+ return this;
1882+
+ }
1883+
+
1884+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
1885+
+ return super.c(baseblockposition);
1886+
+ }
1887+
+ }
1888+
+}
15321889
diff --git a/src/main/java/net/minecraft/server/ChunkProviderFlat.java b/src/main/java/net/minecraft/server/ChunkProviderFlat.java
15331890
new file mode 100644
15341891
index 0000000..d1e10c6
@@ -2966,5 +3323,5 @@ index 0000000..f75e2de
29663323
+ }
29673324
+}
29683325
--
2969-
2.7.0.windows.1
3326+
2.7.0
29703327

0 commit comments

Comments
 (0)