3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00
Dieser Commit ist enthalten in:
Myles 2018-12-05 19:08:55 +00:00
Ursprung fba0a59324
Commit c1147cb9f7
35 geänderte Dateien mit 541 neuen und 524 gelöschten Zeilen

Datei anzeigen

@ -38,7 +38,7 @@ public class DeathListener extends ViaBukkitListener {
@Override @Override
public void run() { public void run() {
// If online // If online
if(getUserConnection(p) != null) { if (getUserConnection(p) != null) {
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p)); PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
try { try {
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead wrapper.write(Type.VAR_INT, 2); // Event - Entity dead

Datei anzeigen

@ -208,7 +208,7 @@ public class UserConnection {
/** /**
* Sends a raw packet to the server * Sends a raw packet to the server
* *
* @param packet Raw packet to be sent * @param packet Raw packet to be sent
* @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop * @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop
*/ */
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) { public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
@ -248,5 +248,7 @@ public class UserConnection {
* *
* @param packet Raw packet to be sent * @param packet Raw packet to be sent
*/ */
public void sendRawPacketToServer(ByteBuf packet) { sendRawPacketToServer(packet, false); } public void sendRawPacketToServer(ByteBuf packet) {
sendRawPacketToServer(packet, false);
}
} }

Datei anzeigen

@ -9,26 +9,27 @@ import java.util.Map;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BlockFace { public enum BlockFace {
NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y); NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y);
private static Map<BlockFace, BlockFace> opposites = new HashMap<>(); private static Map<BlockFace, BlockFace> opposites = new HashMap<>();
static {
opposites.put(BlockFace.NORTH, BlockFace.SOUTH);
opposites.put(BlockFace.SOUTH, BlockFace.NORTH);
opposites.put(BlockFace.EAST, BlockFace.WEST);
opposites.put(BlockFace.WEST, BlockFace.EAST);
opposites.put(BlockFace.TOP, BlockFace.BOTTOM);
opposites.put(BlockFace.BOTTOM, BlockFace.TOP);
}
private int modX, modY, modZ; static {
private EnumAxis axis; opposites.put(BlockFace.NORTH, BlockFace.SOUTH);
opposites.put(BlockFace.SOUTH, BlockFace.NORTH);
opposites.put(BlockFace.EAST, BlockFace.WEST);
opposites.put(BlockFace.WEST, BlockFace.EAST);
opposites.put(BlockFace.TOP, BlockFace.BOTTOM);
opposites.put(BlockFace.BOTTOM, BlockFace.TOP);
}
public BlockFace opposite() { private int modX, modY, modZ;
return opposites.get(this); private EnumAxis axis;
}
public enum EnumAxis { public BlockFace opposite() {
X, Y, Z; return opposites.get(this);
} }
public enum EnumAxis {
X, Y, Z;
}
} }

Datei anzeigen

@ -9,16 +9,16 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@Data @Data
public class BaseChunk implements Chunk { public class BaseChunk implements Chunk {
protected int x; protected int x;
protected int z; protected int z;
protected boolean groundUp; protected boolean groundUp;
protected int bitmask; protected int bitmask;
protected ChunkSection[] sections; protected ChunkSection[] sections;
protected int[] biomeData; protected int[] biomeData;
protected List<CompoundTag> blockEntities; protected List<CompoundTag> blockEntities;
@Override @Override
public boolean isBiomeData() { public boolean isBiomeData() {
return biomeData != null; return biomeData != null;
} }
} }

Datei anzeigen

@ -98,22 +98,22 @@ public class ChunkSection {
} }
public void replacePaletteEntry(int oldId, int newId) { public void replacePaletteEntry(int oldId, int newId) {
Integer index = inversePalette.remove(oldId); Integer index = inversePalette.remove(oldId);
if (index == null) return; if (index == null) return;
inversePalette.put(newId, index); inversePalette.put(newId, index);
for (int i = 0; i < palette.size(); i++) { for (int i = 0; i < palette.size(); i++) {
if (palette.get(i) == oldId) palette.set(i, newId); if (palette.get(i) == oldId) palette.set(i, newId);
} }
} }
public void addPaletteEntry(int id) { public void addPaletteEntry(int id) {
inversePalette.put(id, palette.size()); inversePalette.put(id, palette.size());
palette.add(id); palette.add(id);
} }
public void clearPalette() { public void clearPalette() {
palette.clear(); palette.clear();
inversePalette.clear(); inversePalette.clear();
} }
/** /**
@ -124,14 +124,14 @@ public class ChunkSection {
* @param id The raw or flat id of the block * @param id The raw or flat id of the block
*/ */
public void setFlatBlock(int idx, int id) { public void setFlatBlock(int idx, int id) {
Integer index = inversePalette.get(id); Integer index = inversePalette.get(id);
if (index == null) { if (index == null) {
index = palette.size(); index = palette.size();
palette.add(id); palette.add(id);
inversePalette.put(id, index); inversePalette.put(id, index);
} }
blocks[idx] = index; blocks[idx] = index;
} }
/** /**

Datei anzeigen

@ -57,8 +57,8 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_12_2TO1_12_1(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_12_1.getId()); registerProtocol(new Protocol1_12_2TO1_12_1(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_12_1.getId());
registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId()); registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId());
registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId()); registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId());
registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId()); registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
} }
/** /**
@ -95,7 +95,7 @@ public class ProtocolRegistry {
* Base Protocols registered later have higher priority * Base Protocols registered later have higher priority
* Only one base protocol will be added to pipeline * Only one base protocol will be added to pipeline
* *
* @param baseProtocol Base Protocol to register * @param baseProtocol Base Protocol to register
* @param supportedProtocols Versions that baseProtocol supports * @param supportedProtocols Versions that baseProtocol supports
*/ */
public static void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) { public static void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) {

Datei anzeigen

@ -6,24 +6,24 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
public class Metadata1_13_2Type extends MetaTypeTemplate { public class Metadata1_13_2Type extends MetaTypeTemplate {
@Override @Override
public Metadata read(ByteBuf buffer) throws Exception { public Metadata read(ByteBuf buffer) throws Exception {
short index = buffer.readUnsignedByte(); short index = buffer.readUnsignedByte();
if (index == 0xff) return null; //End of metadata if (index == 0xff) return null; //End of metadata
MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte()); MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte());
return new Metadata(index, type, type.getType().read(buffer)); return new Metadata(index, type, type.getType().read(buffer));
} }
@Override @Override
public void write(ByteBuf buffer, Metadata object) throws Exception { public void write(ByteBuf buffer, Metadata object) throws Exception {
if (object == null) { if (object == null) {
buffer.writeByte(255); buffer.writeByte(255);
} else { } else {
buffer.writeByte(object.getId()); buffer.writeByte(object.getId());
buffer.writeByte(object.getMetaType().getTypeID()); buffer.writeByte(object.getMetaType().getTypeID());
object.getMetaType().getType().write(buffer, object.getValue()); object.getMetaType().getType().write(buffer, object.getValue());
} }
} }
} }

Datei anzeigen

@ -6,13 +6,13 @@ import us.myles.ViaVersion.api.type.Type;
import java.util.List; import java.util.List;
public class Types1_13_2 { public class Types1_13_2 {
/** /**
* Metadata list type for 1.13 * Metadata list type for 1.13
*/ */
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_13_2Type(); public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_13_2Type();
/** /**
* Metadata type for 1.13 * Metadata type for 1.13
*/ */
public static final Type<Metadata> METADATA = new Metadata1_13_2Type(); public static final Type<Metadata> METADATA = new Metadata1_13_2Type();
} }

Datei anzeigen

@ -100,7 +100,7 @@ public class MetadataRewriter {
public static void handleMetadata(int entityId, EntityType type, List<Metadata> metadatas, UserConnection connection) { public static void handleMetadata(int entityId, EntityType type, List<Metadata> metadatas, UserConnection connection) {
for (Metadata metadata : new ArrayList<>(metadatas)) { for (Metadata metadata : new ArrayList<>(metadatas)) {
try { try {
if(metadata.getValue() instanceof Item) { if (metadata.getValue() instanceof Item) {
// Apply rewrite // Apply rewrite
EntityIdRewriter.toClientItem((Item) metadata.getValue()); EntityIdRewriter.toClientItem((Item) metadata.getValue());
} }

Datei anzeigen

@ -8,8 +8,8 @@ public class TranslateRewriter {
public static boolean toClient(JsonElement element, UserConnection user) { public static boolean toClient(JsonElement element, UserConnection user) {
if (element instanceof JsonObject) { if (element instanceof JsonObject) {
JsonObject obj = (JsonObject) element; JsonObject obj = (JsonObject) element;
if(obj.has("translate")) { if (obj.has("translate")) {
if(obj.get("translate").getAsString().equals("chat.type.achievement")) { if (obj.get("translate").getAsString().equals("chat.type.achievement")) {
return false; return false;
} }
} }

Datei anzeigen

@ -14,68 +14,68 @@ import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.WorldPackets
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types.Particle1_13_2Type; import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types.Particle1_13_2Type;
public class Protocol1_13_2To1_13_1 extends Protocol { public class Protocol1_13_2To1_13_1 extends Protocol {
public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type(); public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type();
@Override @Override
protected void registerPackets() { protected void registerPackets() {
InventoryPackets.register(this); InventoryPackets.register(this);
WorldPackets.register(this); WorldPackets.register(this);
EntityPackets.register(this); EntityPackets.register(this);
//Edit Book //Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM);
} }
}); });
// Advancements // Advancements
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier wrapper.passthrough(Type.STRING); // Identifier
// Parent // Parent
if (wrapper.passthrough(Type.BOOLEAN)) if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
// Display data // Display data
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.STRING); // Title wrapper.passthrough(Type.STRING); // Title
wrapper.passthrough(Type.STRING); // Description wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.read(Type.FLAT_ITEM); Item icon = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.FLAT_VAR_INT_ITEM, icon); wrapper.write(Type.FLAT_VAR_INT_ITEM, icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture wrapper.passthrough(Type.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y wrapper.passthrough(Type.FLOAT); // Y
} }
wrapper.passthrough(Type.STRING_ARRAY); // Criteria wrapper.passthrough(Type.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT); int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) { for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array wrapper.passthrough(Type.STRING_ARRAY); // String array
} }
} }
} }
}); });
} }
}); });
} }
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
} }
} }

Datei anzeigen

@ -14,84 +14,84 @@ import us.myles.ViaVersion.packets.State;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
// Spawn mob packet // Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) { if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot); metadata.setMetaType(MetaType1_13_2.Slot);
} }
} }
} }
}); });
} }
}); });
// Spawn player packet // Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) { if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot); metadata.setMetaType(MetaType1_13_2.Slot);
} }
} }
} }
}); });
} }
}); });
// Metadata packet // Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) { if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot); metadata.setMetaType(MetaType1_13_2.Slot);
} }
} }
} }
}); });
} }
}); });
} }
} }

Datei anzeigen

@ -9,143 +9,143 @@ import us.myles.ViaVersion.packets.State;
public class InventoryPackets { public class InventoryPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
/* /*
Outgoing packets Outgoing packets
*/ */
// Set slot packet // Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.BYTE); // 0 - Window ID map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
} }
}); });
// Window items packet // Window items packet
protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
} }
}); });
// Plugin message // Plugin message
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); // Channel map(Type.STRING); // Channel
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.get(Type.STRING, 0); String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) { if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Input Item // Input Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
// Output Item // Output Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Type.INT); // Maximum number of trade uses
} }
} }
} }
}); });
} }
}); });
// Entity Equipment Packet // Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item
} }
}); });
// Declare Recipes // Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int recipesNo = wrapper.passthrough(Type.VAR_INT); int recipesNo = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < recipesNo; i++) { for (int i = 0; i < recipesNo; i++) {
wrapper.passthrough(Type.STRING); // Id wrapper.passthrough(Type.STRING); // Id
String type = wrapper.passthrough(Type.STRING); String type = wrapper.passthrough(Type.STRING);
if (type.equals("crafting_shapeless")) { if (type.equals("crafting_shapeless")) {
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
int ingredientsNo = wrapper.passthrough(Type.VAR_INT); int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int i1 = 0; i1 < ingredientsNo; i1++) { for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
} }
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} else if (type.equals("crafting_shaped")) { } else if (type.equals("crafting_shaped")) {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
for (int i1 = 0; i1 < ingredientsNo; i1++) { for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
} }
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} else if (type.equals("smelting")) { } else if (type.equals("smelting")) {
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
// Ingredient start // Ingredient start
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
// Ingredient end // Ingredient end
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time wrapper.passthrough(Type.VAR_INT); // Cooking time
} }
} }
} }
}); });
} }
}); });
/* /*
Incoming packets Incoming packets
*/ */
// Click window packet // Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item
} }
} }
); );
// Creative Inventory Action // Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.SHORT); // 0 - Slot map(Type.SHORT); // 0 - Slot
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item
} }
} }
); );
} }
} }

Datei anzeigen

@ -9,32 +9,32 @@ import us.myles.ViaVersion.packets.State;
public class WorldPackets { public class WorldPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
//spawn particle //spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Particle ID map(Type.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance map(Type.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X map(Type.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y map(Type.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z map(Type.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Type.INT, 0);
if (id == 27) { if (id == 27) {
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} }
} }
}); });
} }
}); });
} }
} }

Datei anzeigen

@ -16,7 +16,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
private Set<Integer> blockStates = new HashSet<>(); private Set<Integer> blockStates = new HashSet<>();
private Map<Byte, Integer> connectedBlockStates = new HashMap<>(); private Map<Byte, Integer> connectedBlockStates = new HashMap<>();
public AbstractFenceConnectionHandler(String blockConnections, String key){ public AbstractFenceConnectionHandler(String blockConnections, String key) {
this.blockConnections = blockConnections; this.blockConnections = blockConnections;
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {

Datei anzeigen

@ -8,11 +8,11 @@ import java.util.Map;
public class BlockData { public class BlockData {
private Map<String, Boolean[]> connectData = new HashMap<>(); private Map<String, Boolean[]> connectData = new HashMap<>();
public void put(String key, Boolean[] booleans){ public void put(String key, Boolean[] booleans) {
connectData.put(key, booleans); connectData.put(key, booleans);
} }
public boolean connectsTo(String blockConnection, BlockFace face){ public boolean connectsTo(String blockConnection, BlockFace face) {
final Boolean[] booleans = connectData.get(blockConnection); final Boolean[] booleans = connectData.get(blockConnection);
return booleans != null && booleans[face.ordinal()]; return booleans != null && booleans[face.ordinal()];
} }

Datei anzeigen

@ -10,52 +10,52 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
class ChestConnectionHandler extends ConnectionHandler { class ChestConnectionHandler extends ConnectionHandler {
private static Map<Integer, BlockFace> chestFacings = new HashMap<>(); private static Map<Integer, BlockFace> chestFacings = new HashMap<>();
private static Map<Byte, Integer> connectedStates = new HashMap<>(); private static Map<Byte, Integer> connectedStates = new HashMap<>();
private static Set<Integer> trappedChests = new HashSet<>(); private static Set<Integer> trappedChests = new HashSet<>();
static void init() { static void init() {
ChestConnectionHandler connectionHandler = new ChestConnectionHandler(); ChestConnectionHandler connectionHandler = new ChestConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {
String key = blockState.getKey().split("\\[")[0]; String key = blockState.getKey().split("\\[")[0];
if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue; if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue;
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
if (blockData.getValue("waterlogged").equals("true")) continue; if (blockData.getValue("waterlogged").equals("true")) continue;
chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue()); if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue());
connectedStates.put(getStates(blockData), blockState.getValue()); connectedStates.put(getStates(blockData), blockState.getValue());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler);
} }
} }
private static Byte getStates(WrappedBlockData blockData) { private static Byte getStates(WrappedBlockData blockData) {
byte states = 0; byte states = 0;
String type = blockData.getValue("type"); String type = blockData.getValue("type");
if (type.equals("left")) states |= 1; if (type.equals("left")) states |= 1;
if (type.equals("right")) states |= 2; if (type.equals("right")) states |= 2;
states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2); states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2);
if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16; if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16;
return states; return states;
} }
@Override @Override
public int connect(UserConnection user, Position position, int blockState) { public int connect(UserConnection user, Position position, int blockState) {
BlockFace facing = chestFacings.get(blockState); BlockFace facing = chestFacings.get(blockState);
byte states = 0; byte states = 0;
states |= (facing.ordinal() << 2); states |= (facing.ordinal() << 2);
boolean trapped = trappedChests.contains(blockState); boolean trapped = trappedChests.contains(blockState);
if (trapped) states |= 16; if (trapped) states |= 16;
int relative; int relative;
if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) { if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.WEST ? 1 : 2; states |= facing == BlockFace.WEST ? 1 : 2;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.EAST ? 1 : 2; states |= facing == BlockFace.EAST ? 1 : 2;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.NORTH ? 2 : 1; states |= facing == BlockFace.NORTH ? 2 : 1;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.SOUTH ? 2 : 1; states |= facing == BlockFace.SOUTH ? 2 : 1;
} }
Integer newBlockState = connectedStates.get(states); Integer newBlockState = connectedStates.get(states);
return newBlockState == null ? blockState : newBlockState; return newBlockState == null ? blockState : newBlockState;
} }
} }

Datei anzeigen

@ -8,12 +8,12 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi
public abstract class ConnectionHandler { public abstract class ConnectionHandler {
public abstract int connect(UserConnection user, Position position, int blockState); public abstract int connect(UserConnection user, Position position, int blockState);
public int getBlockData(UserConnection user, Position position) { public int getBlockData(UserConnection user, Position position) {
return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position); return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position);
} }
public boolean canConnect(int id) { public boolean canConnect(int id) {
ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id); ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id);
return handler != null && handler == this; return handler != null && handler == this;
} }
} }

Datei anzeigen

@ -39,11 +39,15 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
} }
private static int getState(String value) { private static int getState(String value) {
switch (value){ switch (value) {
case "none": return 0; case "none":
case "side" : return 1; return 0;
case "up" : return 2; case "side":
default: return 0; return 1;
case "up":
return 2;
default:
return 0;
} }
} }

Datei anzeigen

@ -11,82 +11,82 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class TripwireConnectionHandler extends ConnectionHandler { public class TripwireConnectionHandler extends ConnectionHandler {
private static Map<Integer, TripwireData> tripwireDataMap = new HashMap<>(); private static Map<Integer, TripwireData> tripwireDataMap = new HashMap<>();
private static Map<Byte, Integer> connectedBlocks = new HashMap<>(); private static Map<Byte, Integer> connectedBlocks = new HashMap<>();
private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>(); private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>();
static void init() { static void init() {
TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler(); TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {
String key = blockState.getKey().split("\\[")[0]; String key = blockState.getKey().split("\\[")[0];
if (key.equals("minecraft:tripwire_hook")) { if (key.equals("minecraft:tripwire_hook")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
} else if (key.equals("minecraft:tripwire")) { } else if (key.equals("minecraft:tripwire")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
TripwireData tripwireData = new TripwireData( TripwireData tripwireData = new TripwireData(
blockData.getValue("attached").equals("true"), blockData.getValue("attached").equals("true"),
blockData.getValue("disarmed").equals("true"), blockData.getValue("disarmed").equals("true"),
blockData.getValue("powered").equals("true") blockData.getValue("powered").equals("true")
); );
tripwireDataMap.put(blockState.getValue(), tripwireData); tripwireDataMap.put(blockState.getValue(), tripwireData);
connectedBlocks.put(getStates(blockData), blockState.getValue()); connectedBlocks.put(getStates(blockData), blockState.getValue());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler);
} }
} }
} }
private static byte getStates(WrappedBlockData blockData) { private static byte getStates(WrappedBlockData blockData) {
byte b = 0; byte b = 0;
if (blockData.getValue("attached").equals("true")) b |= 1; if (blockData.getValue("attached").equals("true")) b |= 1;
if (blockData.getValue("disarmed").equals("true")) b |= 2; if (blockData.getValue("disarmed").equals("true")) b |= 2;
if (blockData.getValue("powered").equals("true")) b |= 4; if (blockData.getValue("powered").equals("true")) b |= 4;
if (blockData.getValue("east").equals("true")) b |= 8; if (blockData.getValue("east").equals("true")) b |= 8;
if (blockData.getValue("north").equals("true")) b |= 16; if (blockData.getValue("north").equals("true")) b |= 16;
if (blockData.getValue("south").equals("true")) b |= 32; if (blockData.getValue("south").equals("true")) b |= 32;
if (blockData.getValue("west").equals("true")) b |= 64; if (blockData.getValue("west").equals("true")) b |= 64;
return b; return b;
} }
@Override @Override
public int connect(UserConnection user, Position position, int blockState) { public int connect(UserConnection user, Position position, int blockState) {
TripwireData tripwireData = tripwireDataMap.get(blockState); TripwireData tripwireData = tripwireDataMap.get(blockState);
if (tripwireData == null) return blockState; if (tripwireData == null) return blockState;
byte b = 0; byte b = 0;
if (tripwireData.isAttached()) b |= 1; if (tripwireData.isAttached()) b |= 1;
if (tripwireData.isDisarmed()) b |= 2; if (tripwireData.isDisarmed()) b |= 2;
if (tripwireData.isPowered()) b |= 4; if (tripwireData.isPowered()) b |= 4;
int east = getBlockData(user, position.getRelative(BlockFace.EAST)); int east = getBlockData(user, position.getRelative(BlockFace.EAST));
int north = getBlockData(user, position.getRelative(BlockFace.NORTH)); int north = getBlockData(user, position.getRelative(BlockFace.NORTH));
int south = getBlockData(user, position.getRelative(BlockFace.SOUTH)); int south = getBlockData(user, position.getRelative(BlockFace.SOUTH));
int west = getBlockData(user, position.getRelative(BlockFace.WEST)); int west = getBlockData(user, position.getRelative(BlockFace.WEST));
if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) { if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) {
b |= 8; b |= 8;
} }
if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) { if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) {
b |= 16; b |= 16;
} }
if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) { if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) {
b |= 32; b |= 32;
} }
if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) { if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) {
b |= 64; b |= 64;
} }
Integer newBlockState = connectedBlocks.get(b); Integer newBlockState = connectedBlocks.get(b);
return newBlockState == null ? blockState : newBlockState; return newBlockState == null ? blockState : newBlockState;
} }
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
@ToString @ToString
private static class TripwireData { private static class TripwireData {
private final boolean attached, disarmed, powered; private final boolean attached, disarmed, powered;
} }
} }

Datei anzeigen

@ -5,8 +5,8 @@ import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
public class WallConnectionHandler extends AbstractFenceConnectionHandler { public class WallConnectionHandler extends AbstractFenceConnectionHandler {
private static final BlockFace[] BLOCK_FACES = { BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST }; private static final BlockFace[] BLOCK_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST};
private static final int[] OPPOSITES = { 3, 2, 1, 0 }; private static final int[] OPPOSITES = {3, 2, 1, 0};
static void init() { static void init() {
new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall"); new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall");
@ -32,7 +32,8 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler {
} }
public boolean up(UserConnection user, Position position) { public boolean up(UserConnection user, Position position) {
if(isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP))))return true; if (isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP))))
return true;
int blockFaces = getBlockFaces(user, position); int blockFaces = getBlockFaces(user, position);
if (blockFaces == 0 || blockFaces == 0xF) return true; if (blockFaces == 0 || blockFaces == 0xF) return true;
for (int i = 0; i < BLOCK_FACES.length; i++) { for (int i = 0; i < BLOCK_FACES.length; i++) {
@ -51,7 +52,7 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler {
return blockFaces; return blockFaces;
} }
private boolean isWall(int id){ private boolean isWall(int id) {
return getBlockStates().contains(id); return getBlockStates().contains(id);
} }
} }

Datei anzeigen

@ -16,19 +16,27 @@ public class BlockConnectionProvider implements Provider {
return -1; return -1;
} }
public void storeBlock(UserConnection connection, Position position, int blockState) {}; public void storeBlock(UserConnection connection, Position position, int blockState) {
public void removeBlock(UserConnection connection, Position position) {}; }
public void removeBlock(UserConnection connection, Position position) {
}
public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) { public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) {
storeBlock(connection, new Position(x, y, z), blockState); storeBlock(connection, new Position(x, y, z), blockState);
} }
public void clearStorage(UserConnection connection) {}; public void clearStorage(UserConnection connection) {
public void unloadChunk(UserConnection connection, int x, int z) {}; }
public boolean storesBlocks(){ public void unloadChunk(UserConnection connection, int x, int z) {
}
public boolean storesBlocks() {
return false; return false;
} }
} }

Datei anzeigen

@ -243,7 +243,7 @@ public class WorldPackets {
protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
if(Via.getConfig().isServersideBlockConnections()){ if (Via.getConfig().isServersideBlockConnections()) {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {

Datei anzeigen

@ -34,29 +34,29 @@ public class BlockConnectionStorage extends StoredObject {
Pair pair = getPair(position); Pair pair = getPair(position);
Map<BlockPositon, Integer> map = getChunkMap(pair); Map<BlockPositon, Integer> map = getChunkMap(pair);
map.remove(new BlockPositon(position)); map.remove(new BlockPositon(position));
if(map.isEmpty()){ if (map.isEmpty()) {
blockStorage.remove(pair); blockStorage.remove(pair);
} }
} }
public void clear(){ public void clear() {
blockStorage.clear(); blockStorage.clear();
} }
public void unloadChunk(int x, int z){ public void unloadChunk(int x, int z) {
blockStorage.remove(new Pair<>(x, z)); blockStorage.remove(new Pair<>(x, z));
} }
private Map<BlockPositon, Integer> getChunkMap(Pair pair){ private Map<BlockPositon, Integer> getChunkMap(Pair pair) {
Map<BlockPositon, Integer> map = blockStorage.get(pair); Map<BlockPositon, Integer> map = blockStorage.get(pair);
if(map == null){ if (map == null) {
map = new HashMap<>(); map = new HashMap<>();
blockStorage.put(pair, map); blockStorage.put(pair, map);
} }
return map; return map;
} }
private Pair<Integer, Integer> getPair(Position position){ private Pair<Integer, Integer> getPair(Position position) {
int chunkX = (int) (position.getX() >> 4); int chunkX = (int) (position.getX() >> 4);
int chunkZ = (int) (position.getZ() >> 4); int chunkZ = (int) (position.getZ() >> 4);
return new Pair<>(chunkX, chunkZ); return new Pair<>(chunkX, chunkZ);
@ -65,8 +65,9 @@ public class BlockConnectionStorage extends StoredObject {
@EqualsAndHashCode @EqualsAndHashCode
@Data @Data
private class BlockPositon { private class BlockPositon {
int x,y,z; int x, y, z;
public BlockPositon(Position position){
public BlockPositon(Position position) {
x = position.getX().intValue(); x = position.getX().intValue();
y = position.getY().intValue(); y = position.getY().intValue();
z = position.getZ().intValue(); z = position.getZ().intValue();

Datei anzeigen

@ -121,8 +121,8 @@ public class WorldPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks); Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks);
Chunk1_8 chunk = (Chunk1_8) wrapper.read(type); Chunk1_8 chunk = (Chunk1_8) wrapper.read(type);
if (chunk.isUnloadPacket()) { if (chunk.isUnloadPacket()) {
wrapper.setId(0x1D); wrapper.setId(0x1D);

Datei anzeigen

@ -258,7 +258,7 @@ public class EntityTracker extends StoredObject {
} else { } else {
wrapper.write(Type.BYTE, (byte) 3); wrapper.write(Type.BYTE, (byte) 3);
} }
wrapper.write(Type.STRING_ARRAY, new String[] {getUser().get(ProtocolInfo.class).getUsername()}); wrapper.write(Type.STRING_ARRAY, new String[]{getUser().get(ProtocolInfo.class).getUsername()});
} else { } else {
wrapper.write(Type.BYTE, (byte) 1); // remove team wrapper.write(Type.BYTE, (byte) 1); // remove team
} }

Datei anzeigen

@ -113,7 +113,7 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
// Read biome data // Read biome data
if (bytesLeft >= BIOME_DATA_LENGTH) { if (bytesLeft >= BIOME_DATA_LENGTH) {
biomeData = new int[BIOME_DATA_LENGTH]; biomeData = new int[BIOME_DATA_LENGTH];
for (int i = 0; i < BIOME_DATA_LENGTH; i++){ for (int i = 0; i < BIOME_DATA_LENGTH; i++) {
biomeData[i] = input.readByte() & 0xFF; biomeData[i] = input.readByte() & 0xFF;
} }
bytesLeft -= BIOME_DATA_LENGTH; bytesLeft -= BIOME_DATA_LENGTH;

Datei anzeigen

@ -24,7 +24,7 @@ public class SpongeBlockConnectionProvider extends BlockConnectionProvider {
try { try {
block = Class.forName("net.minecraft.block.Block"); block = Class.forName("net.minecraft.block.Block");
blockStateIds = ReflectionUtil.get( blockStateIds = ReflectionUtil.get(
ReflectionUtil.getStatic(block, "field_176229_d", Object.class), ReflectionUtil.getStatic(block, "field_176229_d", Object.class),
"field_148749_a", Map.class); "field_148749_a", Map.class);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?"); Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?");

Datei anzeigen

@ -53,8 +53,8 @@ public class VelocityServerHandler {
// Check if ViaVersion can support that version // Check if ViaVersion can support that version
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null
? user.get(ProtocolInfo.class).getProtocolVersion() ? user.get(ProtocolInfo.class).getProtocolVersion()
: protocolId)); : protocolId));
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) { } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) {
e1.printStackTrace(); e1.printStackTrace();
@ -133,7 +133,7 @@ public class VelocityServerHandler {
} }
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection,"getNextProtocolVersion"); ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection, "getNextProtocolVersion");
setProtocolVersion.invoke(connection, version); setProtocolVersion.invoke(connection, version);
} }
} }

Datei anzeigen

@ -56,21 +56,21 @@ public class ProtocolDetectorService implements Runnable {
public static void probeServer(final RegisteredServer serverInfo) { public static void probeServer(final RegisteredServer serverInfo) {
final String key = serverInfo.getServerInfo().getName(); final String key = serverInfo.getServerInfo().getName();
serverInfo.ping().thenAccept((serverPing) -> { serverInfo.ping().thenAccept((serverPing) -> {
if (serverPing != null && serverPing.getVersion() != null) { if (serverPing != null && serverPing.getVersion() != null) {
detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); detectedProtocolIds.put(key, serverPing.getVersion().getProtocol());
if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) { if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) {
Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols();
Integer protocol = servers.get(key); Integer protocol = servers.get(key);
if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { if (protocol != null && protocol == serverPing.getVersion().getProtocol()) {
return; return;
}
// Ensure we're the only ones writing to the config
synchronized (Via.getPlatform().getConfigurationProvider()) {
servers.put(key, serverPing.getVersion().getProtocol());
}
// Save
Via.getPlatform().getConfigurationProvider().saveConfig();
} }
// Ensure we're the only ones writing to the config
synchronized (Via.getPlatform().getConfigurationProvider()) {
servers.put(key, serverPing.getVersion().getProtocol());
}
// Save
Via.getPlatform().getConfigurationProvider().saveConfig();
}
} }
}); });
} }