3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-08 09:10:10 +01:00

Entity rewriter cleanup

Dieser Commit ist enthalten in:
KennyTV 2020-02-07 22:32:24 +01:00
Ursprung 57602f2cee
Commit a4ed18f59b
24 geänderte Dateien mit 602 neuen und 715 gelöschten Zeilen

Datei anzeigen

@ -1,24 +1,23 @@
package nl.matsv.viabackwards.api.entities.storage; package nl.matsv.viabackwards.api.entities.storage;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriterBase;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.util.Optional;
import java.util.function.Supplier; import java.util.function.Supplier;
public class EntityPositionHandler { public class EntityPositionHandler {
public static final double RELATIVE_MOVE_FACTOR = 32 * 128; public static final double RELATIVE_MOVE_FACTOR = 32 * 128;
private final EntityRewriter<?> entityRewriter; private final EntityRewriterBase<?> entityRewriter;
private final Class<? extends EntityPositionStorage> storageClass; private final Class<? extends EntityPositionStorage> storageClass;
private final Supplier<? extends EntityPositionStorage> storageSupplier; private final Supplier<? extends EntityPositionStorage> storageSupplier;
private boolean warnedForMissingEntity; private boolean warnedForMissingEntity;
public EntityPositionHandler(EntityRewriter<?> entityRewriter, public EntityPositionHandler(EntityRewriterBase<?> entityRewriter,
Class<? extends EntityPositionStorage> storageClass, Supplier<? extends EntityPositionStorage> storageSupplier) { Class<? extends EntityPositionStorage> storageClass, Supplier<? extends EntityPositionStorage> storageSupplier) {
this.entityRewriter = entityRewriter; this.entityRewriter = entityRewriter;
this.storageClass = storageClass; this.storageClass = storageClass;
@ -32,8 +31,8 @@ public class EntityPositionHandler {
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception { public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<EntityTracker.StoredEntity> optStoredEntity = entityRewriter.getEntityTracker(wrapper.user()).getEntity(entityId); EntityTracker.StoredEntity storedEntity = entityRewriter.getEntityTracker(wrapper.user()).getEntity(entityId);
if (!optStoredEntity.isPresent()) { if (storedEntity == null) {
if (!Via.getConfig().isSuppressMetadataErrors()) { if (!Via.getConfig().isSuppressMetadataErrors()) {
ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing at position: " + x + " - " + y + " - " + z + " in " + storageClass.getSimpleName()); ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing at position: " + x + " - " + y + " - " + z + " in " + storageClass.getSimpleName());
// Reports were getting too much :> // Reports were getting too much :>
@ -49,7 +48,6 @@ public class EntityPositionHandler {
return; return;
} }
EntityTracker.StoredEntity storedEntity = optStoredEntity.get();
EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass); EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass);
if (positionStorage == null) { if (positionStorage == null) {
ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName()); ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName());
@ -61,13 +59,13 @@ public class EntityPositionHandler {
} }
public EntityPositionStorage getStorage(UserConnection user, int entityId) { public EntityPositionStorage getStorage(UserConnection user, int entityId) {
Optional<EntityTracker.StoredEntity> optEntity = user.get(EntityTracker.class).get(entityRewriter.getProtocol()).getEntity(entityId); EntityTracker.StoredEntity storedEntity = user.get(EntityTracker.class).get(entityRewriter.getProtocol()).getEntity(entityId);
EntityPositionStorage storedEntity; EntityPositionStorage entityStorage;
if (!optEntity.isPresent() || (storedEntity = optEntity.get().get(EntityPositionStorage.class)) == null) { if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage.class)) == null) {
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId + " in " + storageClass.getSimpleName()); ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId + " in " + storageClass.getSimpleName());
return null; return null;
} }
return storedEntity; return entityStorage;
} }
public static void writeFacingAngles(PacketWrapper wrapper, double x, double y, double z, double targetX, double targetY, double targetZ) { public static void writeFacingAngles(PacketWrapper wrapper, double x, double y, double z, double targetX, double targetY, double targetZ) {

Datei anzeigen

@ -16,7 +16,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject { public class EntityTracker extends StoredObject {
@ -50,12 +49,8 @@ public class EntityTracker extends StoredObject {
return storedEntity != null ? storedEntity.getType() : null; return storedEntity != null ? storedEntity.getType() : null;
} }
public Optional<StoredEntity> getEntity(int id) { public StoredEntity getEntity(int id) {
return Optional.ofNullable(entityMap.get(id)); return entityMap.get(id);
}
public boolean containsEntity(int id) {
return entityMap.containsKey(id);
} }
} }

Datei anzeigen

@ -1,180 +1,79 @@
/*
* Copyright (c) 2016 Matsv
*
* 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 nl.matsv.viabackwards.api.rewriters; package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerEvent;
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerSettings;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.entities.ObjectType;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewriter<T> { public abstract class EntityRewriter<T extends BackwardsProtocol> extends EntityRewriterBase<T> {
private final Map<EntityType, EntityData> entityTypes = new ConcurrentHashMap<>();
private final Map<ObjectType, EntityData> objectTypes = new ConcurrentHashMap<>();
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
private MetaType displayNameMetaType = MetaType1_9.String;
private int displayNameIndex = 2;
private boolean isDisplayNameJson;
protected EntityRewriter(T protocol) { protected EntityRewriter(T protocol) {
super(protocol); super(protocol, MetaType1_14.OptChat, 2, true);
} }
protected EntityType getEntityType(UserConnection connection, int id) { protected EntityRewriter(T protocol, MetaType displayType) {
return getEntityTracker(connection).getEntityType(id); super(protocol, displayType, 2, true);
} }
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception { public void registerSpawnTrackerWithData(int oldPacketId, int newPacketId, EntityType fallingBlockType, ItemRewriter itemRewriter) {
getEntityTracker(wrapper.user()).trackEntityType(entityId, type); protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - Entity UUID
map(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 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(wrapper -> {
int typeId = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = getTypeFromId(typeId);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
int oldTypeId = getOldEntityId(entityType.getId());
if (typeId != oldTypeId) {
wrapper.set(Type.VAR_INT, 1, oldTypeId);
} }
protected boolean hasData(EntityType type) { if (entityType == fallingBlockType) {
return entityTypes.containsKey(type); int blockState = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, itemRewriter.toClientRewriter.rewrite(blockState));
}
});
}
});
} }
protected EntityData getEntityData(EntityType type) { public void registerSpawnTracker(int oldPacketId, int newPacketId) {
return entityTypes.get(type); protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
} @Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
handler(wrapper -> {
int typeId = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = getTypeFromId(typeId);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
protected EntityData getObjectData(ObjectType type) { int oldTypeId = getOldEntityId(entityType.getId());
return objectTypes.get(type); if (typeId != oldTypeId) {
wrapper.set(Type.VAR_INT, 1, oldTypeId);
} }
});
protected EntityData regEntType(EntityType oldEnt, EntityType replacement) {
return regEntType(oldEnt, (short) replacement.getId());
} }
});
private EntityData regEntType(EntityType oldEnt, short replacementId) {
EntityData data = new EntityData(oldEnt.getId(), false, replacementId, -1);
entityTypes.put(oldEnt, data);
return data;
}
protected EntityData regObjType(ObjectType oldObj, ObjectType replacement, int data) {
return regObjType(oldObj, (short) replacement.getId(), data);
}
private EntityData regObjType(ObjectType oldObj, short replacementId, int data) {
EntityData entData = new EntityData(oldObj.getId(), true, replacementId, data);
objectTypes.put(oldObj, entData);
return entData;
}
public MetaHandlerSettings registerMetaHandler() {
MetaHandlerSettings settings = new MetaHandlerSettings();
metaHandlers.add(settings);
return settings;
}
protected MetaStorage handleMeta(UserConnection user, int entityId, MetaStorage storage) throws Exception {
Optional<EntityTracker.StoredEntity> optEntity = getEntityTracker(user).getEntity(entityId);
if (!optEntity.isPresent()) {
if (!Via.getConfig().isSuppressMetadataErrors()) {
ViaBackwards.getPlatform().getLogger().warning("Metadata for entity id: " + entityId + " not sent because the entity doesn't exist. " + storage);
}
throw CancelException.CACHED;
}
EntityTracker.StoredEntity entity = optEntity.get();
EntityType type = entity.getType();
List<Metadata> newList = new ArrayList<>();
for (MetaHandlerSettings settings : metaHandlers) {
List<Metadata> extraData = null;
for (Metadata md : storage.getMetaDataList()) {
Metadata nmd = md;
MetaHandlerEvent event = null;
try {
if (settings.isGucci(type, nmd)) {
event = new MetaHandlerEvent(user, entity, nmd.getId(), nmd, storage);
nmd = settings.getHandler().handle(event);
if (event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
event.clearExtraData();
}
}
if (nmd == null) {
throw RemovedValueException.EX;
}
newList.add(nmd);
} catch (RemovedValueException e) {
// add the additionally created data here in case of an interruption
if (event != null && event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
}
} catch (Exception e) {
Logger log = ViaBackwards.getPlatform().getLogger();
log.warning("Unable to handle metadata " + nmd);
log.warning("Full metadata list " + storage);
e.printStackTrace();
}
}
List<Metadata> newData = new ArrayList<>(newList);
if (extraData != null) {
newData.addAll(extraData);
}
storage.setMetaDataList(newData);
newList.clear();
}
// Handle Entity Name
Metadata data = storage.get(displayNameIndex);
if (data != null) {
EntityData entityData = getEntityData(type);
if (entityData != null) {
if (entityData.getMobName() != null &&
(data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
String mobName = entityData.getMobName();
if (isDisplayNameJson) {
mobName = ChatRewriter.legacyTextToJson(mobName);
}
data.setValue(mobName);
}
}
}
return storage;
} }
/** /**
@ -213,171 +112,4 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> metaType) { protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> metaType) {
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); registerMetadataRewriter(oldPacketId, newPacketId, null, metaType);
} }
/**
* Helper method to handle a metadata list packet.
*/
protected void registerLegacyMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) {
map(oldMetaType, newMetaType);
} else {
map(newMetaType);
}
handler(wrapper -> {
List<Metadata> metadata = wrapper.get(newMetaType, 0);
wrapper.set(newMetaType, 0,
handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0), new MetaStorage(metadata)).getMetaDataList());
});
}
});
}
protected void registerLegacyMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> metaType) {
registerLegacyMetadataRewriter(oldPacketId, newPacketId, null, metaType);
}
/**
* Helper method to handle player, painting, or xp orb trackers without meta changes.
*/
protected void registerExtraTracker(int packetId, EntityType entityType, Type intType) {
getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() {
@Override
public void registerMap() {
map(intType); // 0 - Entity id
handler(wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType));
}
});
}
protected void registerExtraTracker(int packetId, EntityType entityType) {
registerExtraTracker(packetId, entityType, Type.VAR_INT);
}
/**
* Helper method to handle the destroy entities packet.
*/
protected void registerEntityDestroy(int oldPacketId, int newPacketId) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids
handler(wrapper -> {
EntityTracker.ProtocolEntityTracker tracker = getEntityTracker(wrapper.user());
for (int entity : wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0)) {
tracker.removeEntity(entity);
}
});
}
});
}
protected void registerEntityDestroy(int packetId) {
registerEntityDestroy(packetId, packetId);
}
protected PacketHandler getObjectTrackerHandler() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0)));
}
protected PacketHandler getTrackerHandler(Type intType, int typeIndex) {
return wrapper -> {
Number id = (Number) wrapper.get(intType, typeIndex);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getTypeFromId(id.intValue()));
};
}
protected PacketHandler getTrackerHandler() {
return getTrackerHandler(Type.VAR_INT, 1);
}
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) {
return wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType);
}
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = getEntityType(wrapper.user(), entityId);
MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0));
handleMeta(wrapper.user(), entityId, storage);
EntityData entityData = getEntityData(type);
if (entityData != null) {
int replacementId = getOldEntityId(entityData.getReplacementId());
wrapper.set(Type.VAR_INT, 1, replacementId);
if (entityData.hasBaseMeta()) {
entityData.getDefaultMeta().handle(storage);
}
}
// Rewrite Metadata
wrapper.set(metaType, 0, storage.getMetaDataList());
};
}
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) {
return wrapper -> {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
List<Metadata> metaDataList = handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(metaType, 0))).getMetaDataList();
wrapper.set(metaType, 0, metaDataList);
};
}
protected PacketHandler getDimensionHandler(int index) {
return wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, index);
clientWorld.setEnvironment(dimensionId);
};
}
public EntityTracker.ProtocolEntityTracker getEntityTracker(UserConnection user) {
return user.get(EntityTracker.class).get(getProtocol());
}
protected MetaType getDisplayNameMetaType() {
return displayNameMetaType;
}
protected void setDisplayNameMetaType(MetaType displayNameMetaType) {
this.displayNameMetaType = displayNameMetaType;
}
protected int getDisplayNameIndex() {
return displayNameIndex;
}
protected void setDisplayNameIndex(int displayNameIndex) {
this.displayNameIndex = displayNameIndex;
}
protected boolean isDisplayNameJson() {
return isDisplayNameJson;
}
protected void setDisplayNameJson(boolean displayNameJson) {
isDisplayNameJson = displayNameJson;
}
protected abstract EntityType getTypeFromId(int typeId);
protected EntityType getObjectTypeFromId(int typeId) {
return getTypeFromId(typeId);
}
// Only needs to be overriden when getMobSpawnTracker is used
protected Optional<Integer> getOptOldEntityId(int newId) {
return Optional.of(newId);
}
protected int getOldEntityId(int newId) {
return newId;
}
} }

Datei anzeigen

@ -0,0 +1,250 @@
package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerEvent;
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerSettings;
import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
private final Map<EntityType, EntityData> entityTypes = new ConcurrentHashMap<>();
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
private final MetaType displayNameMetaType;
private final int displayNameIndex;
private final boolean isDisplayNameJson;
protected EntityRewriterBase(T protocol) {
this(protocol, MetaType1_9.String, 2, false);
}
protected EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex, boolean isDisplayNameJson) {
super(protocol);
this.displayNameMetaType = displayNameMetaType;
this.displayNameIndex = displayNameIndex;
this.isDisplayNameJson = isDisplayNameJson;
}
protected EntityType getEntityType(UserConnection connection, int id) {
return getEntityTracker(connection).getEntityType(id);
}
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
getEntityTracker(wrapper.user()).trackEntityType(entityId, type);
}
protected boolean hasData(EntityType type) {
return entityTypes.containsKey(type);
}
protected EntityData getEntityData(EntityType type) {
return entityTypes.get(type);
}
protected EntityData mapEntity(EntityType oldType, EntityType replacement) {
EntityData data = new EntityData(oldType.getId(), false, replacement.getId(), -1);
entityTypes.put(oldType, data);
return data;
}
public MetaHandlerSettings registerMetaHandler() {
MetaHandlerSettings settings = new MetaHandlerSettings();
metaHandlers.add(settings);
return settings;
}
protected MetaStorage handleMeta(UserConnection user, int entityId, MetaStorage storage) throws Exception {
EntityTracker.StoredEntity storedEntity = getEntityTracker(user).getEntity(entityId);
if (storedEntity == null) {
if (!Via.getConfig().isSuppressMetadataErrors()) {
ViaBackwards.getPlatform().getLogger().warning("Metadata for entity id: " + entityId + " not sent because the entity doesn't exist. " + storage);
}
throw CancelException.CACHED;
}
EntityType type = storedEntity.getType();
List<Metadata> newList = new ArrayList<>();
for (MetaHandlerSettings settings : metaHandlers) {
List<Metadata> extraData = null;
for (Metadata md : storage.getMetaDataList()) {
Metadata nmd = md;
MetaHandlerEvent event = null;
try {
if (settings.isGucci(type, nmd)) {
event = new MetaHandlerEvent(user, storedEntity, nmd.getId(), nmd, storage);
nmd = settings.getHandler().handle(event);
if (event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
event.clearExtraData();
}
}
if (nmd == null) {
throw RemovedValueException.EX;
}
newList.add(nmd);
} catch (RemovedValueException e) {
// add the additionally created data here in case of an interruption
if (event != null && event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
}
} catch (Exception e) {
Logger log = ViaBackwards.getPlatform().getLogger();
log.warning("Unable to handle metadata " + nmd);
log.warning("Full metadata list " + storage);
e.printStackTrace();
}
}
List<Metadata> newData = new ArrayList<>(newList);
if (extraData != null) {
newData.addAll(extraData);
}
storage.setMetaDataList(newData);
newList.clear();
}
// Handle Entity Name
Metadata data = storage.get(displayNameIndex);
if (data != null) {
EntityData entityData = getEntityData(type);
if (entityData != null) {
if (entityData.getMobName() != null &&
(data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
String mobName = entityData.getMobName();
if (isDisplayNameJson) {
mobName = ChatRewriter.legacyTextToJson(mobName);
}
data.setValue(mobName);
}
}
}
return storage;
}
public void registerRespawn(int oldPacketId, int newPacketId) {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
});
}
});
}
public void registerJoinGame(int oldPacketId, int newPacketId, EntityType playerType) {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), playerType);
});
}
});
}
/**
* Helper method to handle player, painting, or xp orb trackers without meta changes.
*/
protected void registerExtraTracker(int packetId, EntityType entityType, Type intType) {
getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() {
@Override
public void registerMap() {
map(intType); // 0 - Entity id
handler(wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType));
}
});
}
protected void registerExtraTracker(int packetId, EntityType entityType) {
registerExtraTracker(packetId, entityType, Type.VAR_INT);
}
protected void registerEntityDestroy(int oldPacketId, int newPacketId) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids
handler(wrapper -> {
EntityTracker.ProtocolEntityTracker tracker = getEntityTracker(wrapper.user());
for (int entity : wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0)) {
tracker.removeEntity(entity);
}
});
}
});
}
protected void registerEntityDestroy(int packetId) {
registerEntityDestroy(packetId, packetId);
}
// ONLY TRACKS, DOESN'T REWRITE IDS
protected PacketHandler getTrackerHandler(Type intType, int typeIndex) {
return wrapper -> {
Number id = (Number) wrapper.get(intType, typeIndex);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getTypeFromId(id.intValue()));
};
}
protected PacketHandler getTrackerHandler() {
return getTrackerHandler(Type.VAR_INT, 1);
}
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) {
return wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType);
}
protected PacketHandler getDimensionHandler(int index) {
return wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, index);
clientWorld.setEnvironment(dimensionId);
};
}
public EntityTracker.ProtocolEntityTracker getEntityTracker(UserConnection user) {
return user.get(EntityTracker.class).get(getProtocol());
}
protected abstract EntityType getTypeFromId(int typeId);
protected int getOldEntityId(int newId) {
return newId;
}
}

Datei anzeigen

@ -11,15 +11,15 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.ShortTag;
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> { public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
protected static final CompoundTagConverter CONVERTER = new CompoundTagConverter(); protected static final CompoundTagConverter CONVERTER = new CompoundTagConverter();
protected final IdRewriteFunction oldRewriter; protected final IdRewriteFunction toClientRewriter;
protected final IdRewriteFunction newRewriter; protected final IdRewriteFunction toServerRewriter;
protected final String nbtTagName; protected final String nbtTagName;
protected final boolean jsonNameFormat; protected final boolean jsonNameFormat;
protected ItemRewriterBase(T protocol, IdRewriteFunction oldRewriter, IdRewriteFunction newRewriter, boolean jsonNameFormat) { protected ItemRewriterBase(T protocol, IdRewriteFunction toClientRewriter, IdRewriteFunction toServerRewriter, boolean jsonNameFormat) {
super(protocol); super(protocol);
this.oldRewriter = oldRewriter; this.toClientRewriter = toClientRewriter;
this.newRewriter = newRewriter; this.toServerRewriter = toServerRewriter;
this.jsonNameFormat = jsonNameFormat; this.jsonNameFormat = jsonNameFormat;
nbtTagName = "ViaBackwards|" + protocol.getClass().getSimpleName(); nbtTagName = "ViaBackwards|" + protocol.getClass().getSimpleName();
} }
@ -30,8 +30,8 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
public Item handleItemToClient(Item item) { public Item handleItemToClient(Item item) {
if (item == null) return null; if (item == null) return null;
if (oldRewriter != null) { if (toClientRewriter != null) {
item.setIdentifier(oldRewriter.rewrite(item.getIdentifier())); item.setIdentifier(toClientRewriter.rewrite(item.getIdentifier()));
} }
return item; return item;
} }
@ -41,8 +41,8 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
if (newRewriter != null) { if (toServerRewriter != null) {
item.setIdentifier(newRewriter.rewrite(item.getIdentifier())); item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier()));
} }
return item; return item;
} }
@ -64,8 +64,8 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
tag.remove(nbtTagName); tag.remove(nbtTagName);
} else { } else {
// Rewrite id normally // Rewrite id normally
if (newRewriter != null) { if (toServerRewriter != null) {
item.setIdentifier(newRewriter.rewrite(item.getIdentifier())); item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier()));
} }
} }
return item; return item;

Datei anzeigen

@ -0,0 +1,102 @@
package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.entities.ObjectType;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends EntityRewriterBase<T> {
private final Map<ObjectType, EntityData> objectTypes = new ConcurrentHashMap<>();
protected LegacyEntityRewriter(T protocol) {
super(protocol);
}
protected LegacyEntityRewriter(T protocol, MetaType displayType, boolean isDisplayJson) {
super(protocol, displayType, 2, isDisplayJson);
}
protected EntityData mapObjectType(ObjectType oldObjectType, ObjectType replacement, int data) {
EntityData entData = new EntityData(oldObjectType.getId(), true, replacement.getId(), data);
objectTypes.put(oldObjectType, entData);
return entData;
}
protected EntityData getObjectData(ObjectType type) {
return objectTypes.get(type);
}
protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) {
map(oldMetaType, newMetaType);
} else {
map(newMetaType);
}
handler(wrapper -> {
List<Metadata> metadata = wrapper.get(newMetaType, 0);
wrapper.set(newMetaType, 0,
handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0), new MetaStorage(metadata)).getMetaDataList());
});
}
});
}
protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> metaType) {
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType);
}
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = getEntityType(wrapper.user(), entityId);
MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0));
handleMeta(wrapper.user(), entityId, storage);
EntityData entityData = getEntityData(type);
if (entityData != null) {
int replacementId = getOldEntityId(entityData.getReplacementId());
wrapper.set(Type.VAR_INT, 1, replacementId);
if (entityData.hasBaseMeta()) {
entityData.getDefaultMeta().handle(storage);
}
}
// Rewrite Metadata
wrapper.set(metaType, 0, storage.getMetaDataList());
};
}
protected PacketHandler getObjectTrackerHandler() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0)));
}
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) {
return wrapper -> {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
List<Metadata> metaDataList = handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(metaType, 0))).getMetaDataList();
wrapper.set(metaType, 0, metaDataList);
};
}
protected EntityType getObjectTypeFromId(int typeId) {
return getTypeFromId(typeId);
}
}

Datei anzeigen

@ -1,6 +1,9 @@
package nl.matsv.viabackwards.api.rewriters; package nl.matsv.viabackwards.api.rewriters;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public abstract class RecipeRewriter { public abstract class RecipeRewriter {
@ -11,4 +14,20 @@ public abstract class RecipeRewriter {
} }
public abstract void handle(PacketWrapper wrapper, String type) throws Exception; public abstract void handle(PacketWrapper wrapper, String type) throws Exception;
public void registerDefaultHandler(int oldId, int newId) {
rewriter.getProtocol().registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
String id = wrapper.passthrough(Type.STRING); // Recipe Identifier
handle(wrapper, type);
}
});
}
});
}
} }

Datei anzeigen

@ -409,8 +409,8 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
WindowTracker tracker = user.get(WindowTracker.class); WindowTracker tracker = user.get(WindowTracker.class);
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol()); EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol());
Optional<EntityTracker.StoredEntity> optEntity = entTracker.getEntity(tracker.getEntityId()); EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId());
return optEntity.isPresent() && optEntity.get().getType().is(Entity1_11Types.EntityType.LIAMA); return storedEntity != null && storedEntity.getType().is(Entity1_11Types.EntityType.LIAMA);
} }
return false; return false;
} }
@ -419,9 +419,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
WindowTracker tracker = user.get(WindowTracker.class); WindowTracker tracker = user.get(WindowTracker.class);
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol()); EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol());
Optional<EntityTracker.StoredEntity> optEntity = entTracker.getEntity(tracker.getEntityId()); EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId());
if (optEntity.isPresent()) if (storedEntity != null)
return Optional.of(optEntity.get().get(ChestedHorseStorage.class)); return Optional.of(storedEntity.get(ChestedHorseStorage.class));
} }
return Optional.empty(); return Optional.empty();
} }

Datei anzeigen

@ -14,7 +14,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
@ -34,7 +34,7 @@ import us.myles.ViaVersion.packets.State;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> { public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11> {
public EntityPackets1_11(Protocol1_10To1_11 protocol) { public EntityPackets1_11(Protocol1_10To1_11 protocol) {
super(protocol); super(protocol);
@ -229,7 +229,7 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
registerEntityDestroy(0x30); registerEntityDestroy(0x30);
// Metadata packet // Metadata packet
registerLegacyMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST);
// Entity Status // Entity Status
protocol.registerOutgoing(State.PLAY, 0x1B, 0x1B, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x1B, 0x1B, new PacketRemapper() {
@ -258,30 +258,30 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Guardian // Guardian
regEntType(Entity1_11Types.EntityType.ELDER_GUARDIAN, Entity1_11Types.EntityType.GUARDIAN); mapEntity(Entity1_11Types.EntityType.ELDER_GUARDIAN, Entity1_11Types.EntityType.GUARDIAN);
// Skeletons // Skeletons
regEntType(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1))); mapEntity(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1)));
regEntType(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2))); mapEntity(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2)));
// Zombies // Zombies
regEntType(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 6)); mapEntity(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 6));
regEntType(Entity1_11Types.EntityType.ZOMBIE_VILLAGER, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1)); mapEntity(Entity1_11Types.EntityType.ZOMBIE_VILLAGER, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1));
// Horses // Horses
regEntType(Entity1_11Types.EntityType.HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(0))); // Nob able to ride the horse without having the MetaType sent. mapEntity(Entity1_11Types.EntityType.HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(0))); // Nob able to ride the horse without having the MetaType sent.
regEntType(Entity1_11Types.EntityType.DONKEY, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntity(Entity1_11Types.EntityType.DONKEY, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
regEntType(Entity1_11Types.EntityType.MULE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2))); mapEntity(Entity1_11Types.EntityType.MULE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2)));
regEntType(Entity1_11Types.EntityType.SKELETON_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4))); mapEntity(Entity1_11Types.EntityType.SKELETON_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4)));
regEntType(Entity1_11Types.EntityType.ZOMBIE_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3))); mapEntity(Entity1_11Types.EntityType.ZOMBIE_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
// New mobs // New mobs
regEntType(Entity1_11Types.EntityType.EVOCATION_FANGS, Entity1_11Types.EntityType.SHULKER); mapEntity(Entity1_11Types.EntityType.EVOCATION_FANGS, Entity1_11Types.EntityType.SHULKER);
regEntType(Entity1_11Types.EntityType.EVOCATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Evoker"); mapEntity(Entity1_11Types.EntityType.EVOCATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Evoker");
regEntType(Entity1_11Types.EntityType.VEX, Entity1_11Types.EntityType.BAT).mobName("Vex"); mapEntity(Entity1_11Types.EntityType.VEX, Entity1_11Types.EntityType.BAT).mobName("Vex");
regEntType(Entity1_11Types.EntityType.VINDICATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Vindicator").spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession mapEntity(Entity1_11Types.EntityType.VINDICATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Vindicator").spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession
regEntType(Entity1_11Types.EntityType.LIAMA, Entity1_11Types.EntityType.HORSE).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntity(Entity1_11Types.EntityType.LIAMA, Entity1_11Types.EntityType.HORSE).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
regEntType(Entity1_11Types.EntityType.LIAMA_SPIT, Entity1_11Types.EntityType.SNOWBALL); mapEntity(Entity1_11Types.EntityType.LIAMA_SPIT, Entity1_11Types.EntityType.SNOWBALL);
regObjType(Entity1_11Types.ObjectType.LIAMA_SPIT, Entity1_11Types.ObjectType.SNOWBALL, -1); mapObjectType(Entity1_11Types.ObjectType.LIAMA_SPIT, Entity1_11Types.ObjectType.SNOWBALL, -1);
// Replace with endertorchthingies // Replace with endertorchthingies
regObjType(Entity1_11Types.ObjectType.EVOCATION_FANGS, Entity1_11Types.ObjectType.FALLING_BLOCK, 198 | 1 << 12); mapObjectType(Entity1_11Types.ObjectType.EVOCATION_FANGS, Entity1_11Types.ObjectType.FALLING_BLOCK, 198 | 1 << 12);
// Handle ElderGuardian & target metadata // Handle ElderGuardian & target metadata
registerMetaHandler().filter(Entity1_11Types.EntityType.GUARDIAN, true, 12).handle(e -> { registerMetaHandler().filter(Entity1_11Types.EntityType.GUARDIAN, true, 12).handle(e -> {

Datei anzeigen

@ -13,7 +13,7 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
@ -33,7 +33,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> { public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12> {
public EntityPackets1_12(Protocol1_11_1To1_12 protocol) { public EntityPackets1_12(Protocol1_11_1To1_12 protocol) {
super(protocol); super(protocol);
@ -200,7 +200,7 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
registerEntityDestroy(0x31, 0x30); registerEntityDestroy(0x31, 0x30);
// Metadata packet // Metadata packet
registerLegacyMetadataRewriter(0x3B, 0x39, Types1_12.METADATA_LIST); registerMetadataRewriter(0x3B, 0x39, Types1_12.METADATA_LIST);
// Entity Properties // Entity Properties
protocol.registerOutgoing(State.PLAY, 0x4D, 0x4A, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x4D, 0x4A, new PacketRemapper() {
@ -245,8 +245,8 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
regEntType(Entity1_12Types.EntityType.PARROT, Entity1_12Types.EntityType.BAT).mobName("Parrot").spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00))); mapEntity(Entity1_12Types.EntityType.PARROT, Entity1_12Types.EntityType.BAT).mobName("Parrot").spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
regEntType(Entity1_12Types.EntityType.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).mobName("Illusioner"); mapEntity(Entity1_12Types.EntityType.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).mobName("Illusioner");
// Handle Illager // Handle Illager
registerMetaHandler().filter(Entity1_12Types.EntityType.EVOCATION_ILLAGER, true, 12).removed(); registerMetaHandler().filter(Entity1_12Types.EntityType.EVOCATION_ILLAGER, true, 12).removed();

Datei anzeigen

@ -12,7 +12,7 @@ package nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -26,7 +26,7 @@ import us.myles.ViaVersion.packets.State;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> { public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11_1> {
public EntityPackets1_11_1(Protocol1_11To1_11_1 protocol) { public EntityPackets1_11_1(Protocol1_11To1_11_1 protocol) {
super(protocol); super(protocol);
@ -151,7 +151,7 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
registerEntityDestroy(0x30); registerEntityDestroy(0x30);
// Metadata packet // Metadata packet
registerLegacyMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST);
} }
@Override @Override

Datei anzeigen

@ -3,7 +3,7 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityPositionHandler; import nl.matsv.viabackwards.api.entities.storage.EntityPositionHandler;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
@ -26,7 +26,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> { public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13> {
public EntityPackets1_13(Protocol1_12_2To1_13 protocol) { public EntityPackets1_13(Protocol1_12_2To1_13 protocol) {
super(protocol); super(protocol);
@ -223,7 +223,7 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
registerEntityDestroy(0x35, 0x32); registerEntityDestroy(0x35, 0x32);
// Entity Metadata packet // Entity Metadata packet
registerLegacyMetadataRewriter(0x3F, 0x3C, Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); registerMetadataRewriter(0x3F, 0x3C, Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
// Face Player (new packet) // Face Player (new packet)
protocol.out(State.PLAY, 0x31, -1, new PacketRemapper() { protocol.out(State.PLAY, 0x31, -1, new PacketRemapper() {
@ -287,25 +287,25 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Rewrite new Entity 'drowned' // Rewrite new Entity 'drowned'
regEntType(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned"); mapEntity(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
// Fishy // Fishy
regEntType(Entity1_13Types.EntityType.COD_MOB, Entity1_13Types.EntityType.SQUID).mobName("Cod"); mapEntity(Entity1_13Types.EntityType.COD_MOB, Entity1_13Types.EntityType.SQUID).mobName("Cod");
regEntType(Entity1_13Types.EntityType.SALMON_MOB, Entity1_13Types.EntityType.SQUID).mobName("Salmon"); mapEntity(Entity1_13Types.EntityType.SALMON_MOB, Entity1_13Types.EntityType.SQUID).mobName("Salmon");
regEntType(Entity1_13Types.EntityType.PUFFER_FISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish"); mapEntity(Entity1_13Types.EntityType.PUFFER_FISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish");
regEntType(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish"); mapEntity(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish");
// Phantom // Phantom
regEntType(Entity1_13Types.EntityType.PHANTOM, Entity1_13Types.EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> { mapEntity(Entity1_13Types.EntityType.PHANTOM, Entity1_13Types.EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> {
// The phantom is grey/blue so let's do yellow/blue // The phantom is grey/blue so let's do yellow/blue
storage.add(new Metadata(15, MetaType1_12.VarInt, 3)); storage.add(new Metadata(15, MetaType1_12.VarInt, 3));
}); });
// Dolphin // Dolphin
regEntType(Entity1_13Types.EntityType.DOLPHIN, Entity1_13Types.EntityType.SQUID).mobName("Dolphin"); mapEntity(Entity1_13Types.EntityType.DOLPHIN, Entity1_13Types.EntityType.SQUID).mobName("Dolphin");
// Turtle // Turtle
regEntType(Entity1_13Types.EntityType.TURTLE, Entity1_13Types.EntityType.OCELOT).mobName("Turtle"); mapEntity(Entity1_13Types.EntityType.TURTLE, Entity1_13Types.EntityType.OCELOT).mobName("Turtle");
// Rewrite Meta types // Rewrite Meta types
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {

Datei anzeigen

@ -53,6 +53,14 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0B, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
// Open window // Open window
protocol.registerOutgoing(State.PLAY, 0x2E, 0x14, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x2E, 0x14, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -5,7 +5,7 @@ import nl.matsv.viabackwards.api.entities.meta.MetaHandler;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.EntityPositionHandler; import nl.matsv.viabackwards.api.entities.storage.EntityPositionHandler;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.EntityTypeMapping; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
@ -29,12 +29,12 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> { public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14> {
private EntityPositionHandler positionHandler; private EntityPositionHandler positionHandler;
public EntityPackets1_14(Protocol1_13_2To1_14 protocol) { public EntityPackets1_14(Protocol1_13_2To1_14 protocol) {
super(protocol); super(protocol, MetaType1_13_2.OptChat, true);
} }
@Override @Override
@ -213,12 +213,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
map(Type.DOUBLE); // Needs to be mapped for the position cache map(Type.DOUBLE); // Needs to be mapped for the position cache
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
handler(new PacketHandler() { handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.XP_ORB));
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.XP_ORB);
}
});
} }
}); });
@ -231,12 +226,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
map(Type.DOUBLE); // Needs to be mapped for the position cache map(Type.DOUBLE); // Needs to be mapped for the position cache
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
handler(new PacketHandler() { handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.LIGHTNING_BOLT));
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.LIGHTNING_BOLT);
}
});
} }
}); });
@ -251,12 +241,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
map(Type.BYTE); map(Type.BYTE);
// Track entity // Track entity
handler(new PacketHandler() { handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.PAINTING));
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.PAINTING);
}
});
} }
}); });
@ -282,7 +267,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
registerEntityDestroy(0x37, 0x35); registerEntityDestroy(0x37, 0x35);
// Entity Metadata packet // Entity Metadata packet
registerLegacyMetadataRewriter(0x43, 0x3F, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST); registerMetadataRewriter(0x43, 0x3F, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
// Join game // Join game
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
@ -330,16 +315,13 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
setDisplayNameJson(true); mapEntity(Entity1_14Types.EntityType.CAT, Entity1_14Types.EntityType.OCELOT).mobName("Cat");
setDisplayNameMetaType(MetaType1_13_2.OptChat); mapEntity(Entity1_14Types.EntityType.TRADER_LLAMA, Entity1_14Types.EntityType.LLAMA).mobName("Trader Llama");
mapEntity(Entity1_14Types.EntityType.FOX, Entity1_14Types.EntityType.WOLF).mobName("Fox");
regEntType(Entity1_14Types.EntityType.CAT, Entity1_14Types.EntityType.OCELOT).mobName("Cat"); mapEntity(Entity1_14Types.EntityType.PANDA, Entity1_14Types.EntityType.POLAR_BEAR).mobName("Panda");
regEntType(Entity1_14Types.EntityType.TRADER_LLAMA, Entity1_14Types.EntityType.LLAMA).mobName("Trader Llama"); mapEntity(Entity1_14Types.EntityType.PILLAGER, Entity1_14Types.EntityType.VILLAGER).mobName("Pillager");
regEntType(Entity1_14Types.EntityType.FOX, Entity1_14Types.EntityType.WOLF).mobName("Fox"); mapEntity(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).mobName("Wandering Trader");
regEntType(Entity1_14Types.EntityType.PANDA, Entity1_14Types.EntityType.POLAR_BEAR).mobName("Panda"); mapEntity(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).mobName("Ravager");
regEntType(Entity1_14Types.EntityType.PILLAGER, Entity1_14Types.EntityType.VILLAGER).mobName("Pillager");
regEntType(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).mobName("Wandering Trader");
regEntType(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).mobName("Ravager");
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();

Datei anzeigen

@ -17,7 +17,6 @@ public class PlayerPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Server Difficulty // Server Difficulty
protocol.registerOutgoing(State.PLAY, 0x0D, 0x0D, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x0D, 0x0D, new PacketRemapper() {
@Override @Override
@ -44,19 +43,6 @@ public class PlayerPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
} }
}); });
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0B, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
getProtocol().getBlockItemPackets().handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
});
}
});
// Player Digging // Player Digging
protocol.registerIncoming(State.PLAY, 0x1A, 0x18, new PacketRemapper() { protocol.registerIncoming(State.PLAY, 0x1A, 0x18, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -12,8 +12,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import java.util.Optional;
public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> { public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
public SoundPackets1_14(Protocol1_13_2To1_14 protocol) { public SoundPackets1_14(Protocol1_13_2To1_14 protocol) {
@ -57,18 +55,18 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
int category = wrapper.read(Type.VAR_INT); int category = wrapper.read(Type.VAR_INT);
int entityId = wrapper.read(Type.VAR_INT); int entityId = wrapper.read(Type.VAR_INT);
Optional<EntityTracker.StoredEntity> optEntity = wrapper.user().get(EntityTracker.class).get(protocol).getEntity(entityId); EntityTracker.StoredEntity storedEntity = wrapper.user().get(EntityTracker.class).get(protocol).getEntity(entityId);
EntityPositionStorage1_14 storedEntity; EntityPositionStorage1_14 entityStorage;
if (!optEntity.isPresent() || (storedEntity = optEntity.get().get(EntityPositionStorage1_14.class)) == null) { if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId); ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
return; return;
} }
float volume = wrapper.read(Type.FLOAT); float volume = wrapper.read(Type.FLOAT);
float pitch = wrapper.read(Type.FLOAT); float pitch = wrapper.read(Type.FLOAT);
int x = (int) (storedEntity.getX() * 8D); int x = (int) (entityStorage.getX() * 8D);
int y = (int) (storedEntity.getY() * 8D); int y = (int) (entityStorage.getY() * 8D);
int z = (int) (storedEntity.getZ() * 8D); int z = (int) (entityStorage.getZ() * 8D);
PacketWrapper soundPacket = wrapper.create(0x4D); PacketWrapper soundPacket = wrapper.create(0x4D);
soundPacket.write(Type.VAR_INT, newId); soundPacket.write(Type.VAR_INT, newId);

Datei anzeigen

@ -2,7 +2,7 @@ package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_13Types;
@ -16,7 +16,7 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> { public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13_1> {
public EntityPackets1_13_1(Protocol1_13To1_13_1 protocol) { public EntityPackets1_13_1(Protocol1_13To1_13_1 protocol) {
super(protocol); super(protocol);
@ -153,7 +153,7 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
registerEntityDestroy(0x35); registerEntityDestroy(0x35);
// Entity Metadata packet // Entity Metadata packet
registerLegacyMetadataRewriter(0x3F, 0x3F, Types1_13.METADATA_LIST); registerMetadataRewriter(0x3F, 0x3F, Types1_13.METADATA_LIST);
} }
@Override @Override

Datei anzeigen

@ -70,7 +70,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
map(Type.VAR_INT); // Sound Id map(Type.VAR_INT); // Sound Id
handler(wrapper -> { handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0); int id = wrapper.get(Type.VAR_INT, 0);
int newId = nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings.soundMappings.getNewId(id); int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) { if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId); wrapper.set(Type.VAR_INT, 0, newId);
} }
@ -85,7 +85,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
map(Type.VAR_INT); // Sound Id map(Type.VAR_INT); // Sound Id
handler(wrapper -> { handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0); int id = wrapper.get(Type.VAR_INT, 0);
int newId = nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings.soundMappings.getNewId(id); int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) { if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId); wrapper.set(Type.VAR_INT, 0, newId);
} }

Datei anzeigen

@ -1,7 +1,6 @@
package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets; package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.RecipeRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
@ -32,6 +31,17 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId);
// Declare Recipes
new RecipeRewriter1_15(this).registerDefaultHandler(0x5B, 0x5A);
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
// Set cooldown // Set cooldown
itemRewriter.registerSetCooldown(0x18, 0x17, BlockItemPackets1_15::getOldItemId); itemRewriter.registerSetCooldown(0x18, 0x17, BlockItemPackets1_15::getOldItemId);
@ -84,27 +94,6 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
// Entity Equipment Packet // Entity Equipment Packet
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x46); itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x46);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x5B, 0x5A, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
private final RecipeRewriter recipeHandler = new RecipeRewriter1_15(BlockItemPackets1_15.this);
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
String id = wrapper.passthrough(Type.STRING); // Recipe Identifier
recipeHandler.handle(wrapper, type);
}
}
});
}
});
// Incoming packets
// Click window packet // Click window packet
itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09);

Datei anzeigen

@ -7,14 +7,12 @@ import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMappin
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.Particle;
@ -36,9 +34,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
protocol.registerOutgoing(State.PLAY, 0x49, 0x48, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x49, 0x48, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
float health = wrapper.passthrough(Type.FLOAT); float health = wrapper.passthrough(Type.FLOAT);
if (health > 0) return; if (health > 0) return;
if (!wrapper.user().get(ImmediateRespawn.class).isImmediateRespawn()) return; if (!wrapper.user().get(ImmediateRespawn.class).isImmediateRespawn()) return;
@ -47,7 +43,6 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
PacketWrapper statusPacket = wrapper.create(0x04); PacketWrapper statusPacket = wrapper.create(0x04);
statusPacket.write(Type.VAR_INT, 0); statusPacket.write(Type.VAR_INT, 0);
statusPacket.sendToServer(Protocol1_14_4To1_15.class); statusPacket.sendToServer(Protocol1_14_4To1_15.class);
}
}); });
} }
}); });
@ -58,48 +53,16 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); map(Type.UNSIGNED_BYTE);
map(Type.FLOAT); map(Type.FLOAT);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) { if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) {
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.get(Type.FLOAT, 0) == 1); wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.get(Type.FLOAT, 0) == 1);
} }
}
}); });
} }
}); });
// Spawn Object // Spawn Object
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { registerSpawnTrackerWithData(0x00, 0x00, Entity1_15Types.EntityType.FALLING_BLOCK, protocol.getBlockItemPackets());
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.VAR_INT); // 2 - Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(getTrackerHandler());
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int typeId = wrapper.get(Type.VAR_INT, 1);
Entity1_14Types.EntityType entityType = Entity1_14Types.getTypeFromId(getOldEntityId(typeId));
wrapper.set(Type.VAR_INT, 1, entityType.getId());
if (entityType == Entity1_14Types.EntityType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0);
int combined = Protocol1_14_4To1_15.getNewBlockStateId(blockState);
wrapper.set(Type.INT, 0, combined);
}
}
});
}
});
// Spawn mob packet // Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
@ -119,14 +82,11 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
create(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one create(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Type.VAR_INT, 1);
Entity1_15Types.EntityType entityType = Entity1_15Types.getTypeFromId(type); Entity1_15Types.EntityType entityType = Entity1_15Types.getTypeFromId(type);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType); addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type)); wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type));
}
}); });
} }
}); });
@ -137,13 +97,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
public void registerMap() { public void registerMap() {
map(Type.INT); map(Type.INT);
map(Type.LONG, Type.NOTHING); // Seed map(Type.LONG, Type.NOTHING); // Seed
handler(new PacketHandler() { handler(wrapper -> wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.INT, 0)));
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
}
});
} }
}); });
@ -165,26 +119,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
handler(getTrackerHandler(Entity1_15Types.EntityType.PLAYER, Type.INT)); handler(getTrackerHandler(Entity1_15Types.EntityType.PLAYER, Type.INT));
handler(getDimensionHandler(1)); handler(getDimensionHandler(1));
handler(new PacketHandler() { handler(wrapper -> wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.read(Type.BOOLEAN)));
@Override
public void handle(PacketWrapper wrapper) throws Exception {
boolean immediateRespawn = wrapper.read(Type.BOOLEAN);
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(immediateRespawn);
}
});
}
});
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
getProtocol().getBlockItemPackets().handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
});
} }
}); });
@ -226,9 +161,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.INT); map(Type.INT);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = getEntityType(wrapper.user(), entityId); EntityType entityType = getEntityType(wrapper.user(), entityId);
if (entityType != Entity1_15Types.EntityType.BEE) return; if (entityType != Entity1_15Types.EntityType.BEE) return;
@ -261,7 +194,6 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
if (newSize != size) { if (newSize != size) {
wrapper.set(Type.INT, 0, newSize); wrapper.set(Type.INT, 0, newSize);
} }
}
}); });
} }
}); });
@ -269,15 +201,12 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
setDisplayNameJson(true);
setDisplayNameMetaType(MetaType1_14.OptChat);
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
MetaType type = meta.getMetaType(); MetaType type = meta.getMetaType();
if (type == MetaType1_14.Slot) { if (type == MetaType1_14.Slot) {
Item item = (Item) meta.getValue(); Item item = (Item) meta.getValue();
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item)); meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
} else if (type == MetaType1_14.BlockID) { } else if (type == MetaType1_14.BlockID) {
int blockstate = (int) meta.getValue(); int blockstate = (int) meta.getValue();
meta.setValue(Protocol1_14_4To1_15.getNewBlockStateId(blockstate)); meta.setValue(Protocol1_14_4To1_15.getNewBlockStateId(blockstate));
@ -301,7 +230,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 15).removed(); registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 15).removed();
registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 16).removed(); registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 16).removed();
regEntType(Entity1_15Types.EntityType.BEE, Entity1_15Types.EntityType.PUFFER_FISH).mobName("Bee").spawnMetadata(storage -> { mapEntity(Entity1_15Types.EntityType.BEE, Entity1_15Types.EntityType.PUFFER_FISH).mobName("Bee").spawnMetadata(storage -> {
storage.add(new Metadata(14, MetaType1_14.Boolean, false)); storage.add(new Metadata(14, MetaType1_14.Boolean, false));
storage.add(new Metadata(15, MetaType1_14.VarInt, 2)); storage.add(new Metadata(15, MetaType1_14.VarInt, 2));
}); });

Datei anzeigen

@ -1,7 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.packets; package nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.packets;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1; import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.entities.Entity1_14Types;
@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class EntityPackets1_14_1 extends EntityRewriter<Protocol1_14To1_14_1> { public class EntityPackets1_14_1 extends LegacyEntityRewriter<Protocol1_14To1_14_1> {
public EntityPackets1_14_1(Protocol1_14To1_14_1 protocol) { public EntityPackets1_14_1(Protocol1_14To1_14_1 protocol) {
super(protocol); super(protocol);
@ -74,7 +74,7 @@ public class EntityPackets1_14_1 extends EntityRewriter<Protocol1_14To1_14_1> {
}); });
// Entity Metadata // Entity Metadata
registerLegacyMetadataRewriter(0x43, 0x43, Types1_14.METADATA_LIST); registerMetadataRewriter(0x43, 0x43, Types1_14.METADATA_LIST);
} }
@Override @Override

Datei anzeigen

@ -1,15 +1,12 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets; package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.RecipeRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter;
@ -30,6 +27,17 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId);
// Declare Recipes
new RecipeRewriter1_15(this).registerDefaultHandler(0x5B, 0x5B);
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
// Set cooldown // Set cooldown
itemRewriter.registerSetCooldown(0x18, 0x18, BlockItemPackets1_16::getOldItemId); itemRewriter.registerSetCooldown(0x18, 0x18, BlockItemPackets1_16::getOldItemId);
@ -79,26 +87,6 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
// Entity Equipment Packet // Entity Equipment Packet
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x47); itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x47);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x5B, 0x5B, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
private final RecipeRewriter recipeHandler = new RecipeRewriter1_15(BlockItemPackets1_16.this);
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
String id = wrapper.passthrough(Type.STRING); // Recipe Identifier
recipeHandler.handle(wrapper, type);
}
}
});
}
});
// Click window packet // Click window packet
itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09);

Datei anzeigen

@ -3,19 +3,14 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.entities.Entity1_16Types;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.Particle;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> { public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@ -26,84 +21,16 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Spawn Object // Spawn Object
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { registerSpawnTrackerWithData(0x00, 0x00, Entity1_16Types.EntityType.FALLING_BLOCK, protocol.getBlockItemPackets());
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.VAR_INT); // 2 - Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(getTrackerHandler());
handler(wrapper -> {
int typeId = wrapper.get(Type.VAR_INT, 1);
Entity1_15Types.EntityType entityType = Entity1_15Types.getTypeFromId(getOldEntityId(typeId));
wrapper.set(Type.VAR_INT, 1, entityType.getId());
if (entityType == Entity1_15Types.EntityType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0);
int newId = Protocol1_15_2To1_16.getNewBlockStateId(blockState);
wrapper.set(Type.INT, 0, newId);
}
});
}
});
// Spawn mob packet // Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { registerSpawnTracker(0x03, 0x03);
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
handler(wrapper -> {
int type = wrapper.get(Type.VAR_INT, 1);
Entity1_16Types.EntityType entityType = Entity1_16Types.getTypeFromId(type);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
wrapper.set(Type.VAR_INT, 1, getOldEntityId(type));
});
}
});
// Respawn // Respawn
protocol.registerOutgoing(State.PLAY, 0x3B, 0x3B, new PacketRemapper() { registerRespawn(0x3B, 0x3B);
@Override
public void registerMap() {
map(Type.INT);
map(Type.LONG, Type.NOTHING); // Seed
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
});
}
});
// Join Game // Join Game
protocol.registerOutgoing(State.PLAY, 0x26, 0x26, new PacketRemapper() { registerJoinGame(0x26, 0x26, Entity1_16Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_16Types.EntityType.PLAYER, Type.INT));
handler(getDimensionHandler(1));
}
});
// Edit Book
protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> getProtocol().getBlockItemPackets().handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
// Spawn Experience Orb // Spawn Experience Orb
registerExtraTracker(0x01, Entity1_16Types.EntityType.XP_ORB); registerExtraTracker(0x01, Entity1_16Types.EntityType.XP_ORB);
@ -115,20 +42,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
registerExtraTracker(0x04, Entity1_16Types.EntityType.PAINTING); registerExtraTracker(0x04, Entity1_16Types.EntityType.PAINTING);
// Spawn player packet // Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { registerExtraTracker(0x05, Entity1_16Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
handler(getTrackerHandler(Entity1_16Types.EntityType.PLAYER, Type.VAR_INT));
}
});
// Destroy entities // Destroy entities
registerEntityDestroy(0x38, 0x38); registerEntityDestroy(0x38, 0x38);
@ -139,9 +53,6 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
setDisplayNameJson(true);
setDisplayNameMetaType(MetaType1_14.OptChat);
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
MetaType type = meta.getMetaType(); MetaType type = meta.getMetaType();
@ -156,7 +67,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
return meta; return meta;
}); });
regEntType(Entity1_16Types.EntityType.HOGLIN, Entity1_16Types.EntityType.COW).mobName("Hoglin"); mapEntity(Entity1_16Types.EntityType.HOGLIN, Entity1_16Types.EntityType.COW).mobName("Hoglin");
} }
@Override @Override

Datei anzeigen

@ -14,7 +14,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
@ -33,7 +33,7 @@ import us.myles.ViaVersion.packets.State;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> { public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10> {
public EntityPackets1_10(Protocol1_9_4To1_10 protocol) { public EntityPackets1_10(Protocol1_9_4To1_10 protocol) {
super(protocol); super(protocol);
@ -205,12 +205,12 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
registerEntityDestroy(0x30); registerEntityDestroy(0x30);
// Metadata packet // Metadata packet
registerLegacyMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST);
} }
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
regEntType(Entity1_10Types.EntityType.POLAR_BEAR, Entity1_10Types.EntityType.SHEEP).mobName("Polar Bear"); mapEntity(Entity1_10Types.EntityType.POLAR_BEAR, Entity1_10Types.EntityType.SHEEP).mobName("Polar Bear");
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up) // Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
registerMetaHandler().filter(Entity1_10Types.EntityType.POLAR_BEAR, 13).handle((e -> { registerMetaHandler().filter(Entity1_10Types.EntityType.POLAR_BEAR, 13).handle((e -> {