Skip to content

Commit

Permalink
Support Minecraft 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Jan 2, 2024
1 parent 6c7c81c commit 5975f27
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ version = project.maven_version
group = project.maven_group

dependencies {
compileOnly "com.viaversion:viaversion-api:4.6.2"
compileOnly "com.viaversion:viaversion-api:4.9.3-SNAPSHOT"
compileOnly "org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void run() {
}
// Added in 15w44b (1.9)
if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("lily-pad-fix")) {
BoundingBoxFixer.fixLilyPad(getLogger());
BoundingBoxFixer.fixLilyPad(getLogger(), serverProtocol);
}
if (serverProtocol >= ProtocolVersion.v1_14_4.getVersion() && config.getBoolean("carpet-fix")) {
BoundingBoxFixer.fixCarpet(getLogger(), serverProtocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.viaversion.viarewind.legacysupport.injector;

import com.viaversion.viarewind.legacysupport.reflection.ReflectionAPI;
import com.viaversion.viarewind.legacysupport.BukkitPlugin;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;

import java.lang.reflect.Field;
Expand All @@ -31,9 +30,9 @@

public class BoundingBoxFixer {

public static void fixLilyPad(final Logger logger) {
public static void fixLilyPad(final Logger logger, final int serverVersion) {
try {
final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), "a");
final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), serverVersion <= ProtocolVersion.v1_20_2.getVersion() ? "a" : "b");

setBoundingBox(boundingBoxField.get(null), 0.0625, 0.0, 0.0625, 0.9375, 0.015625, 0.9375);
} catch (Exception ex) {
Expand All @@ -45,7 +44,7 @@ public static void fixCarpet(final Logger logger, final int serverVersion) {
try {
final Class<?> blockCarpetClass = serverVersion <= ProtocolVersion.v1_16_4.getVersion() ? NMSReflection.getNMSBlock("BlockCarpet") : NMSReflection.getNMSBlock("CarpetBlock");

final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, "a");
final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, serverVersion <= ProtocolVersion.v1_20_2.getVersion() ? "a" : "b");
setBoundingBox(boundingBoxField.get(0), 0.0D, -0.0000001D, 0.0D, 1.0D, 0.0000001D, 1.0D);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not fix carpet bounding box.", ex);
Expand All @@ -57,13 +56,14 @@ public static void fixLadder(final Logger logger, final int serverVersion) {
final boolean pre1_12_2 = serverVersion <= ProtocolVersion.v1_12_2.getVersion();
final boolean pre1_13_2 = serverVersion <= ProtocolVersion.v1_13_2.getVersion();
final boolean pre1_16_4 = serverVersion <= ProtocolVersion.v1_16_4.getVersion();
final boolean pre1_20_2 = serverVersion <= ProtocolVersion.v1_20_2.getVersion();

final Class<?> blockLadderClass = NMSReflection.getNMSBlock("BlockLadder");

final Field boundingBoxEastField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "b" : pre1_13_2 ? "c" : pre1_16_4 ? "c" : "d");
final Field boundingBoxWestField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "c" : pre1_13_2 ? "o" : pre1_16_4 ? "d" : "e");
final Field boundingBoxSouthField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "d" : pre1_13_2 ? "p" : pre1_16_4 ? "e" : "f");
final Field boundingBoxNorthField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "e" : pre1_13_2 ? "q" : pre1_16_4 ? "f" : "g");
final Field boundingBoxEastField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "b" : pre1_13_2 ? "c" : pre1_16_4 ? "c" : pre1_20_2 ? "d" : "e");
final Field boundingBoxWestField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "c" : pre1_13_2 ? "o" : pre1_16_4 ? "d" : pre1_20_2 ? "e" : "f");
final Field boundingBoxSouthField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "d" : pre1_13_2 ? "p" : pre1_16_4 ? "e" : pre1_20_2 ? "f" : "g");
final Field boundingBoxNorthField = ReflectionAPI.getFieldAccessible(blockLadderClass, pre1_12_2 ? "e" : pre1_13_2 ? "q" : pre1_16_4 ? "f" : pre1_20_2 ? "g" : "h");

setBoundingBox(boundingBoxEastField.get(null), 0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
setBoundingBox(boundingBoxWestField.get(null), 0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void setValue(Class clazz, Object object, String fieldname, Object
field.set(object, value);
}

public static void setValue(Class clazz, Object object, String fieldname, Object value) throws NoSuchFieldException, IllegalAccessException {
public static void setValue(Class clazz, Object object, String fieldname, Object value) throws IllegalAccessException {
setValue(clazz, object, fieldname, value, false);
}

Expand Down

0 comments on commit 5975f27

Please sign in to comment.