Fix carpets on 1.14+ servers (#47)

This commit is contained in:
VidTu 2022-09-03 01:24:51 +03:00 committed by GitHub
parent 61d07dec61
commit 3f4830d7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.iml
.idea/
build/
target/

View File

@ -36,6 +36,8 @@ public class BukkitPlugin extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new BrewingListener(), BukkitPlugin.this);
if (serverProtocol > 84 && config.getBoolean("lily-pad-fix"))
BoundingBoxFixer.fixLilyPad();
if (serverProtocol > 404 && config.getBoolean("carpet-fix")) // 1.14+ only
BoundingBoxFixer.fixCarpet();
if (serverProtocol > 48 && config.getBoolean("ladder-fix"))
BoundingBoxFixer.fixLadder();
if (serverProtocol > 47 && config.getBoolean("sound-fix"))

View File

@ -26,6 +26,22 @@ public class BoundingBoxFixer {
}
}
public static void fixCarpet() {
try {
int serverProtocol = Via.getAPI().getServerVersion().lowestSupportedVersion();
Class<?> blockCarpetClass;
if (serverProtocol <= 754) { // 1.16.5
blockCarpetClass = NMSReflection.getNMSBlock("BlockCarpet");
} else {
blockCarpetClass = NMSReflection.getNMSBlock("CarpetBlock");
}
Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, "a");
setBoundingBox(boundingBoxField.get(0), 0.0D, -0.0000001D, 0.0D, 1.0D, 0.0000001D, 1.0D);
} catch (Exception ex) {
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix carpet bounding box.", ex);
}
}
public static void fixLadder() {
try {
Class<?> blockLadderClass = NMSReflection.getNMSBlock("BlockLadder");

View File

@ -4,6 +4,8 @@ brewing-stand-gui-fix: true
enchanting-gui-fix: true
#Fix the lily pad bounding box to prevent clients lower than 1.9 from glitching
lily-pad-fix: true
#Fix the carpet bounding box to prevent 1.7 clients from glitching on 1.14+ servers
carpet-fix: true
#Fix the ladder bounding box to prevent clients lower than 1.9 from glitching
ladder-fix: true
#If set to true, this plugin will play sounds for 1.8 and lower that got clientside on 1.9 and higher