3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00
# Conflicts:
#	src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/ProtocolSnapshotTo1_10.java
Dieser Commit ist enthalten in:
Matsv 2016-08-10 20:14:11 +02:00
Commit 04d87ebba7
3 geänderte Dateien mit 118 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,51 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
import com.google.common.base.Optional;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import java.util.List;
public class MetadataRewriter {
public static int rewriteEntityType(int currentType, List<Metadata> metadata) {
if (currentType == 68) {
// ElderGuardian - 4
Optional<Metadata> options = getById(metadata, 12);
if (options.isPresent()) {
if ((((byte) options.get().getValue()) & 0x04) == 0x04) {
return 4;
}
}
}
if (currentType == 51) {
// WitherSkeleton - 5
// Stray - 6
Optional<Metadata> options = getById(metadata, 12);
if (options.isPresent()) {
if (((int) options.get().getValue()) == 1) {
return 5;
}
if (((int) options.get().getValue()) == 2) {
return 6;
}
}
}
if (currentType == 54) {
// ZombieVillager - 27
// Husk - 23
}
if (currentType == 100) {
// SkeletonHorse - 28
// ZombieHorse - 29
// Donkey - 31
// Mule - 32
}
return currentType;
}
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
for (Metadata metadata : metadatas) {
if (metadata.getId() == id) return Optional.of(metadata);
}
return Optional.absent();
}
}

Datei anzeigen

@ -3,11 +3,14 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
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.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_9;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_10.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage.EntityTracker;
public class ProtocolSnapshotTo1_10 extends Protocol {
@Override
@ -21,7 +24,24 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.UNSIGNED_BYTE, Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Register Type ID
wrapper.user().get(EntityTracker.class).getClientEntityTypes().put(wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 1));
}
});
}
});
@ -40,10 +60,35 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
});
}
});
// Metadata packet
registerOutgoing(State.PLAY, 0x39, 0x39, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_9.METADATA_LIST); // 1 - Metadata list
}
});
// Destroy entities
registerOutgoing(State.PLAY, 0x30, 0x30, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
wrapper.user().get(EntityTracker.class).removeEntity(entity);
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker(userConnection));
}
}

Datei anzeigen

@ -0,0 +1,21 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage;
import lombok.Getter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Getter
public class EntityTracker extends StoredObject {
private final Map<Integer, Integer> clientEntityTypes = new ConcurrentHashMap<>();
public EntityTracker(UserConnection user) {
super(user);
}
public void removeEntity(Integer entityID) {
clientEntityTypes.remove(entityID);
}
}