mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-10-31 23:59:33 +01:00
Improve ceillog2 method
This commit is contained in:
parent
782d7a2172
commit
8de7a4c828
@ -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_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 = register(755, "1.17");
|
||||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
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 final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||||
|
|
||||||
public static ProtocolVersion register(int version, String name) {
|
public static ProtocolVersion register(int version, String name) {
|
||||||
|
@ -46,6 +46,13 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
|
|||||||
|
|
||||||
public Protocol1_18To1_17_1() {
|
public Protocol1_18To1_17_1() {
|
||||||
super(ClientboundPackets1_17_1.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
|
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);
|
final SoundRewriter soundRewriter = new SoundRewriter(this);
|
||||||
soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND);
|
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);
|
.reader("vibration", ParticleType.Readers.VIBRATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void registerPackets() {
|
|
||||||
entityRewriter.register();
|
|
||||||
itemRewriter.register();
|
|
||||||
WorldPackets.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappingData getMappingData() {
|
public MappingData getMappingData() {
|
||||||
return MAPPINGS;
|
return MAPPINGS;
|
||||||
|
@ -20,18 +20,12 @@ package com.viaversion.viaversion.util;
|
|||||||
public final class MathUtil {
|
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
|
* @return ceiled log2 of the given number
|
||||||
*/
|
*/
|
||||||
public static int ceilLog2(final int i) {
|
public static int ceilLog2(final int i) {
|
||||||
int j = 1;
|
return i > 0 ? 31 - Integer.numberOfLeadingZeros(i) : 0;
|
||||||
int k = 0;
|
|
||||||
while (j < i) {
|
|
||||||
j *= 2;
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
return k;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user