Improve ceillog2 method

This commit is contained in:
Nassim Jahnke 2021-11-19 09:10:06 +01:00
parent 782d7a2172
commit 8de7a4c828
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 11 additions and 16 deletions

View File

@ -81,6 +81,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("1.16", 4, 5));
public static final ProtocolVersion v1_17 = register(755, "1.17");
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
public static final ProtocolVersion v1_18 = register(757, "1.18");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
public static ProtocolVersion register(int version, String name) {

View File

@ -46,6 +46,13 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
public Protocol1_18To1_17_1() {
super(ClientboundPackets1_17_1.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
}
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
WorldPackets.register(this);
final SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND);
@ -84,13 +91,6 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
.reader("vibration", ParticleType.Readers.VIBRATION);
}
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
WorldPackets.register(this);
}
@Override
public MappingData getMappingData() {
return MAPPINGS;

View File

@ -20,18 +20,12 @@ package com.viaversion.viaversion.util;
public final class MathUtil {
/**
* Primitive method to return the ceiled log to the base of 2 for the given number.
* Returns the ceiled log to the base of 2 for the given number.
*
* @param i number to ceillog
* @param i positive number to ceillog
* @return ceiled log2 of the given number
*/
public static int ceilLog2(final int i) {
int j = 1;
int k = 0;
while (j < i) {
j *= 2;
k++;
}
return k;
return i > 0 ? 31 - Integer.numberOfLeadingZeros(i) : 0;
}
}