1.7 stolen from Gerrygames/ClientViaVersion

This commit is contained in:
creeper123123321 2019-02-05 18:46:46 -02:00
parent c182a67c18
commit bb2a937415
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
14 changed files with 2758 additions and 1 deletions

View File

@ -32,6 +32,7 @@ processResources {
dependencies {
compile "us.myles:viaversion:2.0.0-19w04a"
compile "de.gerrygames:viarewind-all:1.4.0"
minecraft "com.mojang:minecraft:19w04a"
mappings "net.fabricmc:yarn:19w04a.1"

View File

@ -133,15 +133,58 @@ public class ViaFabric implements ClientModInitializer {
e.printStackTrace();
}
}
File viaRewindJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.jar").toFile();
if (!(viaRewindJar.exists() && viaRewindJar.lastModified() / timeDivisor == cachedTime)) {
String localMd5 = null;
try {
if (viaRewindJar.exists()) {
try (InputStream is = Files.newInputStream(viaRewindJar.toPath())) {
localMd5 = DigestUtils.md5Hex(is);
}
}
URL versionsUrl = new URL("https://repo.viaversion.com/de/gerrygames/viarewind-all/?" + cachedTime);
JLOGGER.info("Checking for ViaRewind updates " + versionsUrl);
HttpURLConnection con = (HttpURLConnection) versionsUrl.openConnection();
con.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream()));
Pattern urlPattern = Pattern.compile("<A href='([^']*)/'>");
Matcher matcher = urlPattern.matcher(rawOutput);
List<String> versions = new ArrayList<>();
while (matcher.find()) {
versions.add(matcher.group(1));
}
String bestViaRewind = versions.stream().max(Comparator.comparing(Version::new)).orElse(null);
HttpURLConnection md5Con = (HttpURLConnection) new URL(
"https://repo.viaversion.com/de/gerrygames/viarewind-all/" + bestViaRewind
+ "/viarewind-all-" + bestViaRewind + ".jar.md5").openConnection();
md5Con.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
String remoteMd5 = CharStreams.toString(new InputStreamReader(md5Con.getInputStream()));
if (!remoteMd5.equals(localMd5)) {
URL url = new URL("https://repo.viaversion.com/de/gerrygames/viarewind-all/" + bestViaRewind
+ "/viarewind-all-" + bestViaRewind + ".jar");
ViaFabric.JLOGGER.info("Downloading " + url);
HttpURLConnection jarCon = (HttpURLConnection) url.openConnection();
jarCon.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
FileUtils.copyInputStreamToFile(jarCon.getInputStream(), viaRewindJar);
} else {
JLOGGER.info("No updates found");
viaRewindJar.setLastModified(System.currentTimeMillis());
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Method addUrl = ViaFabric.class.getClassLoader().getClass().getMethod("addURL", URL.class);
addUrl.setAccessible(true);
addUrl.invoke(ViaFabric.class.getClassLoader(), viaVersionJar.toURI().toURL());
addUrl.invoke(ViaFabric.class.getClassLoader(), viaRewindJar.toURI().toURL());
Class.forName("com.github.creeper123123321.viafabric.platform.VRViaVersionInitializer")
.getMethod("init")
.invoke(null);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | MalformedURLException | ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}

View File

@ -25,8 +25,14 @@
package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.commands.VRCommandHandler;
import com.github.creeper123123321.viafabric.protocol.protocol1_7_6_10to1_7_1_5.Protocol1_7_6_10to1_7_1_5;
import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.Protocol1_8TO1_7_6_10;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import java.util.Collections;
public class VRViaVersionInitializer {
public static void init() {
@ -36,5 +42,7 @@ public class VRViaVersionInitializer {
.commandHandler(new VRCommandHandler())
.platform(new VRPlatform()).build());
Via.getManager().init();
ProtocolRegistry.registerProtocol(new Protocol1_7_6_10to1_7_1_5(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_7_1.getId());
ProtocolRegistry.registerProtocol(new Protocol1_8TO1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_7_6.getId());
}
}

View File

@ -0,0 +1,80 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_7_6_10to1_7_1_5;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
// Based on https://github.com/Gerrygames/ClientViaVersion
public class Protocol1_7_6_10to1_7_1_5 extends Protocol {
public static final ValueTransformer<String, String> INSERT_DASHES = new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper packetWrapper, String s) {
StringBuilder builder = new StringBuilder(s);
builder.insert(20, "-");
builder.insert(16, "-");
builder.insert(12, "-");
builder.insert(8, "-");
return builder.toString();
}
};
@Override
protected void registerPackets() {
//Login Success
this.registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING, INSERT_DASHES);
}
});
//Spawn Player
this.registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.STRING, INSERT_DASHES);
map(Type.STRING);
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
packetWrapper.write(Type.VAR_INT, 0);
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
}
}

View File

@ -0,0 +1,149 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.chunks;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
public class Chunk1_8to1_7_6_10 {
public ExtendedBlockStorage[] storageArrays = new ExtendedBlockStorage[16];
public byte[] blockBiomeArray = new byte[256];
private boolean skyLight;
private int primaryBitMask;
private boolean groundUp;
public Chunk1_8to1_7_6_10(byte[] data, int primaryBitMask, int addBitMask, boolean skyLight, boolean groundUp) {
this.primaryBitMask = primaryBitMask;
this.skyLight = skyLight;
this.groundUp = groundUp;
int dataSize = 0;
for (int i = 0; i < this.storageArrays.length; i++) {
if ((primaryBitMask & 1 << i) != 0) {
if (this.storageArrays[i] == null) this.storageArrays[i] = new ExtendedBlockStorage(i << 4, skyLight);
byte[] blockIds = this.storageArrays[i].getBlockLSBArray();
System.arraycopy(data, dataSize, blockIds, 0, blockIds.length);
dataSize += blockIds.length;
} else if (this.storageArrays[i] != null && groundUp) {
this.storageArrays[i] = null;
}
}
for (int i = 0; i < this.storageArrays.length; i++) {
if ((primaryBitMask & 1 << i) != 0 && this.storageArrays[i] != null) {
NibbleArray nibblearray = this.storageArrays[i].getMetadataArray();
System.arraycopy(data, dataSize, nibblearray.getHandle(), 0, nibblearray.getHandle().length);
dataSize += nibblearray.getHandle().length;
}
}
for (int i = 0; i < this.storageArrays.length; i++) {
if ((primaryBitMask & 1 << i) != 0 && this.storageArrays[i] != null) {
NibbleArray nibblearray = this.storageArrays[i].getBlocklightArray();
System.arraycopy(data, dataSize, nibblearray.getHandle(), 0, nibblearray.getHandle().length);
dataSize += nibblearray.getHandle().length;
}
}
if (skyLight) {
for (int i = 0; i < this.storageArrays.length; i++) {
if ((primaryBitMask & 1 << i) != 0 && this.storageArrays[i] != null) {
NibbleArray nibblearray = this.storageArrays[i].getSkylightArray();
System.arraycopy(data, dataSize, nibblearray.getHandle(), 0, nibblearray.getHandle().length);
dataSize += nibblearray.getHandle().length;
}
}
}
for (int i = 0; i < this.storageArrays.length; i++) {
if ((addBitMask & 1 << i) != 0) {
if (this.storageArrays[i] == null) {
dataSize += 2048;
} else {
NibbleArray nibblearray = this.storageArrays[i].getBlockMSBArray();
if (nibblearray == null) {
nibblearray = this.storageArrays[i].createBlockMSBArray();
}
System.arraycopy(data, dataSize, nibblearray.getHandle(), 0, nibblearray.getHandle().length);
dataSize += nibblearray.getHandle().length;
}
} else if (groundUp && this.storageArrays[i] != null && this.storageArrays[i].getBlockMSBArray() != null) {
this.storageArrays[i].clearMSBArray();
}
}
if (groundUp) {
System.arraycopy(data, dataSize, this.blockBiomeArray, 0, this.blockBiomeArray.length);
}
}
public byte[] get1_8Data() {
int finalSize = 0;
int columns = Integer.bitCount(this.primaryBitMask);
byte[] buffer = new byte[columns * 10240 + (this.skyLight ? columns * 2048 : 0) + 256];
for (int i = 0; i < storageArrays.length; ++i) {
if (storageArrays[i] != null && (this.primaryBitMask & 1 << i) != 0 && (!this.groundUp || storageArrays[i].isEmpty())) {
byte[] blockIds = storageArrays[i].getBlockLSBArray();
NibbleArray nibblearray = storageArrays[i].getMetadataArray();
for (int ind = 0; ind < blockIds.length; ++ind) {
int id = blockIds[ind] & 255;
int px = ind & 15;
int py = ind >> 8 & 15;
int pz = ind >> 4 & 15;
int data = nibblearray.get(px, py, pz);
//data = SpigotDebreakifier.getCorrectedData(id, data);
char val = (char) (id << 4 | data);
buffer[finalSize++] = (byte) (val & 255);
buffer[finalSize++] = (byte) (val >> 8 & 255);
}
}
}
for (int i = 0; i < storageArrays.length; ++i) {
if (storageArrays[i] != null && (this.primaryBitMask & 1 << i) != 0 && (!this.groundUp || storageArrays[i].isEmpty())) {
NibbleArray nibblearray = storageArrays[i].getBlocklightArray();
System.arraycopy(nibblearray.getHandle(), 0, buffer, finalSize, nibblearray.getHandle().length);
finalSize += nibblearray.getHandle().length;
}
}
if (this.skyLight) {
for (int i = 0; i < storageArrays.length; ++i) {
if (storageArrays[i] != null && (this.primaryBitMask & 1 << i) != 0 && (!this.groundUp || storageArrays[i].isEmpty())) {
NibbleArray nibblearray = storageArrays[i].getSkylightArray();
System.arraycopy(nibblearray.getHandle(), 0, buffer, finalSize, nibblearray.getHandle().length);
finalSize += nibblearray.getHandle().length;
}
}
}
if (this.groundUp) {
System.arraycopy(blockBiomeArray, 0, buffer, finalSize, blockBiomeArray.length);
finalSize += blockBiomeArray.length;
}
byte[] finaldata = new byte[finalSize];
System.arraycopy(buffer, 0, finaldata, 0, finalSize);
return finaldata;
}
}

View File

@ -0,0 +1,192 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.chunks;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.CustomByteType;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
public class ChunkPacketTransformer {
public static void transformChunk(PacketWrapper packetWrapper) throws Exception {
int chunkX = packetWrapper.read(Type.INT);
int chunkZ = packetWrapper.read(Type.INT);
boolean groundUp = packetWrapper.read(Type.BOOLEAN);
int primaryBitMask = packetWrapper.read(Type.SHORT);
int addBitMask = packetWrapper.read(Type.SHORT);
int compressedSize = packetWrapper.read(Type.INT);
CustomByteType customByteType = new CustomByteType(compressedSize);
byte[] data = packetWrapper.read(customByteType);
int k = 0;
int l = 0;
for(int j = 0; j < 16; ++j) {
k += primaryBitMask >> j & 1;
l += addBitMask >> j & 1;
}
int uncompressedSize = 12288 * k;
uncompressedSize += 2048 * l;
if (groundUp) {
uncompressedSize += 256;
}
byte[] uncompressedData = new byte[uncompressedSize];
Inflater inflater = new Inflater();
inflater.setInput(data, 0, compressedSize);
try {
inflater.inflate(uncompressedData);
} catch (DataFormatException ex) {
throw new IOException("Bad compressed data format");
} finally {
inflater.end();
}
Chunk1_8to1_7_6_10 chunk = new Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp);
Field field = PacketWrapper.class.getDeclaredField("packetValues");
field.setAccessible(true);
((List)field.get(packetWrapper)).clear();
field = PacketWrapper.class.getDeclaredField("readableObjects");
field.setAccessible(true);
((LinkedList)field.get(packetWrapper)).clear();
field = PacketWrapper.class.getDeclaredField("inputBuffer");
field.setAccessible(true);
ByteBuf buffer = (ByteBuf) field.get(packetWrapper);
buffer.clear();
buffer.writeInt(chunkX);
buffer.writeInt(chunkZ);
buffer.writeBoolean(groundUp);
buffer.writeShort(primaryBitMask);
byte[] finaldata = chunk.get1_8Data();
Type.VAR_INT.write(buffer, finaldata.length);
buffer.writeBytes(finaldata);
}
public static void transformChunkBulk(PacketWrapper packetWrapper) throws Exception {
short columnCount = packetWrapper.read(Type.SHORT); //short1
int size = packetWrapper.read(Type.INT); //size
boolean skyLightSent = packetWrapper.read(Type.BOOLEAN); //h
int[] chunkX = new int[columnCount]; //a
int[] chunkZ = new int[columnCount]; //b
int[] primaryBitMask = new int[columnCount]; //c
int[] addBitMask = new int[columnCount]; //d
byte[][] inflatedBuffers = new byte[columnCount][]; //inflatedBuffers
CustomByteType customByteType = new CustomByteType(size);
byte[] buildBuffer = packetWrapper.read(customByteType); //buildBuffer
byte[] data = new byte[196864 * columnCount]; //abyte
Inflater inflater = new Inflater();
inflater.setInput(buildBuffer, 0, size);
try {
inflater.inflate(data);
} catch (DataFormatException ex) {
throw new IOException("Bad compressed data format");
} finally {
inflater.end();
}
int i = 0;
for(int j = 0; j < columnCount; ++j) {
chunkX[j] = packetWrapper.read(Type.INT);
chunkZ[j] = packetWrapper.read(Type.INT);
primaryBitMask[j] = packetWrapper.read(Type.SHORT);
addBitMask[j] = packetWrapper.read(Type.SHORT);
int k = 0;
int l = 0;
int i1;
for(i1 = 0; i1 < 16; ++i1) {
k += primaryBitMask[j] >> i1 & 1;
l += addBitMask[j] >> i1 & 1;
}
i1 = 8192 * k + 256;
i1 += 2048 * l;
if (skyLightSent) {
i1 += 2048 * k;
}
inflatedBuffers[j] = new byte[i1];
System.arraycopy(data, i, inflatedBuffers[j], 0, i1);
i += i1;
}
Chunk1_8to1_7_6_10[] chunks = new Chunk1_8to1_7_6_10[columnCount];
for (i = 0; i<columnCount; i++) {
chunks[i] = new Chunk1_8to1_7_6_10(inflatedBuffers[i], primaryBitMask[i], addBitMask[i], skyLightSent, true);
}
packetWrapper.write(Type.BOOLEAN, skyLightSent);
packetWrapper.write(Type.VAR_INT, (int)columnCount);
for(i = 0; i < columnCount; ++i) {
packetWrapper.write(Type.INT, chunkX[i]);
packetWrapper.write(Type.INT, chunkZ[i]);
packetWrapper.write(Type.UNSIGNED_SHORT, primaryBitMask[i]);
}
for(i = 0; i < columnCount; ++i) {
data = chunks[i].get1_8Data();
customByteType = new CustomByteType(data.length);
packetWrapper.write(customByteType, data);
}
}
public static void transformMultiBlockChange(PacketWrapper packetWrapper) throws Exception {
int chunkX = packetWrapper.read(Type.INT);
int chunkZ = packetWrapper.read(Type.INT);
int size = packetWrapper.read(Type.SHORT);
packetWrapper.read(Type.INT);
short[] blocks = new short[size];
short[] positions = new short[size];
for (int i = 0; i<size; i++) {
positions[i] = packetWrapper.read(Type.SHORT);
blocks[i] = packetWrapper.read(Type.SHORT);
}
packetWrapper.write(Type.INT, chunkX);
packetWrapper.write(Type.INT, chunkZ);
packetWrapper.write(Type.VAR_INT, size);
for (int i = 0; i<size; i++) {
packetWrapper.write(Type.SHORT, positions[i]);
packetWrapper.write(Type.VAR_INT, (int)blocks[i]);
}
}
}

View File

@ -0,0 +1,127 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.chunks;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
public class ExtendedBlockStorage {
private int yBase;
private byte[] blockLSBArray;
private NibbleArray blockMSBArray;
private NibbleArray blockMetadataArray;
private NibbleArray blocklightArray;
private NibbleArray skylightArray;
public ExtendedBlockStorage(int paramInt, boolean paramBoolean) {
this.yBase = paramInt;
this.blockLSBArray = new byte[4096];
this.blockMetadataArray = new NibbleArray(this.blockLSBArray.length);
this.blocklightArray = new NibbleArray(this.blockLSBArray.length);
if (paramBoolean) {
this.skylightArray = new NibbleArray(this.blockLSBArray.length);
}
}
public int getExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3) {
return this.blockMetadataArray.get(paramInt1, paramInt2, paramInt3);
}
public void setExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
this.blockMetadataArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
}
public int getYLocation() {
return this.yBase;
}
public void setExtSkylightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
this.skylightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
}
public int getExtSkylightValue(int paramInt1, int paramInt2, int paramInt3) {
return this.skylightArray.get(paramInt1, paramInt2, paramInt3);
}
public void setExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
this.blocklightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
}
public int getExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3) {
return this.blocklightArray.get(paramInt1, paramInt2, paramInt3);
}
public byte[] getBlockLSBArray() {
return this.blockLSBArray;
}
public boolean isEmpty() {
return this.blockMSBArray==null;
}
public void clearMSBArray() {
this.blockMSBArray = null;
}
public NibbleArray getBlockMSBArray() {
return this.blockMSBArray;
}
public NibbleArray getMetadataArray() {
return this.blockMetadataArray;
}
public NibbleArray getBlocklightArray() {
return this.blocklightArray;
}
public NibbleArray getSkylightArray() {
return this.skylightArray;
}
public void setBlockLSBArray(byte[] paramArrayOfByte) {
this.blockLSBArray = paramArrayOfByte;
}
public void setBlockMSBArray(NibbleArray paramNibbleArray) {
this.blockMSBArray = paramNibbleArray;
}
public void setBlockMetadataArray(NibbleArray paramNibbleArray) {
this.blockMetadataArray = paramNibbleArray;
}
public void setBlocklightArray(NibbleArray paramNibbleArray) {
this.blocklightArray = paramNibbleArray;
}
public void setSkylightArray(NibbleArray paramNibbleArray) {
this.skylightArray = paramNibbleArray;
}
public NibbleArray createBlockMSBArray() {
this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
return this.blockMSBArray;
}
}

View File

@ -0,0 +1,109 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.metadata;
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.MetaType1_7_6_10;
import de.gerrygames.viarewind.protocol.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6_10;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
import java.util.ArrayList;
import java.util.List;
public class MetadataRewriter {
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
for (Metadata entry : new ArrayList<>(list)) {
MetaIndex1_8to1_7_6_10 metaIndex = MetaIndex1_8to1_7_6_10.searchIndex(type, entry.getId());
try {
if (metaIndex == null) throw new Exception("Could not find valid metadata");
if (metaIndex.getNewType() == MetaType1_8.NonExistent) {
list.remove(entry);
return;
}
Object value = entry.getValue();
if (!value.getClass().isAssignableFrom(metaIndex.getOldType().getType().getOutputClass())) {
list.remove(entry);
return;
}
entry.setMetaType(metaIndex.getNewType());
entry.setId(metaIndex.getNewIndex());
switch (metaIndex.getNewType()) {
case Int:
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
entry.setValue(((Byte) value).intValue());
}
if (metaIndex.getOldType() == MetaType1_7_6_10.Short) {
entry.setValue(((Short) value).intValue());
}
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
entry.setValue(value);
}
break;
case Byte:
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
entry.setValue(((Integer) value).byteValue());
}
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
entry.setValue(value);
}
if (metaIndex==MetaIndex1_8to1_7_6_10.HUMAN_SKIN_FLAGS) {
byte flags = (byte) value;
boolean cape = flags==2;
flags = (byte) (cape ? 127 : 125);
entry.setValue(flags);
}
break;
case Slot:
entry.setValue(value);
break;
case Float:
entry.setValue(value);
break;
case Short:
entry.setValue(value);
break;
case String:
entry.setValue(value);
break;
case Position:
entry.setValue(value);
break;
case Rotation:
entry.setValue(value);
break;
default:
Via.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
list.remove(entry);
break;
}
} catch (Exception e) {
list.remove(entry);
}
}
}
}

View File

@ -0,0 +1,86 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.storage;
import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.Protocol1_8TO1_7_6_10;
import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.metadata.MetadataRewriter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_8;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject {
private final Map<Integer, Entity1_10Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
public EntityTracker(UserConnection user) {
super(user);
}
public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId);
}
public Map<Integer, Entity1_10Types.EntityType> getClientEntityTypes() {
return this.clientEntityTypes;
}
public void addMetadataToBuffer(int entityID, List<Metadata> metadataList) {
if (this.metadataBuffer.containsKey(entityID)) {
this.metadataBuffer.get(entityID).addAll(metadataList);
} else if (!metadataList.isEmpty()) {
this.metadataBuffer.put(entityID, metadataList);
}
}
public List<Metadata> getBufferedMetadata(int entityId) {
return metadataBuffer.get(entityId);
}
public void sendMetadataBuffer(int entityId) {
if (!this.metadataBuffer.containsKey(entityId)) return;
PacketWrapper wrapper = new PacketWrapper(0x1C, null, this.getUser());
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_8.METADATA_LIST, this.metadataBuffer.get(entityId));
MetadataRewriter.transform(this.getClientEntityTypes().get(entityId), this.metadataBuffer.get(entityId));
if (!this.metadataBuffer.get(entityId).isEmpty()) {
try {
wrapper.send(Protocol1_8TO1_7_6_10.class);
} catch (Exception ex) {
ex.printStackTrace();
}
}
this.metadataBuffer.remove(entityId);
}
}

View File

@ -0,0 +1,66 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.storage;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.HashMap;
import java.util.Map;
public class MapStorage extends StoredObject {
private Map<Integer, MapData> maps = new HashMap<>();
public MapStorage(UserConnection user) {
super(user);
}
public MapData getMapData(int id) {
return maps.get(id);
}
public void putMapData(int id, MapData mapData) {
maps.put(id, mapData);
}
public static class MapData {
public byte scale = 0;
public MapIcon[] mapIcons = {};
}
public static class MapIcon {
public byte direction;
public byte type;
public byte x;
public byte z;
public MapIcon(byte direction, byte type, byte x, byte z) {
this.direction = direction;
this.type = type;
this.x = x;
this.z = z;
}
}
}

View File

@ -0,0 +1,47 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.storage;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.HashMap;
public class Scoreboard extends StoredObject {
private HashMap<String, String> objectives = new HashMap<>();
public Scoreboard(UserConnection user) {
super(user);
}
public void put(String name, String objective) {
objectives.put(name, objective);
}
public String get(String name) {
return objectives.getOrDefault(name, "null");
}
}

View File

@ -0,0 +1,88 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.storage;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Tablist extends StoredObject {
private ArrayList<TabListEntry> tablist = new ArrayList<>();
public Tablist(UserConnection user) {
super(user);
}
public TabListEntry getTabListEntry(String name) {
for (TabListEntry entry : tablist) if (name.equals(entry.name)) return entry;
return null;
}
public TabListEntry getTabListEntry(UUID uuid) {
for (TabListEntry entry : tablist) if (uuid.equals(entry.uuid)) return entry;
return null;
}
public void remove(TabListEntry entry) {
tablist.remove(entry);
}
public void add(TabListEntry entry) {
tablist.add(entry);
}
public static boolean shouldUpdateDisplayName(String oldName, String newName) {
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && !oldName.equals(newName);
}
public static class TabListEntry {
public String name;
public String displayName;
public UUID uuid;
public int ping;
public List<Property> properties = new ArrayList<>();
public TabListEntry(String name, UUID uuid) {
this.name = name;
this.uuid = uuid;
}
}
public static class Property {
public String name;
public String value;
public String signature;
public Property(String name, String value, String signature) {
this.name = name;
this.value = value;
this.signature = signature;
}
}
}

View File

@ -0,0 +1,43 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.storage;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.HashMap;
public class Windows extends StoredObject {
public HashMap<Short, Short> types = new HashMap<>();
public Windows(UserConnection user) {
super(user);
}
public short get(short windowId) {
return types.getOrDefault(windowId, (short)-1);
}
}