Skip to content

Commit 8ad0cff

Browse files
committed
Updated bukkit/spigot build for minecraft 1.16.4
1 parent 87b57d5 commit 8ad0cff

File tree

7 files changed

+800
-46
lines changed

7 files changed

+800
-46
lines changed

bukkit-helper-116-4/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
/build/
3+
/bin/
4+
/.classpath

bukkit-helper-116-4/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
description = 'bukkit-helper-1.16.4'
3+
4+
dependencies {
5+
compile project(':bukkit-helper')
6+
compile project(':dynmap-api')
7+
compile project(path: ':DynmapCore', configuration: 'shadow')
8+
compile group: 'org.spigotmc', name: 'spigot-api', version:'1.16.4-R0.1-SNAPSHOT'
9+
compile group: 'org.spigotmc', name: 'spigot', version:'1.16.4-R0.1-SNAPSHOT'
10+
}
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
package org.dynmap.bukkit.helper.v116_4;
2+
3+
import net.minecraft.server.v1_16_R3.Material;
4+
import net.minecraft.server.v1_16_R3.*;
5+
import org.bukkit.World;
6+
import org.bukkit.WorldBorder;
7+
import org.bukkit.*;
8+
import org.bukkit.entity.Player;
9+
import org.dynmap.DynmapChunk;
10+
import org.dynmap.Log;
11+
import org.dynmap.bukkit.helper.BukkitMaterial;
12+
import org.dynmap.bukkit.helper.BukkitVersionHelperGeneric;
13+
import org.dynmap.bukkit.helper.BukkitWorld;
14+
import org.dynmap.renderer.DynmapBlockState;
15+
import org.dynmap.utils.MapChunkCache;
16+
import org.dynmap.utils.Polygon;
17+
18+
import java.lang.reflect.Field;
19+
import java.lang.reflect.Method;
20+
import java.util.HashMap;
21+
import java.util.IdentityHashMap;
22+
import java.util.List;
23+
24+
25+
/**
26+
* Helper for isolation of bukkit version specific issues
27+
*/
28+
public class BukkitVersionHelperSpigot116_4 extends BukkitVersionHelperGeneric {
29+
private Field watercolorfield;
30+
31+
public BukkitVersionHelperSpigot116_4() {
32+
Class biomefog = getNMSClass("net.minecraft.server.BiomeFog");
33+
watercolorfield = getPrivateField(biomefog, new String[] { "c" }, int.class);
34+
}
35+
36+
/**
37+
* Get block short name list
38+
*/
39+
@Override
40+
public String[] getBlockNames() {
41+
int cnt = Block.REGISTRY_ID.a();
42+
String[] names = new String[cnt];
43+
for (int i = 0; i < cnt; i++) {
44+
IBlockData bd = Block.getByCombinedId(i);
45+
names[i] = IRegistry.BLOCK.getKey(bd.getBlock()).toString();
46+
Log.info(i + ": blk=" + names[i] + ", bd=" + bd.toString());
47+
}
48+
return names;
49+
}
50+
51+
private IRegistry<BiomeBase> reg = null;
52+
53+
private IRegistry<BiomeBase> getBiomeReg() {
54+
if (reg == null) {
55+
reg = MinecraftServer.getServer().getCustomRegistry().b(IRegistry.ay);
56+
}
57+
return reg;
58+
}
59+
60+
private Object[] biomelist;
61+
/**
62+
* Get list of defined biomebase objects
63+
*/
64+
@Override
65+
public Object[] getBiomeBaseList() {
66+
if (biomelist == null) {
67+
biomelist = new Object[1024];
68+
for (int i = 0; i < 1024; i++) {
69+
biomelist[i] = getBiomeReg().fromId(i);
70+
}
71+
}
72+
return biomelist;
73+
}
74+
75+
/** Get ID from biomebase */
76+
@Override
77+
public int getBiomeBaseID(Object bb) {
78+
return getBiomeReg().a((BiomeBase)bb);
79+
}
80+
81+
public static IdentityHashMap<IBlockData, DynmapBlockState> dataToState;
82+
83+
/**
84+
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
85+
*/
86+
@Override
87+
public void initializeBlockStates() {
88+
dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
89+
HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
90+
91+
int cnt = Block.REGISTRY_ID.a();
92+
// Loop through block data states
93+
for (int i = 0; i < cnt; i++) {
94+
IBlockData bd = Block.getByCombinedId(i);
95+
String bname = IRegistry.BLOCK.getKey(bd.getBlock()).toString();
96+
DynmapBlockState lastbs = lastBlockState.get(bname); // See if we have seen this one
97+
int idx = 0;
98+
if (lastbs != null) { // Yes
99+
idx = lastbs.getStateCount(); // Get number of states so far, since this is next
100+
}
101+
// Build state name
102+
String sb = "";
103+
String fname = bd.toString();
104+
int off1 = fname.indexOf('[');
105+
if (off1 >= 0) {
106+
int off2 = fname.indexOf(']');
107+
sb = fname.substring(off1+1, off2);
108+
}
109+
Material mat = bd.getMaterial();
110+
DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb, mat.toString());
111+
if ((!bd.getFluid().isEmpty()) && ((bd.getBlock() instanceof BlockFluids) == false)) { // Test if fluid type for block is not empty
112+
bs.setWaterlogged();
113+
}
114+
if (mat == Material.AIR) {
115+
bs.setAir();
116+
}
117+
if (mat == Material.LEAVES) {
118+
bs.setLeaves();
119+
}
120+
if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.WOOD)) {
121+
bs.setLog();
122+
}
123+
if (mat.isSolid()) {
124+
bs.setSolid();
125+
}
126+
dataToState.put(bd, bs);
127+
lastBlockState.put(bname, (lastbs == null) ? bs : lastbs);
128+
Log.verboseinfo(i + ": blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + bs.isWaterlogged());
129+
}
130+
}
131+
/**
132+
* Create chunk cache for given chunks of given world
133+
* @param dw - world
134+
* @param chunks - chunk list
135+
* @return cache
136+
*/
137+
@Override
138+
public MapChunkCache getChunkCache(BukkitWorld dw, List<DynmapChunk> chunks) {
139+
MapChunkCache116_4 c = new MapChunkCache116_4();
140+
c.setChunks(dw, chunks);
141+
return c;
142+
}
143+
144+
/**
145+
* Get biome base water multiplier
146+
*/
147+
@Override
148+
public int getBiomeBaseWaterMult(Object bb) {
149+
try {
150+
return (int) watercolorfield.get(((BiomeBase)bb).l());
151+
} catch (IllegalArgumentException e) {
152+
} catch (IllegalAccessException e) {
153+
}
154+
return 0xFFFFFF;
155+
}
156+
157+
/** Get temperature from biomebase */
158+
@Override
159+
public float getBiomeBaseTemperature(Object bb) {
160+
return ((BiomeBase)bb).k();
161+
}
162+
163+
/** Get humidity from biomebase */
164+
@Override
165+
public float getBiomeBaseHumidity(Object bb) {
166+
return ((BiomeBase)bb).getHumidity();
167+
}
168+
169+
@Override
170+
public Polygon getWorldBorder(World world) {
171+
Polygon p = null;
172+
WorldBorder wb = world.getWorldBorder();
173+
if (wb != null) {
174+
Location c = wb.getCenter();
175+
double size = wb.getSize();
176+
if ((size > 1) && (size < 1E7)) {
177+
size = size / 2;
178+
p = new Polygon();
179+
p.addVertex(c.getX()-size, c.getZ()-size);
180+
p.addVertex(c.getX()+size, c.getZ()-size);
181+
p.addVertex(c.getX()+size, c.getZ()+size);
182+
p.addVertex(c.getX()-size, c.getZ()+size);
183+
}
184+
}
185+
return p;
186+
}
187+
// Send title/subtitle to user
188+
public void sendTitleText(Player p, String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTIcks) {
189+
if (p != null) {
190+
p.sendTitle(title, subtitle, fadeInTicks, stayTicks, fadeOutTIcks);
191+
}
192+
}
193+
194+
/**
195+
* Get material map by block ID
196+
*/
197+
@Override
198+
public BukkitMaterial[] getMaterialList() {
199+
return new BukkitMaterial[4096]; // Not used
200+
}
201+
202+
@Override
203+
protected void loadNMS() {
204+
// Not needed
205+
}
206+
207+
@Override
208+
protected String getNMSPackage() {
209+
Server srv = Bukkit.getServer();
210+
/* Get getHandle() method */
211+
try {
212+
Method m = srv.getClass().getMethod("getHandle");
213+
Object scm = m.invoke(srv); /* And use it to get SCM (nms object) */
214+
return scm.getClass().getPackage().getName();
215+
} catch (Exception x) {
216+
Log.severe("Error finding net.minecraft.server packages");
217+
return null;
218+
}
219+
}
220+
221+
@Override
222+
public void unloadChunkNoSave(World w, org.bukkit.Chunk c, int cx, int cz) {
223+
Log.severe("unloadChunkNoSave not implemented");
224+
}
225+
226+
private String[] biomenames;
227+
@Override
228+
public String[] getBiomeNames() {
229+
if (biomenames == null) {
230+
biomenames = new String[1024];
231+
for (int i = 0; i < 1024; i++) {
232+
BiomeBase bb = getBiomeReg().fromId(i);
233+
if (bb != null) {
234+
biomenames[i] = bb.toString();
235+
}
236+
}
237+
}
238+
return biomenames;
239+
}
240+
241+
@Override
242+
public String getStateStringByCombinedId(int blkid, int meta) {
243+
Log.severe("getStateStringByCombinedId not implemented");
244+
return null;
245+
}
246+
@Override
247+
/** Get ID string from biomebase */
248+
public String getBiomeBaseIDString(Object bb) {
249+
String s = ((BiomeBase)bb).toString();
250+
if (s != null) {
251+
String[] ss = s.split("\\.");
252+
return ss[ss.length-1];
253+
}
254+
return null;
255+
}
256+
}

0 commit comments

Comments
 (0)