mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
Fix some 1.8 bugs
Fix chunk reading bug Fix InventorySlots::byId bug VersionMapping NullPointerException
This commit is contained in:
parent
e515b019e4
commit
36548e9004
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -110,7 +110,11 @@ public class InventorySlots {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId(int versionId) {
|
public int getId(int versionId) {
|
||||||
return valueMap.get(versionId);
|
Integer value = valueMap.get(versionId);
|
||||||
|
if (value == null) {
|
||||||
|
return Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,23 +38,23 @@ public class VersionMapping {
|
|||||||
private final HashSet<Mappings> loaded = new HashSet<>();
|
private final HashSet<Mappings> loaded = new HashSet<>();
|
||||||
private Version version;
|
private Version version;
|
||||||
private VersionMapping parentMapping;
|
private VersionMapping parentMapping;
|
||||||
private HashBiMap<String, Motive> motiveIdentifierMap;
|
private final HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap = HashBiMap.create();
|
||||||
private HashBiMap<String, Particle> particleIdentifierMap;
|
private final HashMap<EntityMetaDataFields, Integer> entityMetaIndexMap = new HashMap<>();
|
||||||
private HashBiMap<String, Statistic> statisticIdentifierMap;
|
private final HashMap<String, Pair<String, Integer>> entityMetaIndexOffsetParentMapping = new HashMap<>();
|
||||||
private HashBiMap<Integer, Item> itemMap;
|
private final HashBiMap<Integer, Class<? extends Entity>> entityIdClassMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Motive> motiveIdMap;
|
private HashBiMap<String, Motive> motiveIdentifierMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, MobEffect> mobEffectMap;
|
private HashBiMap<String, Particle> particleIdentifierMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Dimension> dimensionMap;
|
private HashBiMap<String, Statistic> statisticIdentifierMap = HashBiMap.create();
|
||||||
private HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
|
private HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
|
||||||
private HashBiMap<Integer, Block> blockMap;
|
private HashBiMap<Integer, Item> itemMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, BlockId> blockIdMap;
|
private HashBiMap<Integer, Motive> motiveIdMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Enchantment> enchantmentMap;
|
private HashBiMap<Integer, MobEffect> mobEffectMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Particle> particleIdMap;
|
private HashBiMap<Integer, Dimension> dimensionMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Statistic> statisticIdMap;
|
private HashBiMap<Integer, Block> blockMap = HashBiMap.create();
|
||||||
private HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap;
|
private HashBiMap<Integer, BlockId> blockIdMap = HashBiMap.create();
|
||||||
private HashMap<EntityMetaDataFields, Integer> entityMetaIndexMap;
|
private HashBiMap<Integer, Enchantment> enchantmentMap = HashBiMap.create();
|
||||||
private HashMap<String, Pair<String, Integer>> entityMetaIndexOffsetParentMapping;
|
private HashBiMap<Integer, Particle> particleIdMap = HashBiMap.create();
|
||||||
private HashBiMap<Integer, Class<? extends Entity>> entityIdClassMap;
|
private HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
|
||||||
|
|
||||||
public VersionMapping(Version version) {
|
public VersionMapping(Version version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
@ -153,7 +153,11 @@ public class VersionMapping {
|
|||||||
return dimensionMap.get(versionId);
|
return dimensionMap.get(versionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Block getBlockById(int versionId) {
|
public Block getBlockById(int versionId) {
|
||||||
|
if (versionId == ProtocolDefinition.NULL_BLOCK_ID) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (parentMapping != null) {
|
if (parentMapping != null) {
|
||||||
Block block = parentMapping.getBlockById(versionId);
|
Block block = parentMapping.getBlockById(versionId);
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
@ -302,16 +306,6 @@ public class VersionMapping {
|
|||||||
dimensionMap = Versions.PRE_FLATTENING_MAPPING.dimensionMap;
|
dimensionMap = Versions.PRE_FLATTENING_MAPPING.dimensionMap;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
itemMap = HashBiMap.create();
|
|
||||||
enchantmentMap = HashBiMap.create();
|
|
||||||
statisticIdMap = HashBiMap.create();
|
|
||||||
statisticIdentifierMap = HashBiMap.create();
|
|
||||||
blockIdMap = HashBiMap.create();
|
|
||||||
motiveIdMap = HashBiMap.create();
|
|
||||||
motiveIdentifierMap = HashBiMap.create();
|
|
||||||
particleIdMap = HashBiMap.create();
|
|
||||||
particleIdentifierMap = HashBiMap.create();
|
|
||||||
mobEffectMap = HashBiMap.create();
|
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
break;
|
break;
|
||||||
@ -387,17 +381,11 @@ public class VersionMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
blockMap = HashBiMap.create();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
blockMap = Blocks.load(mod, data, !version.isFlattened());
|
blockMap = Blocks.load(mod, data, !version.isFlattened());
|
||||||
}
|
}
|
||||||
case ENTITIES -> {
|
case ENTITIES -> {
|
||||||
entityInformationMap = HashBiMap.create();
|
|
||||||
entityMetaIndexMap = new HashMap<>();
|
|
||||||
entityMetaIndexOffsetParentMapping = new HashMap<>();
|
|
||||||
entityIdClassMap = HashBiMap.create();
|
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ public class PacketChunkData implements ClientboundPacket {
|
|||||||
if (buffer.getVersionId() < 23) {
|
if (buffer.getVersionId() < 23) {
|
||||||
this.location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
this.location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||||
boolean groundUpContinuous = buffer.readBoolean();
|
boolean groundUpContinuous = buffer.readBoolean();
|
||||||
short sectionBitMask = buffer.readShort();
|
int sectionBitMask = buffer.readUnsignedShort();
|
||||||
short addBitMask = buffer.readShort();
|
int addBitMask = buffer.readUnsignedShort();
|
||||||
|
|
||||||
// decompress chunk data
|
// decompress chunk data
|
||||||
InByteBuffer decompressed;
|
InByteBuffer decompressed;
|
||||||
@ -60,15 +60,14 @@ public class PacketChunkData implements ClientboundPacket {
|
|||||||
boolean groundUpContinuous = buffer.readBoolean();
|
boolean groundUpContinuous = buffer.readBoolean();
|
||||||
int sectionBitMask;
|
int sectionBitMask;
|
||||||
if (buffer.getVersionId() < 60) {
|
if (buffer.getVersionId() < 60) {
|
||||||
sectionBitMask = buffer.readShort();
|
sectionBitMask = buffer.readUnsignedShort();
|
||||||
} else {
|
} else {
|
||||||
sectionBitMask = buffer.readInt();
|
sectionBitMask = buffer.readInt();
|
||||||
}
|
}
|
||||||
int size = buffer.readVarInt();
|
int size = buffer.readVarInt();
|
||||||
int lastPos = buffer.getPosition();
|
int lastPos = buffer.getPosition();
|
||||||
|
chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight);
|
||||||
buffer.setPosition(size + lastPos);
|
buffer.setPosition(size + lastPos);
|
||||||
|
|
||||||
chunk = ChunkUtil.readChunkPacket(buffer, (short) sectionBitMask, (short) 0, groundUpContinuous, containsSkyLight);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
this.location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||||
@ -99,7 +98,7 @@ public class PacketChunkData implements ClientboundPacket {
|
|||||||
int lastPos = buffer.getPosition();
|
int lastPos = buffer.getPosition();
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
chunk = ChunkUtil.readChunkPacket(buffer, (short) sectionBitMask, (short) 0, groundUpContinuous, containsSkyLight);
|
chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight);
|
||||||
// set position of the byte buffer, because of some reasons HyPixel makes some weird stuff and sends way to much 0 bytes. (~ 190k), thanks @pokechu22
|
// set position of the byte buffer, because of some reasons HyPixel makes some weird stuff and sends way to much 0 bytes. (~ 190k), thanks @pokechu22
|
||||||
buffer.setPosition(size + lastPos);
|
buffer.setPosition(size + lastPos);
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,15 @@ public class PacketEntityEquipment implements ClientboundPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(InByteBuffer buffer) {
|
public boolean read(InByteBuffer buffer) {
|
||||||
if (buffer.getVersionId() < 7) {
|
entityId = buffer.readEntityId();
|
||||||
entityId = buffer.readInt();
|
|
||||||
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getVersionId()), buffer.readSlot());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (buffer.getVersionId() < 49) {
|
if (buffer.getVersionId() < 49) {
|
||||||
entityId = buffer.readVarInt();
|
|
||||||
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getVersionId()), buffer.readSlot());
|
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getVersionId()), buffer.readSlot());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (buffer.getVersionId() < 732) {
|
if (buffer.getVersionId() < 732) {
|
||||||
entityId = buffer.readVarInt();
|
|
||||||
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readVarInt(), buffer.getVersionId()), buffer.readSlot());
|
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readVarInt(), buffer.getVersionId()), buffer.readSlot());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
entityId = buffer.readVarInt();
|
|
||||||
boolean slotAvailable = true;
|
boolean slotAvailable = true;
|
||||||
while (slotAvailable) {
|
while (slotAvailable) {
|
||||||
int slotId = buffer.readByte();
|
int slotId = buffer.readByte();
|
||||||
|
@ -123,8 +123,8 @@ public class InByteBuffer {
|
|||||||
return readByte() == 1;
|
return readByte() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short[] readLEShorts(int num) {
|
public int[] readUnsignedLEShorts(int num) {
|
||||||
short[] ret = new short[num];
|
int[] ret = new int[num];
|
||||||
for (int i = 0; i < ret.length; i++) {
|
for (int i = 0; i < ret.length; i++) {
|
||||||
ret[i] = (short) (readByte() & 0xFF);
|
ret[i] = (short) (readByte() & 0xFF);
|
||||||
ret[i] |= (readByte() & 0xFF) << 8;
|
ret[i] |= (readByte() & 0xFF) << 8;
|
||||||
|
@ -39,6 +39,8 @@ public final class ProtocolDefinition {
|
|||||||
|
|
||||||
public static final int DEFAULT_BUFFER_SIZE = 4096;
|
public static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
|
public static final int NULL_BLOCK_ID = 0;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// java does (why ever) not allow to directly assign a null
|
// java does (why ever) not allow to directly assign a null
|
||||||
InetAddress temp;
|
InetAddress temp;
|
||||||
|
@ -23,10 +23,10 @@ public final class BitByte {
|
|||||||
return ((in & mask) == mask);
|
return ((in & mask) == mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte getBitCount(short input) {
|
public static byte getBitCount(int input) {
|
||||||
byte ret = 0;
|
byte ret = 0;
|
||||||
for (byte i = 0; i < Short.BYTES * 8; i++) { // bytes to bits
|
for (byte i = 0; i < Short.BYTES * 8; i++) { // bytes to bits
|
||||||
if (isBitSetShort(input, i)) {
|
if (isBitSet(input, i)) {
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public final class ChunkUtil {
|
public final class ChunkUtil {
|
||||||
public static Chunk readChunkPacket(InByteBuffer buffer, short sectionBitMask, short addBitMask, boolean groundUpContinuous, boolean containsSkyLight) {
|
public static Chunk readChunkPacket(InByteBuffer buffer, int sectionBitMask, int addBitMask, boolean groundUpContinuous, boolean containsSkyLight) {
|
||||||
if (buffer.getVersionId() < 23) {
|
if (buffer.getVersionId() < 23) {
|
||||||
if (sectionBitMask == 0x00 && groundUpContinuous) {
|
if (sectionBitMask == 0x00 && groundUpContinuous) {
|
||||||
// unload chunk
|
// unload chunk
|
||||||
@ -100,7 +100,7 @@ public final class ChunkUtil {
|
|||||||
int totalBlocks = 4096 * sections; // 16 * 16 * 16 * sections; Section Width * Section Height * Section Width * sections
|
int totalBlocks = 4096 * sections; // 16 * 16 * 16 * sections; Section Width * Section Height * Section Width * sections
|
||||||
int halfBytes = totalBlocks / 2; // half bytes
|
int halfBytes = totalBlocks / 2; // half bytes
|
||||||
|
|
||||||
short[] blockData = buffer.readLEShorts(totalBlocks); // blocks >>> 4, data & 0xF
|
int[] blockData = buffer.readUnsignedLEShorts(totalBlocks); // blocks >>> 4, data & 0xF
|
||||||
|
|
||||||
byte[] light = buffer.readBytes(halfBytes);
|
byte[] light = buffer.readBytes(halfBytes);
|
||||||
byte[] skyLight = null;
|
byte[] skyLight = null;
|
||||||
@ -122,9 +122,9 @@ public final class ChunkUtil {
|
|||||||
for (int nibbleY = 0; nibbleY < 16; nibbleY++) {
|
for (int nibbleY = 0; nibbleY < 16; nibbleY++) {
|
||||||
for (int nibbleZ = 0; nibbleZ < 16; nibbleZ++) {
|
for (int nibbleZ = 0; nibbleZ < 16; nibbleZ++) {
|
||||||
for (int nibbleX = 0; nibbleX < 16; nibbleX++) {
|
for (int nibbleX = 0; nibbleX < 16; nibbleX++) {
|
||||||
int blockId = blockData[arrayPos] & 0xFFFF;
|
int blockId = blockData[arrayPos];
|
||||||
Block block = buffer.getConnection().getMapping().getBlockById(blockId);
|
Block block = buffer.getConnection().getMapping().getBlockById(blockId);
|
||||||
if (block.equals(Blocks.nullBlock)) {
|
if (block == null || block.equals(Blocks.nullBlock)) {
|
||||||
arrayPos++;
|
arrayPos++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user