mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Update EntityTracker/meta rewriter
This commit is contained in:
parent
1201c2979b
commit
a789e2ff7b
@ -18,9 +18,9 @@
|
||||
package com.viaversion.viabackwards.api;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappings;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.ItemRewriterBase;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
@ -45,23 +45,22 @@ public abstract class BackwardsProtocol<C1 extends ClientboundPacketType, C2 ext
|
||||
Via.getManager().getProtocolManager().addMappingLoaderFuture(getClass(), protocolClass, runnable);
|
||||
}
|
||||
|
||||
protected void initEntityTracker(UserConnection user) {
|
||||
EntityTracker entityTracker = user.get(EntityTracker.class);
|
||||
if (entityTracker == null) {
|
||||
user.put(entityTracker = new EntityTracker(user));
|
||||
}
|
||||
|
||||
entityTracker.initProtocol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
// Manually load them later, since they depend on VV's mappings
|
||||
return false;
|
||||
}
|
||||
|
||||
public @Nullable ItemRewriterBase getBlockItemPackets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable TranslatableRewriter getTranslatableRewriter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
public @Nullable BackwardsMappings getMappingData() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.entities.meta;
|
||||
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
|
||||
public interface MetaHandler {
|
||||
|
||||
Metadata handle(MetaHandlerEvent e) throws RemovedValueException;
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.entities.meta;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaHandlerEvent {
|
||||
private final UserConnection user;
|
||||
private final EntityTracker.StoredEntity entity;
|
||||
private final int index;
|
||||
private final Metadata data;
|
||||
private final MetaStorage storage;
|
||||
private List<Metadata> extraData;
|
||||
|
||||
public MetaHandlerEvent(UserConnection user, EntityTracker.StoredEntity entity, int index, Metadata data, MetaStorage storage) {
|
||||
this.user = user;
|
||||
this.entity = entity;
|
||||
this.index = index;
|
||||
this.data = data;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public boolean hasData() {
|
||||
return data != null;
|
||||
}
|
||||
|
||||
public Metadata getMetaByIndex(int index) {
|
||||
for (Metadata meta : storage.getMetaDataList()) {
|
||||
if (index == meta.getId()) {
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearExtraData() {
|
||||
extraData = null;
|
||||
}
|
||||
|
||||
public void createMeta(Metadata metadata) {
|
||||
(extraData != null ? extraData : (extraData = new ArrayList<>())).add(metadata);
|
||||
}
|
||||
|
||||
public UserConnection getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public EntityTracker.StoredEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Metadata getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public MetaStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* May be null, use {@link #createMeta(Metadata)} for adding metadata.
|
||||
*/
|
||||
public @Nullable List<Metadata> getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.entities.meta;
|
||||
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class MetaHandlerSettings {
|
||||
private EntityType filterType;
|
||||
private boolean filterFamily;
|
||||
private int filterIndex = -1;
|
||||
private MetaHandler handler;
|
||||
|
||||
public MetaHandlerSettings filter(EntityType type) {
|
||||
return filter(type, filterFamily, filterIndex);
|
||||
}
|
||||
|
||||
public MetaHandlerSettings filter(EntityType type, boolean filterFamily) {
|
||||
return filter(type, filterFamily, filterIndex);
|
||||
}
|
||||
|
||||
public MetaHandlerSettings filter(int index) {
|
||||
return filter(filterType, filterFamily, index);
|
||||
}
|
||||
|
||||
public MetaHandlerSettings filter(EntityType type, int index) {
|
||||
return filter(type, filterFamily, index);
|
||||
}
|
||||
|
||||
public MetaHandlerSettings filter(EntityType type, boolean filterFamily, int index) {
|
||||
this.filterType = type;
|
||||
this.filterFamily = filterFamily;
|
||||
this.filterIndex = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void handle(@Nullable MetaHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void handleIndexChange(final int newIndex) {
|
||||
handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
data.setId(newIndex);
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void removed() {
|
||||
handle(e -> {
|
||||
throw RemovedValueException.EX;
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasHandler() {
|
||||
return handler != null;
|
||||
}
|
||||
|
||||
public boolean hasType() {
|
||||
return filterType != null;
|
||||
}
|
||||
|
||||
public boolean hasIndex() {
|
||||
return filterIndex > -1;
|
||||
}
|
||||
|
||||
public boolean isFilterFamily() {
|
||||
return filterFamily;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the metadata should be handled by this object.
|
||||
*
|
||||
* @param type entity type
|
||||
* @param metadata metadata
|
||||
* @return true if gucci
|
||||
*/
|
||||
public boolean isGucci(EntityType type, Metadata metadata) {
|
||||
if (!hasHandler()) return false;
|
||||
if (hasType() && (filterFamily ? !type.isOrHasParent(filterType) : !filterType.is(type))) {
|
||||
return false;
|
||||
}
|
||||
return !hasIndex() || metadata.getId() == filterIndex;
|
||||
}
|
||||
|
||||
public EntityType getFilterType() {
|
||||
return filterType;
|
||||
}
|
||||
|
||||
public int getFilterIndex() {
|
||||
return filterIndex;
|
||||
}
|
||||
|
||||
public @Nullable MetaHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MetaHandlerSettings{" +
|
||||
"filterType=" + filterType +
|
||||
", filterFamily=" + filterFamily +
|
||||
", filterIndex=" + filterIndex +
|
||||
", handler=" + handler +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -51,30 +51,30 @@ public class EntityData {
|
||||
return this.defaultMeta != null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
public int typeId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return custom mobname, can be either a String or a JsonElement
|
||||
*/
|
||||
public @Nullable Object getMobName() {
|
||||
public @Nullable Object mobName() {
|
||||
return mobName;
|
||||
}
|
||||
|
||||
public int getReplacementId() {
|
||||
public int replacementId() {
|
||||
return replacementId;
|
||||
}
|
||||
|
||||
public @Nullable MetaCreator getDefaultMeta() {
|
||||
public @Nullable MetaCreator defaultMeta() {
|
||||
return defaultMeta;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
public boolean isObjectType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getObjectData() {
|
||||
public int objectData() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -91,6 +91,6 @@ public class EntityData {
|
||||
@FunctionalInterface
|
||||
public interface MetaCreator {
|
||||
|
||||
void createMeta(MetaStorage storage);
|
||||
void createMeta(WrappedMetadata storage);
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ public class EntityObjectData extends EntityData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObject() {
|
||||
public boolean isObjectType() {
|
||||
return isObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
public int objectData() {
|
||||
return objectData;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriterBase;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
||||
@ -29,12 +30,12 @@ import java.util.function.Supplier;
|
||||
public class EntityPositionHandler {
|
||||
|
||||
public static final double RELATIVE_MOVE_FACTOR = 32 * 128;
|
||||
private final EntityRewriterBase<?> entityRewriter;
|
||||
private final EntityRewriterBase entityRewriter;
|
||||
private final Class<? extends EntityPositionStorage> storageClass;
|
||||
private final Supplier<? extends EntityPositionStorage> storageSupplier;
|
||||
private boolean warnedForMissingEntity;
|
||||
|
||||
public EntityPositionHandler(EntityRewriterBase<?> entityRewriter,
|
||||
public EntityPositionHandler(EntityRewriterBase entityRewriter,
|
||||
Class<? extends EntityPositionStorage> storageClass, Supplier<? extends EntityPositionStorage> storageSupplier) {
|
||||
this.entityRewriter = entityRewriter;
|
||||
this.storageClass = storageClass;
|
||||
@ -48,7 +49,7 @@ public class EntityPositionHandler {
|
||||
|
||||
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);
|
||||
EntityTracker.StoredEntity storedEntity = entityRewriter.getEntityTracker(wrapper.user()).getEntity(entityId);
|
||||
StoredEntityData storedEntity = entityRewriter.tracker(wrapper.user()).entityData(entityId);
|
||||
if (storedEntity == null) {
|
||||
if (Via.getManager().isDebug()) { // There is too many plugins violating this out there, and reading seems to be hard! :>
|
||||
ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing at position: " + x + " - " + y + " - " + z + " in " + storageClass.getSimpleName());
|
||||
@ -73,7 +74,7 @@ public class EntityPositionHandler {
|
||||
}
|
||||
|
||||
public EntityPositionStorage getStorage(UserConnection user, int entityId) {
|
||||
EntityTracker.StoredEntity storedEntity = user.get(EntityTracker.class).get(entityRewriter.getProtocol()).getEntity(entityId);
|
||||
StoredEntityData storedEntity = entityRewriter.tracker(user).entityData(entityId);
|
||||
EntityPositionStorage entityStorage;
|
||||
if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage.class)) == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId + " in " + storageClass.getSimpleName());
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.entities.storage;
|
||||
|
||||
public abstract class EntityPositionStorage implements EntityStorage {
|
||||
public abstract class EntityPositionStorage {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.entities.storage;
|
||||
|
||||
public interface EntityStorage {
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.entities.storage;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject {
|
||||
private final Map<BackwardsProtocol, ProtocolEntityTracker> trackers = new HashMap<>();
|
||||
private int currentWorldSectionHeight = 16;
|
||||
private int currentMinY;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void initProtocol(BackwardsProtocol protocol) {
|
||||
trackers.put(protocol, new ProtocolEntityTracker());
|
||||
}
|
||||
|
||||
public @Nullable ProtocolEntityTracker get(BackwardsProtocol protocol) {
|
||||
return trackers.get(protocol);
|
||||
}
|
||||
|
||||
public Map<BackwardsProtocol, ProtocolEntityTracker> getTrackers() {
|
||||
return trackers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of chunk sections of the current world (block height / 16)
|
||||
*/
|
||||
public int getCurrentWorldSectionHeight() {
|
||||
return currentWorldSectionHeight;
|
||||
}
|
||||
|
||||
public void setCurrentWorldSectionHeight(int currentWorldSectionHeight) {
|
||||
this.currentWorldSectionHeight = currentWorldSectionHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return absolute minimum y coordinate of the current world
|
||||
*/
|
||||
public int getCurrentMinY() {
|
||||
return currentMinY;
|
||||
}
|
||||
|
||||
public void setCurrentMinY(int currentMinY) {
|
||||
this.currentMinY = currentMinY;
|
||||
}
|
||||
|
||||
public static class ProtocolEntityTracker {
|
||||
private final Map<Integer, StoredEntity> entityMap = new ConcurrentHashMap<>();
|
||||
|
||||
public void trackEntityType(int id, EntityType type) {
|
||||
entityMap.putIfAbsent(id, new StoredEntity(id, type));
|
||||
}
|
||||
|
||||
public void removeEntity(int id) {
|
||||
entityMap.remove(id);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EntityType getEntityType(int id) {
|
||||
StoredEntity storedEntity = entityMap.get(id);
|
||||
return storedEntity != null ? storedEntity.getType() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public StoredEntity getEntity(int id) {
|
||||
return entityMap.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class StoredEntity {
|
||||
private final int entityId;
|
||||
private final EntityType type;
|
||||
private Map<Class<? extends EntityStorage>, EntityStorage> storedObjects;
|
||||
|
||||
private StoredEntity(final int entityId, final EntityType type) {
|
||||
this.entityId = entityId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an object from the storage
|
||||
*
|
||||
* @param objectClass The class of the object to get
|
||||
* @param <T> The type of the class you want to get.
|
||||
* @return The requested object
|
||||
*/
|
||||
@Nullable
|
||||
public <T extends EntityStorage> T get(Class<T> objectClass) {
|
||||
return storedObjects != null ? (T) storedObjects.get(objectClass) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the storage has an object
|
||||
*
|
||||
* @param objectClass The object class to check
|
||||
* @return True if the object is in the storage
|
||||
*/
|
||||
public boolean has(Class<? extends EntityStorage> objectClass) {
|
||||
return storedObjects != null && storedObjects.containsKey(objectClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an object into the stored objects based on class
|
||||
*
|
||||
* @param object The object to store.
|
||||
*/
|
||||
public void put(EntityStorage object) {
|
||||
if (storedObjects == null) {
|
||||
storedObjects = new ConcurrentHashMap<>();
|
||||
}
|
||||
storedObjects.put(object.getClass(), object);
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public EntityType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StoredEntity{" +
|
||||
"entityId=" + entityId +
|
||||
", type=" + type +
|
||||
", storedObjects=" + storedObjects +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
@ -23,48 +23,44 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaStorage {
|
||||
private List<Metadata> metaDataList;
|
||||
public final class WrappedMetadata {
|
||||
private final List<Metadata> metadataList;
|
||||
|
||||
public MetaStorage(List<Metadata> metaDataList) {
|
||||
this.metaDataList = metaDataList;
|
||||
public WrappedMetadata(List<Metadata> metadataList) {
|
||||
this.metadataList = metadataList;
|
||||
}
|
||||
|
||||
public boolean has(Metadata data) {
|
||||
return this.metaDataList.contains(data);
|
||||
return this.metadataList.contains(data);
|
||||
}
|
||||
|
||||
public void delete(Metadata data) {
|
||||
this.metaDataList.remove(data);
|
||||
public void remove(Metadata data) {
|
||||
this.metadataList.remove(data);
|
||||
}
|
||||
|
||||
public void delete(int index) {
|
||||
metaDataList.removeIf(meta -> meta.getId() == index);
|
||||
public void remove(int index) {
|
||||
metadataList.removeIf(meta -> meta.id() == index);
|
||||
}
|
||||
|
||||
public void add(Metadata data) {
|
||||
this.metaDataList.add(data);
|
||||
this.metadataList.add(data);
|
||||
}
|
||||
|
||||
public @Nullable Metadata get(int index) {
|
||||
for (Metadata meta : this.metaDataList) {
|
||||
if (index == meta.getId()) {
|
||||
for (Metadata meta : this.metadataList) {
|
||||
if (index == meta.id()) {
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Metadata> getMetaDataList() {
|
||||
return metaDataList;
|
||||
}
|
||||
|
||||
public void setMetaDataList(List<Metadata> metaDataList) {
|
||||
this.metaDataList = metaDataList;
|
||||
public List<Metadata> metadataList() {
|
||||
return metadataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MetaStorage{" + "metaDataList=" + metaDataList + '}';
|
||||
return "MetaStorage{" + "metaDataList=" + metadataList + '}';
|
||||
}
|
||||
}
|
@ -18,11 +18,8 @@
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -30,8 +27,6 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class EntityRewriter<T extends BackwardsProtocol> extends EntityRewriterBase<T> {
|
||||
|
||||
protected EntityRewriter(T protocol) {
|
||||
@ -42,7 +37,8 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
super(protocol, displayType, 2, displayVisibilityType, 3);
|
||||
}
|
||||
|
||||
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
|
||||
@Override
|
||||
public void registerTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
|
||||
protocol.registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -55,13 +51,14 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Type.BYTE); // 7 - Yaw
|
||||
map(Type.INT); // 8 - Data
|
||||
handler(getSpawnTracketWithDataHandler(fallingBlockType));
|
||||
handler(getSpawnTrackerWithDataHandler(fallingBlockType));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PacketHandler getSpawnTracketWithDataHandler(EntityType fallingBlockType) {
|
||||
public PacketHandler getSpawnTrackerWithDataHandler(EntityType fallingBlockType) {
|
||||
return wrapper -> {
|
||||
// Check against the UNMAPPED entity type
|
||||
EntityType entityType = setOldEntityId(wrapper);
|
||||
if (entityType == fallingBlockType) {
|
||||
int blockState = wrapper.get(Type.INT, 0);
|
||||
@ -84,52 +81,14 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
|
||||
private EntityType setOldEntityId(PacketWrapper wrapper) throws Exception {
|
||||
int typeId = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = getTypeFromId(typeId);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
EntityType entityType = typeFromId(typeId);
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldTypeId = getOldEntityId(entityType.getId());
|
||||
if (typeId != oldTypeId) {
|
||||
wrapper.set(Type.VAR_INT, 1, oldTypeId);
|
||||
int mappedTypeId = newEntityId(entityType.getId());
|
||||
if (typeId != mappedTypeId) {
|
||||
wrapper.set(Type.VAR_INT, 1, mappedTypeId);
|
||||
}
|
||||
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to handle a metadata list packet and its full initial meta rewrite.
|
||||
*/
|
||||
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
|
||||
getProtocol().registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
if (oldMetaType != null) {
|
||||
map(oldMetaType, newMetaType);
|
||||
} else {
|
||||
map(newMetaType);
|
||||
}
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(newMetaType, 0));
|
||||
handleMeta(wrapper.user(), entityId, storage);
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
//TODO only do this once for a first meta packet?
|
||||
if (entityData != null) {
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.set(newMetaType, 0, storage.getMetaDataList());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> metaType) {
|
||||
registerMetadataRewriter(packetType, null, metaType);
|
||||
}
|
||||
}
|
||||
|
@ -20,97 +20,120 @@ package com.viaversion.viabackwards.api.rewriters;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.entities.meta.MetaHandlerEvent;
|
||||
import com.viaversion.viabackwards.api.entities.meta.MetaHandlerSettings;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Entity rewriter base class.
|
||||
*
|
||||
* @see EntityRewriter
|
||||
* @see com.viaversion.viabackwards.api.rewriters.EntityRewriter
|
||||
* @see LegacyEntityRewriter
|
||||
*/
|
||||
public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
private final Map<EntityType, EntityData> entityTypes = new HashMap<>();
|
||||
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
|
||||
public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends EntityRewriter<T> {
|
||||
private final Int2ObjectMap<EntityData> entityDataMappings = new Int2ObjectOpenHashMap<>();
|
||||
private final MetaType displayNameMetaType;
|
||||
private final MetaType displayVisibilityMetaType;
|
||||
private final int displayNameIndex;
|
||||
private final int displayVisibilityIndex;
|
||||
protected Int2IntMap typeMapping;
|
||||
|
||||
EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex,
|
||||
MetaType displayVisibilityMetaType, int displayVisibilityIndex) {
|
||||
super(protocol);
|
||||
super(protocol, false);
|
||||
this.displayNameMetaType = displayNameMetaType;
|
||||
this.displayNameIndex = displayNameIndex;
|
||||
this.displayVisibilityMetaType = displayVisibilityMetaType;
|
||||
this.displayVisibilityIndex = displayVisibilityIndex;
|
||||
}
|
||||
|
||||
protected EntityType getEntityType(UserConnection connection, int id) {
|
||||
return getEntityTracker(connection).getEntityType(id);
|
||||
@Override
|
||||
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
|
||||
super.handleMetadata(entityId, metadataList, connection);
|
||||
|
||||
EntityType type = tracker(connection).entityType(entityId);
|
||||
if (type == null) return;
|
||||
|
||||
EntityData entityData = entityDataForType(type);
|
||||
|
||||
// Set the mapped entity name if there is no custom name set already
|
||||
Metadata meta = getMeta(displayNameIndex, metadataList);
|
||||
if (meta != null && entityData != null && entityData.mobName() != null
|
||||
&& (meta.getValue() == null || meta.getValue().toString().isEmpty())
|
||||
&& meta.metaType().typeId() == displayNameMetaType.typeId()) {
|
||||
meta.setValue(entityData.mobName());
|
||||
if (ViaBackwards.getConfig().alwaysShowOriginalMobName()) {
|
||||
removeMeta(displayVisibilityIndex, metadataList);
|
||||
metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, true));
|
||||
}
|
||||
}
|
||||
|
||||
// Add any other extra meta for mapped entities
|
||||
if (entityData != null) {
|
||||
//TODO only do this once for a first meta packet?
|
||||
if (entityData != null && entityData.hasBaseMeta()) {
|
||||
entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
|
||||
getEntityTracker(wrapper.user()).trackEntityType(entityId, type);
|
||||
protected @Nullable Metadata getMeta(int metaIndex, List<Metadata> metadataList) {
|
||||
for (Metadata metadata : metadataList) {
|
||||
if (metadata.id() == metaIndex) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void removeMeta(int metaIndex, List<Metadata> metadataList) {
|
||||
metadataList.removeIf(meta -> meta.id() == metaIndex);
|
||||
}
|
||||
|
||||
protected boolean hasData(EntityType type) {
|
||||
return entityTypes.containsKey(type);
|
||||
return entityDataMappings.containsKey(type.getId());
|
||||
}
|
||||
|
||||
protected @Nullable EntityData getEntityData(EntityType type) {
|
||||
return entityTypes.get(type);
|
||||
protected @Nullable EntityData entityDataForType(EntityType type) {
|
||||
return entityDataMappings.get(type.getId());
|
||||
}
|
||||
|
||||
protected @Nullable StoredEntityData storedEntityData(MetaHandlerEvent event) {
|
||||
return tracker(event.user()).entityData(event.entityId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that both types should be of the SAME version.
|
||||
* Maps an entity type to another with extra data.
|
||||
* Note that both types should be of the same version.
|
||||
*
|
||||
* @param oldType old type of the higher version
|
||||
* @param replacement new type of the higher version
|
||||
* @param type entity type
|
||||
* @param mappedType mapped entity type
|
||||
* @return created entity data
|
||||
* @see #mapEntityDirect(EntityType, EntityType) for id only rewriting
|
||||
* @see #mapEntityType(EntityType, EntityType) for id only rewriting
|
||||
*/
|
||||
protected EntityData mapEntity(EntityType oldType, EntityType replacement) {
|
||||
Preconditions.checkArgument(oldType.getClass() == replacement.getClass());
|
||||
protected EntityData mapEntityTypeWithData(EntityType type, EntityType mappedType) {
|
||||
Preconditions.checkArgument(type.getClass() == mappedType.getClass());
|
||||
|
||||
// Already rewrite the id here
|
||||
int mappedReplacementId = getOldEntityId(replacement.getId());
|
||||
EntityData data = new EntityData(oldType.getId(), mappedReplacementId);
|
||||
mapEntityDirect(oldType.getId(), mappedReplacementId);
|
||||
entityTypes.put(oldType, data);
|
||||
int mappedReplacementId = newEntityId(mappedType.getId());
|
||||
EntityData data = new EntityData(type.getId(), mappedReplacementId);
|
||||
mapEntityType(type.getId(), mappedReplacementId);
|
||||
entityDataMappings.put(type.getId(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -119,167 +142,40 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
*
|
||||
* @param oldTypes entity types of the higher version
|
||||
* @param newTypeClass entity types enum class of the lower version
|
||||
* @param <T> new type class
|
||||
* @param <E> new enum type
|
||||
*/
|
||||
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
|
||||
if (typeMapping == null) {
|
||||
typeMapping = new Int2IntOpenHashMap(oldTypes.length, 1F);
|
||||
typeMapping.defaultReturnValue(-1);
|
||||
@Override
|
||||
public <E extends Enum<E> & EntityType> void mapTypes(EntityType[] oldTypes, Class<E> newTypeClass) {
|
||||
if (typeMappings == null) {
|
||||
typeMappings = new Int2IntOpenHashMap(oldTypes.length, 1F);
|
||||
typeMappings.defaultReturnValue(-1);
|
||||
}
|
||||
for (EntityType oldType : oldTypes) {
|
||||
try {
|
||||
T newType = Enum.valueOf(newTypeClass, oldType.name());
|
||||
typeMapping.put(oldType.getId(), newType.getId());
|
||||
E newType = Enum.valueOf(newTypeClass, oldType.name());
|
||||
typeMappings.put(oldType.getId(), newType.getId());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// Don't warn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly maps the entity without any other rewriting.
|
||||
*
|
||||
* @param oldType type of the higher version
|
||||
* @param newType type of the lower version
|
||||
* @see #mapEntity(EntityType, EntityType) for mapping with data
|
||||
*/
|
||||
public void mapEntityDirect(EntityType oldType, EntityType newType) {
|
||||
Preconditions.checkArgument(oldType.getClass() != newType.getClass());
|
||||
mapEntityDirect(oldType.getId(), newType.getId());
|
||||
}
|
||||
|
||||
private void mapEntityDirect(int oldType, int newType) {
|
||||
if (typeMapping == null) {
|
||||
typeMapping = new Int2IntOpenHashMap();
|
||||
typeMapping.defaultReturnValue(-1);
|
||||
}
|
||||
typeMapping.put(oldType, newType);
|
||||
}
|
||||
|
||||
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();
|
||||
for (MetaHandlerSettings settings : metaHandlers) {
|
||||
List<Metadata> newData = new ArrayList<>();
|
||||
for (Metadata meta : storage.getMetaDataList()) {
|
||||
MetaHandlerEvent event = null;
|
||||
try {
|
||||
Metadata modifiedMeta = meta;
|
||||
if (settings.isGucci(type, meta)) {
|
||||
event = new MetaHandlerEvent(user, storedEntity, meta.getId(), meta, storage);
|
||||
modifiedMeta = settings.getHandler().handle(event);
|
||||
|
||||
if (event.getExtraData() != null) {
|
||||
newData.addAll(event.getExtraData());
|
||||
event.clearExtraData();
|
||||
}
|
||||
}
|
||||
|
||||
if (modifiedMeta == null) {
|
||||
throw RemovedValueException.EX;
|
||||
}
|
||||
|
||||
newData.add(modifiedMeta);
|
||||
} catch (RemovedValueException e) {
|
||||
// Add the additionally created data here in case of an interruption
|
||||
if (event != null && event.getExtraData() != null) {
|
||||
newData.addAll(event.getExtraData());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger log = ViaBackwards.getPlatform().getLogger();
|
||||
log.warning("Unable to handle metadata " + meta + " for entity type " + type);
|
||||
log.warning(storage.getMetaDataList().stream().sorted(Comparator.comparingInt(Metadata::getId))
|
||||
.map(Metadata::toString).collect(Collectors.joining("\n", "Full metadata list: ", "")));
|
||||
e.printStackTrace();
|
||||
public void registerMetaTypeHandler(@Nullable MetaType itemType, @Nullable MetaType blockType, @Nullable MetaType particleType, @Nullable MetaType optChatType) {
|
||||
filter().handler((event, meta) -> {
|
||||
MetaType type = meta.metaType();
|
||||
if (itemType != null && type == itemType) {
|
||||
protocol.getBlockItemPackets().handleItemToClient(meta.value());
|
||||
} else if (blockType != null && type == blockType) {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (particleType != null && type == particleType) {
|
||||
rewriteParticle(meta.value());
|
||||
} else if (optChatType != null && type == optChatType) {
|
||||
JsonElement text = meta.value();
|
||||
if (text != null) {
|
||||
protocol.getTranslatableRewriter().processText(text);
|
||||
}
|
||||
}
|
||||
|
||||
storage.setMetaDataList(newData);
|
||||
}
|
||||
|
||||
// Handle Entity Name
|
||||
Metadata data = storage.get(displayNameIndex);
|
||||
if (data != null) {
|
||||
EntityData entityData = getEntityData(type);
|
||||
// Set the name if there is no custom name set already
|
||||
if (entityData != null && entityData.getMobName() != null
|
||||
&& (data.getValue() == null || data.getValue().toString().isEmpty())
|
||||
&& data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
|
||||
data.setValue(entityData.getMobName());
|
||||
if (ViaBackwards.getConfig().alwaysShowOriginalMobName()) {
|
||||
storage.delete(displayVisibilityIndex);
|
||||
storage.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to handle player, painting, or xp orb trackers without meta changes.
|
||||
*/
|
||||
protected void registerExtraTracker(ClientboundPacketType packetType, EntityType entityType, Type intType) {
|
||||
getProtocol().registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(intType); // 0 - Entity id
|
||||
handler(wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void registerExtraTracker(ClientboundPacketType packetType, EntityType entityType) {
|
||||
registerExtraTracker(packetType, entityType, Type.VAR_INT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub 1.17 method for entity remove packets.
|
||||
*
|
||||
* @param packetType remove entities packet type
|
||||
*/
|
||||
protected void registerEntityDestroy(ClientboundPacketType packetType) {
|
||||
getProtocol().registerClientbound(packetType, 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 1.17+ method for entity remove packets.
|
||||
*
|
||||
* @param packetType remove entities packet type
|
||||
*/
|
||||
protected void registerRemoveEntity(ClientboundPacketType packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ids
|
||||
handler(wrapper -> {
|
||||
int entity = wrapper.get(Type.VAR_INT, 0);
|
||||
getEntityTracker(wrapper.user()).removeEntity(entity);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -287,7 +183,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
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()));
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), typeFromId(id.intValue()));
|
||||
};
|
||||
}
|
||||
|
||||
@ -296,29 +192,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) {
|
||||
return wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType);
|
||||
}
|
||||
|
||||
protected PacketHandler getWorldDataTracker(int nbtIndex) {
|
||||
return wrapper -> {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
|
||||
CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex);
|
||||
Tag height = registryData.get("height");
|
||||
if (height instanceof IntTag) {
|
||||
int blockHeight = ((IntTag) height).asInt();
|
||||
tracker.setCurrentWorldSectionHeight(blockHeight >> 4);
|
||||
} else {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData);
|
||||
}
|
||||
|
||||
Tag minY = registryData.get("min_y");
|
||||
if (minY instanceof IntTag) {
|
||||
tracker.setCurrentMinY(((IntTag) minY).asInt());
|
||||
} else {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData);
|
||||
}
|
||||
};
|
||||
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType);
|
||||
}
|
||||
|
||||
protected PacketHandler getDimensionHandler(int index) {
|
||||
@ -328,28 +202,4 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
};
|
||||
}
|
||||
|
||||
public EntityTracker.ProtocolEntityTracker getEntityTracker(UserConnection user) {
|
||||
return user.get(EntityTracker.class).get(getProtocol());
|
||||
}
|
||||
|
||||
protected void rewriteParticle(Particle particle) {
|
||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||
int id = particle.getId();
|
||||
if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) {
|
||||
Particle.ParticleData data = particle.getArguments().get(0);
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(data.get()));
|
||||
} else if (id == mappings.getItemId()) {
|
||||
Particle.ParticleData data = particle.getArguments().get(0);
|
||||
data.setValue(protocol.getMappingData().getNewItemId(data.get()));
|
||||
}
|
||||
|
||||
particle.setId(protocol.getMappingData().getNewParticleId(id));
|
||||
}
|
||||
|
||||
protected abstract EntityType getTypeFromId(int typeId);
|
||||
|
||||
public int getOldEntityId(int newId) {
|
||||
return typeMapping != null ? typeMapping.getOrDefault(newId, newId) : newId;
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,10 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends RewriterBase<T> {
|
||||
|
||||
protected final String nbtTagName;
|
||||
protected final boolean jsonNameFormat;
|
||||
|
@ -21,13 +21,14 @@ import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityObjectData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.ObjectType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@ -83,14 +84,15 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
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);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.INT, 0), playerType);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
|
||||
getProtocol().registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
|
||||
protocol.registerClientbound(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
@ -101,35 +103,32 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
}
|
||||
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());
|
||||
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> metaType) {
|
||||
@Override
|
||||
public void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> metaType) {
|
||||
registerMetadataRewriter(packetType, 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);
|
||||
EntityType type = tracker(wrapper.user()).entityType(entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0));
|
||||
handleMeta(wrapper.user(), entityId, storage);
|
||||
List<Metadata> metadata = wrapper.get(metaType, 0);
|
||||
handleMetadata(entityId, metadata, wrapper.user());
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
EntityData entityData = entityDataForType(type);
|
||||
if (entityData != null) {
|
||||
wrapper.set(Type.VAR_INT, 1, entityData.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, entityData.replacementId());
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
entityData.defaultMeta().createMeta(new WrappedMetadata(metadata));
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(metaType, 0, storage.getMetaDataList());
|
||||
};
|
||||
}
|
||||
|
||||
@ -140,10 +139,8 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
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);
|
||||
List<Metadata> metadata = wrapper.get(metaType, 0);
|
||||
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
|
||||
};
|
||||
}
|
||||
|
||||
@ -157,15 +154,20 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
|
||||
EntityData data = getObjectData(type);
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, (byte) data.getReplacementId());
|
||||
if (data.getObjectData() != -1) {
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
wrapper.set(Type.BYTE, 0, (byte) data.replacementId());
|
||||
if (data.objectData() != -1) {
|
||||
wrapper.set(Type.INT, 0, data.objectData());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected EntityType getObjectTypeFromId(int typeId) {
|
||||
return getTypeFromId(typeId);
|
||||
return typeFromId(typeId);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
|
||||
tracker(wrapper.user()).addEntity(entityId, type);
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ package com.viaversion.viabackwards.api.rewriters;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
@Deprecated
|
||||
public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends RewriterBase<T> {
|
||||
protected final Int2ObjectMap<SoundData> soundRewrites = new Int2ObjectOpenHashMap<>(64);
|
||||
|
||||
protected LegacySoundRewriter(T protocol) {
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
|
||||
public abstract class Rewriter<T extends BackwardsProtocol> {
|
||||
protected final T protocol;
|
||||
|
||||
protected Rewriter(final T protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register everything.
|
||||
*/
|
||||
public void register() {
|
||||
registerPackets();
|
||||
registerRewrites();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register packet listeners.
|
||||
*/
|
||||
protected abstract void registerPackets();
|
||||
|
||||
/**
|
||||
* Register rewrites.
|
||||
*/
|
||||
protected void registerRewrites() {
|
||||
}
|
||||
|
||||
public T getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
}
|
@ -26,6 +26,8 @@ import com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets.EntityPac
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets.PlayerPackets1_11;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
@ -58,7 +60,7 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_11Types.EntityType.PLAYER, true));
|
||||
|
||||
if (!user.has(WindowTracker.class)) {
|
||||
user.put(new WindowTracker(user));
|
||||
|
@ -19,18 +19,18 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -335,13 +335,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
}
|
||||
});
|
||||
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item
|
||||
data.setValue(handleItemToClient((Item) data.getValue()));
|
||||
|
||||
return data;
|
||||
protocol.getEntityPackets().filter().handler((event, meta) -> {
|
||||
if (meta.metaType().type().equals(Type.ITEM)) // Is Item
|
||||
meta.setValue(handleItemToClient((Item) meta.getValue()));
|
||||
});
|
||||
}
|
||||
|
||||
@ -404,9 +400,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
private boolean isLlama(UserConnection user) {
|
||||
WindowTracker tracker = user.get(WindowTracker.class);
|
||||
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
|
||||
EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol());
|
||||
EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId());
|
||||
return storedEntity != null && storedEntity.getType().is(Entity1_11Types.EntityType.LIAMA);
|
||||
EntityTracker entTracker = user.getEntityTracker(Protocol1_10To1_11.class);
|
||||
StoredEntityData entityData = entTracker.entityData(tracker.getEntityId());
|
||||
return entityData != null && entityData.type().is(Entity1_11Types.EntityType.LIAMA);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -414,10 +410,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
private Optional<ChestedHorseStorage> getChestedHorse(UserConnection user) {
|
||||
WindowTracker tracker = user.get(WindowTracker.class);
|
||||
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
|
||||
EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol());
|
||||
EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId());
|
||||
if (storedEntity != null)
|
||||
return Optional.of(storedEntity.get(ChestedHorseStorage.class));
|
||||
EntityTracker entTracker = user.getEntityTracker(Protocol1_10To1_11.class);
|
||||
StoredEntityData entityData = entTracker.entityData(tracker.getEntityId());
|
||||
if (entityData != null)
|
||||
return Optional.of(entityData.get(ChestedHorseStorage.class));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
@ -19,13 +19,13 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11> {
|
||||
@ -98,7 +99,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
@ -109,8 +110,8 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -137,35 +138,24 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
EntityType type = tracker(wrapper.user()).entityType(entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
storage
|
||||
);
|
||||
List<Metadata> list = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
handleMetadata(wrapper.get(Type.VAR_INT, 0), list, wrapper.user());
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
EntityData entityData = entityDataForType(type);
|
||||
if (entityData != null) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.getReplacementId());
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
entityData.defaultMeta().createMeta(new WrappedMetadata(list));
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
|
||||
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_11Types.EntityType.PLAYER);
|
||||
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
|
||||
|
||||
@ -185,7 +175,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.ENTITY_STATUS, new PacketRemapper() {
|
||||
@ -214,99 +204,86 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Guardian
|
||||
mapEntity(Entity1_11Types.EntityType.ELDER_GUARDIAN, Entity1_11Types.EntityType.GUARDIAN);
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.ELDER_GUARDIAN, Entity1_11Types.EntityType.GUARDIAN);
|
||||
// Skeletons
|
||||
mapEntity(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).mobName("Wither Skeleton").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1)));
|
||||
mapEntity(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).mobName("Stray").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).mobName("Wither Skeleton").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).mobName("Stray").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2)));
|
||||
// Zombies
|
||||
mapEntity(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).mobName("Husk").spawnMetadata(storage -> handleZombieType(storage, 6));
|
||||
mapEntity(Entity1_11Types.EntityType.ZOMBIE_VILLAGER, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).mobName("Husk").spawnMetadata(storage -> handleZombieType(storage, 6));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.ZOMBIE_VILLAGER, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1));
|
||||
// Horses
|
||||
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.
|
||||
mapEntity(Entity1_11Types.EntityType.DONKEY, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
|
||||
mapEntity(Entity1_11Types.EntityType.MULE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2)));
|
||||
mapEntity(Entity1_11Types.EntityType.SKELETON_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4)));
|
||||
mapEntity(Entity1_11Types.EntityType.ZOMBIE_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
|
||||
mapEntityTypeWithData(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.
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.DONKEY, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.MULE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.SKELETON_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.ZOMBIE_HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
|
||||
// New mobs
|
||||
mapEntity(Entity1_11Types.EntityType.EVOCATION_FANGS, Entity1_11Types.EntityType.SHULKER);
|
||||
mapEntity(Entity1_11Types.EntityType.EVOCATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Evoker");
|
||||
mapEntity(Entity1_11Types.EntityType.VEX, Entity1_11Types.EntityType.BAT).mobName("Vex");
|
||||
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
|
||||
mapEntity(Entity1_11Types.EntityType.LIAMA, Entity1_11Types.EntityType.HORSE).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
|
||||
mapEntity(Entity1_11Types.EntityType.LIAMA_SPIT, Entity1_11Types.EntityType.SNOWBALL);
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.EVOCATION_FANGS, Entity1_11Types.EntityType.SHULKER);
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.EVOCATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Evoker");
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.VEX, Entity1_11Types.EntityType.BAT).mobName("Vex");
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.VINDICATION_ILLAGER, Entity1_11Types.EntityType.VILLAGER).mobName("Vindicator").spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.LIAMA, Entity1_11Types.EntityType.HORSE).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
|
||||
mapEntityTypeWithData(Entity1_11Types.EntityType.LIAMA_SPIT, Entity1_11Types.EntityType.SNOWBALL);
|
||||
|
||||
mapObjectType(Entity1_11Types.ObjectType.LIAMA_SPIT, Entity1_11Types.ObjectType.SNOWBALL, -1);
|
||||
// Replace with endertorchthingies
|
||||
mapObjectType(Entity1_11Types.ObjectType.EVOCATION_FANGS, Entity1_11Types.ObjectType.FALLING_BLOCK, 198 | 1 << 12);
|
||||
|
||||
// Handle ElderGuardian & target metadata
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.GUARDIAN, true, 12).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
boolean b = (boolean) data.getValue();
|
||||
filter().filterFamily(Entity1_11Types.EntityType.GUARDIAN).index(12).handler((event, meta) -> {
|
||||
boolean b = (boolean) meta.getValue();
|
||||
int bitmask = b ? 0x02 : 0;
|
||||
|
||||
if (e.getEntity().getType().is(Entity1_11Types.EntityType.ELDER_GUARDIAN))
|
||||
if (event.entityType() == Entity1_11Types.EntityType.ELDER_GUARDIAN) {
|
||||
bitmask |= 0x04;
|
||||
}
|
||||
|
||||
data.setMetaType(MetaType1_9.Byte);
|
||||
data.setValue((byte) bitmask);
|
||||
|
||||
return data;
|
||||
meta.setMetaType(MetaType1_9.Byte);
|
||||
meta.setValue((byte) bitmask);
|
||||
});
|
||||
|
||||
// Handle skeleton swing
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.ABSTRACT_SKELETON, true, 12).handleIndexChange(13);
|
||||
filter().filterFamily(Entity1_11Types.EntityType.ABSTRACT_SKELETON).index(12).toIndex(13);
|
||||
|
||||
/*
|
||||
ZOMBIE CHANGES
|
||||
*/
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.ZOMBIE, true).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
switch (data.getId()) {
|
||||
filter().filterFamily(Entity1_11Types.EntityType.ZOMBIE).handler((event, meta) -> {
|
||||
switch (meta.id()) {
|
||||
case 13:
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
return;
|
||||
case 14:
|
||||
data.setId(15);
|
||||
event.setIndex(15);
|
||||
break;
|
||||
case 15:
|
||||
data.setId(14);
|
||||
event.setIndex(14);
|
||||
break;
|
||||
// Profession
|
||||
case 16:
|
||||
data.setId(13);
|
||||
data.setValue(1 + (int) data.getValue());
|
||||
event.setIndex(13);
|
||||
meta.setValue(1 + (int) meta.getValue());
|
||||
break;
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
// Handle Evocation Illager
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.EVOCATION_ILLAGER, 12).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
data.setId(13);
|
||||
data.setMetaType(MetaType1_9.VarInt);
|
||||
data.setValue(((Byte) data.getValue()).intValue()); // Change the profession for the states
|
||||
|
||||
return data;
|
||||
filter().type(Entity1_11Types.EntityType.EVOCATION_ILLAGER).index(12).handler((event, meta) -> {
|
||||
event.setIndex(13);
|
||||
meta.setMetaType(MetaType1_9.VarInt);
|
||||
meta.setValue(((Byte) meta.getValue()).intValue()); // Change the profession for the states
|
||||
});
|
||||
|
||||
// Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ):
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.VEX, 12).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
data.setValue((byte) 0x00);
|
||||
return data;
|
||||
filter().type(Entity1_11Types.EntityType.VEX).index(12).handler((event, meta) -> {
|
||||
meta.setValue((byte) 0x00);
|
||||
});
|
||||
|
||||
// Handle VindicationIllager
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.VINDICATION_ILLAGER, 12).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
data.setId(13);
|
||||
data.setMetaType(MetaType1_9.VarInt);
|
||||
data.setValue(((Number) data.getValue()).intValue() == 1 ? 2 : 4);
|
||||
return data;
|
||||
filter().type(Entity1_11Types.EntityType.VINDICATION_ILLAGER).index(12).handler((event, meta) -> {
|
||||
event.setIndex(13);
|
||||
meta.setMetaType(MetaType1_9.VarInt);
|
||||
meta.setValue(((Number) meta.getValue()).intValue() == 1 ? 2 : 4);
|
||||
});
|
||||
|
||||
/*
|
||||
@ -314,72 +291,70 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
*/
|
||||
|
||||
// Handle horse flags
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.ABSTRACT_HORSE, true, 13).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
byte b = (byte) data.getValue();
|
||||
if (e.getEntity().has(ChestedHorseStorage.class) &&
|
||||
e.getEntity().get(ChestedHorseStorage.class).isChested()) {
|
||||
filter().filterFamily(Entity1_11Types.EntityType.ABSTRACT_HORSE).index(13).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
byte b = (byte) meta.getValue();
|
||||
if (data.has(ChestedHorseStorage.class) && data.get(ChestedHorseStorage.class).isChested()) {
|
||||
b |= 0x08; // Chested
|
||||
data.setValue(b);
|
||||
meta.setValue(b);
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
// Create chested horse storage
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.CHESTED_HORSE, true).handle(e -> {
|
||||
if (!e.getEntity().has(ChestedHorseStorage.class))
|
||||
e.getEntity().put(new ChestedHorseStorage());
|
||||
return e.getData();
|
||||
filter().filterFamily(Entity1_11Types.EntityType.CHESTED_HORSE).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
if (!data.has(ChestedHorseStorage.class)) {
|
||||
data.put(new ChestedHorseStorage());
|
||||
}
|
||||
});
|
||||
|
||||
// Handle horse armor
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.HORSE, 16).handleIndexChange(17);
|
||||
filter().type(Entity1_11Types.EntityType.HORSE).index(16).toIndex(17);
|
||||
|
||||
// Handle chested horse
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.CHESTED_HORSE, true, 15).handle(e -> {
|
||||
ChestedHorseStorage storage = e.getEntity().get(ChestedHorseStorage.class);
|
||||
boolean b = (boolean) e.getData().getValue();
|
||||
filter().filterFamily(Entity1_11Types.EntityType.CHESTED_HORSE).index(15).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class);
|
||||
boolean b = (boolean) meta.getValue();
|
||||
storage.setChested(b);
|
||||
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
});
|
||||
|
||||
// Get rid of Liama metadata
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.LIAMA).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
ChestedHorseStorage storage = e.getEntity().get(ChestedHorseStorage.class);
|
||||
filter().type(Entity1_11Types.EntityType.LIAMA).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class);
|
||||
|
||||
int index = e.getIndex();
|
||||
int index = event.index();
|
||||
// Store them for later (:
|
||||
switch (index) {
|
||||
case 16:
|
||||
storage.setLiamaStrength((int) data.getValue());
|
||||
throw RemovedValueException.EX;
|
||||
storage.setLiamaStrength((int) meta.getValue());
|
||||
event.cancel();
|
||||
break;
|
||||
case 17:
|
||||
storage.setLiamaCarpetColor((int) data.getValue());
|
||||
throw RemovedValueException.EX;
|
||||
storage.setLiamaCarpetColor((int) meta.getValue());
|
||||
event.cancel();
|
||||
break;
|
||||
case 18:
|
||||
storage.setLiamaVariant((int) data.getValue());
|
||||
throw RemovedValueException.EX;
|
||||
storage.setLiamaVariant((int) meta.getValue());
|
||||
event.cancel();
|
||||
break;
|
||||
}
|
||||
return e.getData();
|
||||
});
|
||||
|
||||
// Handle Horse (Correct owner)
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.ABSTRACT_HORSE, true, 14).handleIndexChange(16);
|
||||
filter().filterFamily(Entity1_11Types.EntityType.ABSTRACT_HORSE).index(14).toIndex(16);
|
||||
|
||||
// Handle villager - Change non-existing profession
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.VILLAGER, 13).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
if ((int) data.getValue() == 5)
|
||||
data.setValue(0);
|
||||
|
||||
return data;
|
||||
filter().type(Entity1_11Types.EntityType.VILLAGER).index(13).handler((event, meta) -> {
|
||||
if ((int) meta.getValue() == 5) {
|
||||
meta.setValue(0);
|
||||
}
|
||||
});
|
||||
|
||||
// handle new Shulker color meta
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.SHULKER, 15).removed();
|
||||
|
||||
filter().type(Entity1_11Types.EntityType.SHULKER).cancel(15);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -401,7 +376,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
return new Metadata(13, MetaType1_9.VarInt, type);
|
||||
}
|
||||
|
||||
private void handleZombieType(MetaStorage storage, int type) {
|
||||
private void handleZombieType(WrappedMetadata storage, int type) {
|
||||
Metadata meta = storage.get(13);
|
||||
if (meta == null) {
|
||||
storage.add(getZombieTypeMeta(type));
|
||||
@ -420,7 +395,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityStorage;
|
||||
|
||||
public class ChestedHorseStorage implements EntityStorage {
|
||||
public class ChestedHorseStorage {
|
||||
private boolean chested;
|
||||
private int liamaStrength;
|
||||
private int liamaCarpetColor = -1;
|
||||
|
@ -25,8 +25,10 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPac
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.EntityPackets1_12;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12;
|
||||
@ -76,7 +78,7 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_12Types.EntityType.PLAYER, true));
|
||||
|
||||
user.put(new ShoulderTracker(user));
|
||||
}
|
||||
|
@ -18,10 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data;
|
||||
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityStorage;
|
||||
|
||||
public class ParrotStorage implements EntityStorage {
|
||||
public class ParrotStorage {
|
||||
private boolean tamed = true;
|
||||
private boolean sitting = true;
|
||||
|
||||
|
@ -24,7 +24,6 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMa
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -236,13 +235,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
|
||||
}
|
||||
});
|
||||
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item
|
||||
data.setValue(handleItemToClient((Item) data.getValue()));
|
||||
|
||||
return data;
|
||||
protocol.getEntityPackets().filter().handler((event, meta) -> {
|
||||
if (meta.metaType().type().equals(Type.ITEM)) // Is Item
|
||||
meta.setValue(handleItemToClient((Item) meta.getValue()));
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_STATUS, new PacketRemapper() {
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.Rewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -27,8 +26,9 @@ import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
||||
public class ChatPackets1_12 extends RewriterBase<Protocol1_11_1To1_12> {
|
||||
|
||||
private final ComponentRewriter componentRewriter = new ComponentRewriter() {
|
||||
@Override
|
||||
|
@ -18,12 +18,12 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
@ -73,7 +73,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
@ -85,8 +85,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_12.SPAWN_EXPERIENCE_ORB, Entity1_12Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_12.SPAWN_GLOBAL_ENTITY, Entity1_12Types.EntityType.WEATHER);
|
||||
registerTracker(ClientboundPackets1_12.SPAWN_EXPERIENCE_ORB, Entity1_12Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_12.SPAWN_GLOBAL_ENTITY, Entity1_12Types.EntityType.WEATHER);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -113,7 +113,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_12.SPAWN_PAINTING, Entity1_12Types.EntityType.PAINTING);
|
||||
registerTracker(ClientboundPackets1_12.SPAWN_PAINTING, Entity1_12Types.EntityType.PAINTING);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.SPAWN_PLAYER, new PacketRemapper() {
|
||||
@Override
|
||||
@ -167,7 +167,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
});
|
||||
|
||||
registerRespawn(ClientboundPackets1_12.RESPAWN);
|
||||
registerEntityDestroy(ClientboundPackets1_12.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_12.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_12.ENTITY_METADATA, Types1_12.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.ENTITY_PROPERTIES, new PacketRemapper() {
|
||||
@ -212,36 +212,37 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
mapEntity(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.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).mobName("Illusioner");
|
||||
mapEntityTypeWithData(Entity1_12Types.EntityType.PARROT, Entity1_12Types.EntityType.BAT).mobName("Parrot").spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
|
||||
mapEntityTypeWithData(Entity1_12Types.EntityType.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).mobName("Illusioner");
|
||||
|
||||
// Handle Illager
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.EVOCATION_ILLAGER, true, 12).removed();
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.EVOCATION_ILLAGER, true, 13).handleIndexChange(12);
|
||||
filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).cancel(12);
|
||||
filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);
|
||||
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.ILLUSION_ILLAGER, 0).handle(e -> {
|
||||
byte mask = (byte) e.getData().getValue();
|
||||
filter().type(Entity1_12Types.EntityType.ILLUSION_ILLAGER).index(0).handler((event, meta) -> {
|
||||
byte mask = (byte) meta.getValue();
|
||||
|
||||
if ((mask & 0x20) == 0x20)
|
||||
if ((mask & 0x20) == 0x20) {
|
||||
mask &= ~0x20;
|
||||
}
|
||||
|
||||
e.getData().setValue(mask);
|
||||
return e.getData();
|
||||
meta.setValue(mask);
|
||||
});
|
||||
|
||||
// Create Parrot storage
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PARROT, true).handle(e -> {
|
||||
if (!e.getEntity().has(ParrotStorage.class))
|
||||
e.getEntity().put(new ParrotStorage());
|
||||
return e.getData();
|
||||
filter().filterFamily(Entity1_12Types.EntityType.PARROT).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
if (!data.has(ParrotStorage.class)) {
|
||||
data.put(new ParrotStorage());
|
||||
}
|
||||
});
|
||||
// Parrot remove animal metadata
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PARROT, 12).removed(); // Is baby
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PARROT, 13).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
ParrotStorage storage = e.getEntity().get(ParrotStorage.class);
|
||||
boolean isSitting = (((byte) data.getValue()) & 0x01) == 0x01;
|
||||
boolean isTamed = (((byte) data.getValue()) & 0x04) == 0x04;
|
||||
filter().type(Entity1_12Types.EntityType.PARROT).cancel(12); // Is baby
|
||||
filter().type(Entity1_12Types.EntityType.PARROT).index(13).handler((event, meta) -> {
|
||||
StoredEntityData data = storedEntityData(event);
|
||||
ParrotStorage storage = data.get(ParrotStorage.class);
|
||||
boolean isSitting = (((byte) meta.getValue()) & 0x01) == 0x01;
|
||||
boolean isTamed = (((byte) meta.getValue()) & 0x04) == 0x04;
|
||||
|
||||
if (!storage.isTamed() && isTamed) {
|
||||
// TODO do something to let the user know it's done
|
||||
@ -250,30 +251,29 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
storage.setTamed(isTamed);
|
||||
|
||||
if (isSitting) {
|
||||
data.setId(12);
|
||||
data.setValue((byte) 0x01);
|
||||
event.setIndex(12);
|
||||
meta.setValue((byte) 0x01);
|
||||
storage.setSitting(true);
|
||||
} else if (storage.isSitting()) {
|
||||
data.setId(12);
|
||||
data.setValue((byte) 0x00);
|
||||
event.setIndex(12);
|
||||
meta.setValue((byte) 0x00);
|
||||
storage.setSitting(false);
|
||||
} else
|
||||
throw RemovedValueException.EX;
|
||||
|
||||
return data;
|
||||
} else {
|
||||
event.cancel();
|
||||
}
|
||||
}); // Flags (Is sitting etc, might be useful in the future
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PARROT, 14).removed(); // Owner
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PARROT, 15).removed(); // Variant
|
||||
filter().type(Entity1_12Types.EntityType.PARROT).cancel(14); // Owner
|
||||
filter().type(Entity1_12Types.EntityType.PARROT).cancel(15); // Variant
|
||||
|
||||
// Left shoulder entity data
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PLAYER, 15).handle(e -> {
|
||||
CompoundTag tag = (CompoundTag) e.getData().getValue();
|
||||
ShoulderTracker tracker = e.getUser().get(ShoulderTracker.class);
|
||||
filter().type(Entity1_12Types.EntityType.PLAYER).index(15).handler((event, meta) -> {
|
||||
CompoundTag tag = (CompoundTag) meta.getValue();
|
||||
ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
|
||||
|
||||
if (tag.isEmpty() && tracker.getLeftShoulder() != null) {
|
||||
tracker.setLeftShoulder(null);
|
||||
tracker.update();
|
||||
} else if (tag.contains("id") && e.getEntity().getEntityId() == tracker.getEntityId()) {
|
||||
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
|
||||
String id = (String) tag.get("id").getValue();
|
||||
if (tracker.getLeftShoulder() == null || !tracker.getLeftShoulder().equals(id)) {
|
||||
tracker.setLeftShoulder(id);
|
||||
@ -281,18 +281,18 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
}
|
||||
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
});
|
||||
|
||||
// Right shoulder entity data
|
||||
registerMetaHandler().filter(Entity1_12Types.EntityType.PLAYER, 16).handle(e -> {
|
||||
CompoundTag tag = (CompoundTag) e.getData().getValue();
|
||||
ShoulderTracker tracker = e.getUser().get(ShoulderTracker.class);
|
||||
filter().type(Entity1_12Types.EntityType.PLAYER).index(16).handler((event, meta) -> {
|
||||
CompoundTag tag = (CompoundTag) event.meta().getValue();
|
||||
ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
|
||||
|
||||
if (tag.isEmpty() && tracker.getRightShoulder() != null) {
|
||||
tracker.setRightShoulder(null);
|
||||
tracker.update();
|
||||
} else if (tag.contains("id") && e.getEntity().getEntityId() == tracker.getEntityId()) {
|
||||
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
|
||||
String id = (String) tag.get("id").getValue();
|
||||
if (tracker.getRightShoulder() == null || !tracker.getRightShoulder().equals(id)) {
|
||||
tracker.setRightShoulder(id);
|
||||
@ -300,12 +300,12 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
}
|
||||
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_12Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityPackets1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.ItemPackets1_11_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
@ -47,7 +49,7 @@ public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_11Types.EntityType.PLAYER));
|
||||
}
|
||||
|
||||
public EntityPackets1_11_1 getEntityPackets() {
|
||||
|
@ -54,8 +54,8 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -82,7 +82,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
|
||||
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_11Types.EntityType.PLAYER);
|
||||
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
|
||||
|
||||
@ -102,21 +102,21 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Handle non-existing firework metadata (index 7 entity id for boosting)
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.FIREWORK, 7).removed();
|
||||
filter().type(Entity1_11Types.EntityType.FIREWORK).cancel(7);
|
||||
|
||||
// Handle non-existing pig metadata (index 14 - boost time)
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.PIG, 14).removed();
|
||||
filter().type(Entity1_11Types.EntityType.PIG).cancel(14);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -85,14 +84,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
|
||||
// Handle item metadata
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getMetaType().getType().equals(Type.ITEM)) { // Is Item
|
||||
data.setValue(handleItemToClient((Item) data.getValue()));
|
||||
protocol.getEntityPackets().filter().handler((event, meta) -> {
|
||||
if (meta.metaType().type().equals(Type.ITEM)) { // Is Item
|
||||
meta.setValue(handleItemToClient((Item) meta.getValue()));
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerP
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
|
||||
@ -99,7 +101,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_13Types.EntityType.PLAYER));
|
||||
|
||||
// Register Block Storage
|
||||
if (!user.has(BackwardsBlockStorage.class)) {
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler;
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping;
|
||||
@ -131,8 +130,8 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, Entity1_13Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, Entity1_13Types.EntityType.LIGHTNING_BOLT);
|
||||
registerTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, Entity1_13Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, Entity1_13Types.EntityType.LIGHTNING_BOLT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -156,7 +155,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = Entity1_13Types.getTypeFromId(type, false);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldId = EntityTypeMapping.getOldId(type);
|
||||
if (oldId == -1) {
|
||||
@ -220,7 +219,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
|
||||
|
||||
// Face Player (new packet)
|
||||
@ -281,30 +280,29 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Rewrite new Entity 'drowned'
|
||||
mapEntity(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
|
||||
|
||||
// Fishy
|
||||
mapEntity(Entity1_13Types.EntityType.COD, Entity1_13Types.EntityType.SQUID).mobName("Cod");
|
||||
mapEntity(Entity1_13Types.EntityType.SALMON, Entity1_13Types.EntityType.SQUID).mobName("Salmon");
|
||||
mapEntity(Entity1_13Types.EntityType.PUFFERFISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish");
|
||||
mapEntity(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.COD, Entity1_13Types.EntityType.SQUID).mobName("Cod");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.SALMON, Entity1_13Types.EntityType.SQUID).mobName("Salmon");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.PUFFERFISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish");
|
||||
|
||||
// Phantom
|
||||
mapEntity(Entity1_13Types.EntityType.PHANTOM, Entity1_13Types.EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> {
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.PHANTOM, Entity1_13Types.EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> {
|
||||
// The phantom is grey/blue so let's do yellow/blue
|
||||
storage.add(new Metadata(15, MetaType1_12.VarInt, 3));
|
||||
});
|
||||
|
||||
// Dolphin
|
||||
mapEntity(Entity1_13Types.EntityType.DOLPHIN, Entity1_13Types.EntityType.SQUID).mobName("Dolphin");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.DOLPHIN, Entity1_13Types.EntityType.SQUID).mobName("Dolphin");
|
||||
|
||||
// Turtle
|
||||
mapEntity(Entity1_13Types.EntityType.TURTLE, Entity1_13Types.EntityType.OCELOT).mobName("Turtle");
|
||||
mapEntityTypeWithData(Entity1_13Types.EntityType.TURTLE, Entity1_13Types.EntityType.OCELOT).mobName("Turtle");
|
||||
|
||||
// Rewrite Meta types
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int typeId = meta.getMetaType().getTypeID();
|
||||
filter().handler((event, meta) -> {
|
||||
int typeId = meta.metaType().typeId();
|
||||
|
||||
// Rewrite optional chat to chat
|
||||
if (typeId == 5) {
|
||||
@ -334,63 +332,49 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
));
|
||||
}
|
||||
|
||||
return meta;
|
||||
});
|
||||
|
||||
// Rewrite Custom Name from Chat to String
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.ENTITY, true, 2).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
filter().filterFamily(Entity1_13Types.EntityType.ENTITY).index(2).handler((event, meta) -> {
|
||||
String value = meta.getValue().toString();
|
||||
if (value.isEmpty()) return meta;
|
||||
meta.setValue(ChatRewriter.jsonToLegacyText(value));
|
||||
return meta;
|
||||
if (!value.isEmpty()) {
|
||||
meta.setValue(ChatRewriter.jsonToLegacyText(value));
|
||||
}
|
||||
});
|
||||
|
||||
// Handle zombie metadata
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.ZOMBIE, true, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.ZOMBIE, true).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
|
||||
if (meta.getId() > 15) {
|
||||
meta.setId(meta.getId() - 1);
|
||||
}
|
||||
|
||||
return meta;
|
||||
});
|
||||
filter().filterFamily(Entity1_13Types.EntityType.ZOMBIE).removeIndex(15);
|
||||
|
||||
// Handle turtle metadata (Remove them all for now)
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 13).removed(); // Home pos
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 14).removed(); // Has egg
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 15).removed(); // Laying egg
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 16).removed(); // Travel pos
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 17).removed(); // Going home
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TURTLE, 18).removed(); // Traveling
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(13); // Home pos
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(14); // Has egg
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(15); // Laying egg
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(16); // Travel pos
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(17); // Going home
|
||||
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(18); // Traveling
|
||||
|
||||
// Remove additional fish meta
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.ABSTRACT_FISHES, true, 12).removed();
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.ABSTRACT_FISHES, true, 13).removed();
|
||||
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_FISHES).cancel(12);
|
||||
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_FISHES).cancel(13);
|
||||
|
||||
// Remove phantom size
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.PHANTOM, 12).removed();
|
||||
filter().type(Entity1_13Types.EntityType.PHANTOM).cancel(12);
|
||||
|
||||
// Remove boat splash timer
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.BOAT, 12).removed();
|
||||
filter().type(Entity1_13Types.EntityType.BOAT).cancel(12);
|
||||
|
||||
// Remove Trident special loyalty level
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TRIDENT, 7).removed();
|
||||
filter().type(Entity1_13Types.EntityType.TRIDENT).cancel(7);
|
||||
|
||||
// Handle new wolf colors
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.WOLF, 17).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
filter().type(Entity1_13Types.EntityType.WOLF).index(17).handler((event, meta) -> {
|
||||
|
||||
meta.setValue(15 - (int) meta.getValue());
|
||||
|
||||
return meta;
|
||||
});
|
||||
|
||||
// Rewrite AreaEffectCloud
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD, 9).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
filter().type(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> {
|
||||
Particle particle = (Particle) meta.getValue();
|
||||
|
||||
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
|
||||
@ -408,16 +392,16 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
secondArg = particleArgs.length == 2 ? particleArgs[1] : 0;
|
||||
}
|
||||
|
||||
e.createMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
|
||||
e.createMeta(new Metadata(10, MetaType1_12.VarInt, firstArg));
|
||||
e.createMeta(new Metadata(11, MetaType1_12.VarInt, secondArg));
|
||||
event.createExtraMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
|
||||
event.createExtraMeta(new Metadata(10, MetaType1_12.VarInt, firstArg));
|
||||
event.createExtraMeta(new Metadata(11, MetaType1_12.VarInt, secondArg));
|
||||
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@ -427,7 +411,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldEntityId(final int newId) {
|
||||
public int newEntityId(final int newId) {
|
||||
return EntityTypeMapping.getOldId(newId);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.Rewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
|
||||
@ -40,6 +39,7 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@ -47,7 +47,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
|
||||
private final CommandRewriter commandRewriter = new CommandRewriter(protocol) {
|
||||
};
|
||||
@ -93,16 +93,16 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
for (int i = 0; i < size; i++) {
|
||||
//Input Item
|
||||
Item input = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input));
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(input));
|
||||
//Output Item
|
||||
Item output = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output));
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(output));
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
|
||||
if (secondItem) {
|
||||
//Second Item
|
||||
Item second = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second));
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(second));
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
|
||||
@ -448,7 +448,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
case "MC|BEdit":
|
||||
wrapper.setId(0x0B);
|
||||
Item book = wrapper.read(Type.ITEM);
|
||||
wrapper.write(Type.FLAT_ITEM, getProtocol().getBlockItemPackets().handleItemToServer(book));
|
||||
wrapper.write(Type.FLAT_ITEM, protocol.getBlockItemPackets().handleItemToServer(book));
|
||||
boolean signing = channel.equals("MC|BSign");
|
||||
wrapper.write(Type.BOOLEAN, signing);
|
||||
break;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.Rewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
@ -26,8 +25,9 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
public class SoundPackets1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
|
||||
|
||||
public SoundPackets1_13(Protocol1_12_2To1_13 protocol) {
|
||||
|
@ -54,7 +54,7 @@ public class EntityPackets1_13_2 {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
|
||||
if (metadata.getMetaType() == MetaType1_13_2.Slot) {
|
||||
if (metadata.metaType() == MetaType1_13_2.Slot) {
|
||||
metadata.setMetaType(MetaType1_13.Slot);
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class EntityPackets1_13_2 {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
|
||||
if (metadata.getMetaType() == MetaType1_13_2.Slot) {
|
||||
if (metadata.metaType() == MetaType1_13_2.Slot) {
|
||||
metadata.setMetaType(MetaType1_13.Slot);
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,7 @@ public class EntityPackets1_13_2 {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
|
||||
if (metadata.getMetaType() == MetaType1_13_2.Slot) {
|
||||
if (metadata.metaType() == MetaType1_13_2.Slot) {
|
||||
metadata.setMetaType(MetaType1_13.Slot);
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,12 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.PlayerP
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.SoundPackets1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
@ -71,7 +73,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
new PlayerPackets1_14(this).register();
|
||||
new SoundPackets1_14(this).register();
|
||||
|
||||
new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_14.STATISTICS);
|
||||
new StatisticsRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_14.STATISTICS);
|
||||
|
||||
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
|
||||
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
|
||||
@ -187,7 +189,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_14Types.PLAYER, true));
|
||||
|
||||
if (!user.has(ChunkLightStorage.class)) {
|
||||
user.put(new ChunkLightStorage(user));
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
@ -276,7 +275,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType entityType = wrapper.user().get(EntityTracker.class).get(getProtocol()).getEntityType(entityId);
|
||||
EntityType entityType = wrapper.user().getEntityTracker(Protocol1_13_2To1_14.class).entityType(entityId);
|
||||
if (entityType == null) return;
|
||||
|
||||
if (entityType.isOrHasParent(Entity1_14Types.ABSTRACT_HORSE)) {
|
||||
|
@ -18,15 +18,13 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.entities.meta.MetaHandler;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.VillagerData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
|
||||
@ -43,8 +41,10 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandler;
|
||||
|
||||
public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14> {
|
||||
|
||||
@ -54,6 +54,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
super(protocol, MetaType1_13_2.OptChat, MetaType1_13_2.Boolean);
|
||||
}
|
||||
|
||||
//TODO work the method into this class alone
|
||||
@Override
|
||||
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
|
||||
super.addTrackedEntity(wrapper, entityId, type);
|
||||
@ -62,7 +63,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
if (type == Entity1_14Types.PAINTING) {
|
||||
final Position position = wrapper.get(Type.POSITION, 0);
|
||||
positionHandler.cacheEntityPosition(wrapper, position.getX(), position.getY(), position.getZ(), true, false);
|
||||
} else if (wrapper.getId() != 0x25) { // ignore join game
|
||||
} else if (wrapper.getId() != ClientboundPackets1_14.JOIN_GAME.getId()) { // ignore join game
|
||||
positionHandler.cacheEntityPosition(wrapper, true, false);
|
||||
}
|
||||
}
|
||||
@ -80,8 +81,8 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
// Check for death status
|
||||
if (status != 3) return;
|
||||
|
||||
EntityTracker.ProtocolEntityTracker tracker = getEntityTracker(wrapper.user());
|
||||
EntityType entityType = tracker.getEntityType(entityId);
|
||||
EntityTracker tracker = tracker(wrapper.user());
|
||||
EntityType entityType = tracker.entityType(entityId);
|
||||
if (entityType != Entity1_14Types.PLAYER) return;
|
||||
|
||||
// Remove equipment, else the client will see ghost items
|
||||
@ -150,7 +151,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int id = wrapper.get(Type.BYTE, 0);
|
||||
int mappedId = getOldEntityId(id);
|
||||
int mappedId = newEntityId(id);
|
||||
Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(mappedId, false);
|
||||
Entity1_13Types.ObjectType objectType;
|
||||
if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) {
|
||||
@ -223,14 +224,14 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
EntityType entityType = Entity1_14Types.getTypeFromId(type);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldId = typeMapping.get(type);
|
||||
int oldId = newEntityId(type);
|
||||
if (oldId == -1) {
|
||||
EntityData entityData = getEntityData(entityType);
|
||||
EntityData entityData = entityDataForType(entityType);
|
||||
if (entityData == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType);
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.set(Type.VAR_INT, 1, entityData.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, entityData.replacementId());
|
||||
}
|
||||
} else {
|
||||
wrapper.set(Type.VAR_INT, 1, oldId);
|
||||
@ -243,7 +244,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
});
|
||||
|
||||
getProtocol().registerClientbound(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, new PacketRemapper() {
|
||||
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity id
|
||||
@ -254,7 +255,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
});
|
||||
|
||||
getProtocol().registerClientbound(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, new PacketRemapper() {
|
||||
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity id
|
||||
@ -297,7 +298,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() {
|
||||
@ -346,142 +347,113 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
protected void registerRewrites() {
|
||||
mapTypes(Entity1_14Types.values(), Entity1_13Types.EntityType.class);
|
||||
|
||||
mapEntity(Entity1_14Types.CAT, Entity1_14Types.OCELOT).jsonName("Cat");
|
||||
mapEntity(Entity1_14Types.TRADER_LLAMA, Entity1_14Types.LLAMA).jsonName("Trader Llama");
|
||||
mapEntity(Entity1_14Types.FOX, Entity1_14Types.WOLF).jsonName("Fox");
|
||||
mapEntity(Entity1_14Types.PANDA, Entity1_14Types.POLAR_BEAR).jsonName("Panda");
|
||||
mapEntity(Entity1_14Types.PILLAGER, Entity1_14Types.VILLAGER).jsonName("Pillager");
|
||||
mapEntity(Entity1_14Types.WANDERING_TRADER, Entity1_14Types.VILLAGER).jsonName("Wandering Trader");
|
||||
mapEntity(Entity1_14Types.RAVAGER, Entity1_14Types.COW).jsonName("Ravager");
|
||||
mapEntityTypeWithData(Entity1_14Types.CAT, Entity1_14Types.OCELOT).jsonName("Cat");
|
||||
mapEntityTypeWithData(Entity1_14Types.TRADER_LLAMA, Entity1_14Types.LLAMA).jsonName("Trader Llama");
|
||||
mapEntityTypeWithData(Entity1_14Types.FOX, Entity1_14Types.WOLF).jsonName("Fox");
|
||||
mapEntityTypeWithData(Entity1_14Types.PANDA, Entity1_14Types.POLAR_BEAR).jsonName("Panda");
|
||||
mapEntityTypeWithData(Entity1_14Types.PILLAGER, Entity1_14Types.VILLAGER).jsonName("Pillager");
|
||||
mapEntityTypeWithData(Entity1_14Types.WANDERING_TRADER, Entity1_14Types.VILLAGER).jsonName("Wandering Trader");
|
||||
mapEntityTypeWithData(Entity1_14Types.RAVAGER, Entity1_14Types.COW).jsonName("Ravager");
|
||||
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int typeId = meta.getMetaType().getTypeID();
|
||||
filter().handler((event, meta) -> {
|
||||
int typeId = meta.metaType().typeId();
|
||||
if (typeId <= 15) {
|
||||
meta.setMetaType(MetaType1_13_2.byId(typeId));
|
||||
}
|
||||
|
||||
MetaType type = meta.getMetaType();
|
||||
MetaType type = meta.metaType();
|
||||
|
||||
if (type == MetaType1_13_2.Slot) {
|
||||
Item item = (Item) meta.getValue();
|
||||
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item));
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
|
||||
} else if (type == MetaType1_13_2.BlockID) {
|
||||
int blockstate = (Integer) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
|
||||
}
|
||||
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.PILLAGER, 15).removed();
|
||||
filter().type(Entity1_14Types.PILLAGER).cancel(15);
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.FOX, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.FOX, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.FOX, 17).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.FOX, 18).removed();
|
||||
filter().type(Entity1_14Types.FOX).cancel(15);
|
||||
filter().type(Entity1_14Types.FOX).cancel(16);
|
||||
filter().type(Entity1_14Types.FOX).cancel(17);
|
||||
filter().type(Entity1_14Types.FOX).cancel(18);
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 17).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 18).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 19).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.PANDA, 20).removed();
|
||||
filter().type(Entity1_14Types.PANDA).cancel(15);
|
||||
filter().type(Entity1_14Types.PANDA).cancel(16);
|
||||
filter().type(Entity1_14Types.PANDA).cancel(17);
|
||||
filter().type(Entity1_14Types.PANDA).cancel(18);
|
||||
filter().type(Entity1_14Types.PANDA).cancel(19);
|
||||
filter().type(Entity1_14Types.PANDA).cancel(20);
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.CAT, 18).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.CAT, 19).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.CAT, 20).removed();
|
||||
filter().type(Entity1_14Types.CAT).cancel(18);
|
||||
filter().type(Entity1_14Types.CAT).cancel(19);
|
||||
filter().type(Entity1_14Types.CAT).cancel(20);
|
||||
|
||||
registerMetaHandler().handle(e -> {
|
||||
EntityType type = e.getEntity().getType();
|
||||
Metadata meta = e.getData();
|
||||
filter().handler((event, meta) -> {
|
||||
EntityType type = event.entityType();
|
||||
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE) || type == Entity1_14Types.RAVAGER || type == Entity1_14Types.WITCH) {
|
||||
int index = e.getIndex();
|
||||
int index = event.index();
|
||||
if (index == 14) {
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
} else if (index > 14) {
|
||||
meta.setId(index - 1);
|
||||
event.setIndex(index - 1);
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.AREA_EFFECT_CLOUD, 10).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
filter().type(Entity1_14Types.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> {
|
||||
rewriteParticle((Particle) meta.getValue());
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.FIREWORK_ROCKET, 8).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
filter().type(Entity1_14Types.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
|
||||
meta.setMetaType(MetaType1_13_2.VarInt);
|
||||
Integer value = (Integer) meta.getValue();
|
||||
if (value == null) meta.setValue(0);
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.ABSTRACT_ARROW, true).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int index = e.getIndex();
|
||||
if (index == 9) {
|
||||
throw RemovedValueException.EX;
|
||||
} else if (index > 9) {
|
||||
meta.setId(index - 1);
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
filter().filterFamily(Entity1_14Types.ABSTRACT_ARROW).removeIndex(9);
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.VILLAGER, 15).removed(); // Head shake timer
|
||||
filter().type(Entity1_14Types.VILLAGER).cancel(15); // Head shake timer
|
||||
|
||||
MetaHandler villagerDataHandler = e -> {
|
||||
Metadata meta = e.getData();
|
||||
MetaHandler villagerDataHandler = (event, meta) -> {
|
||||
VillagerData villagerData = (VillagerData) meta.getValue();
|
||||
meta.setValue(villagerDataToProfession(villagerData));
|
||||
meta.setMetaType(MetaType1_13_2.VarInt);
|
||||
if (meta.getId() == 16) {
|
||||
meta.setId(15); // decreased by 2 again in one of the following handlers
|
||||
if (meta.id() == 16) {
|
||||
event.setIndex(15); // decreased by 2 again in one of the following handlers
|
||||
}
|
||||
return meta;
|
||||
};
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.ZOMBIE_VILLAGER, 18).handle(villagerDataHandler);
|
||||
registerMetaHandler().filter(Entity1_14Types.VILLAGER, 16).handle(villagerDataHandler);
|
||||
filter().type(Entity1_14Types.ZOMBIE_VILLAGER).index(18).handler(villagerDataHandler);
|
||||
filter().type(Entity1_14Types.VILLAGER).index(16).handler(villagerDataHandler);
|
||||
|
||||
// Holding arms up - from bitfield into own boolean
|
||||
registerMetaHandler().filter(Entity1_14Types.ABSTRACT_SKELETON, true, 13).handle(e -> {
|
||||
byte value = (byte) e.getData().getValue();
|
||||
filter().filterFamily(Entity1_14Types.ABSTRACT_SKELETON).index(13).handler((event, meta) -> {
|
||||
byte value = (byte) meta.getValue();
|
||||
if ((value & 4) != 0) {
|
||||
e.createMeta(new Metadata(14, MetaType1_13_2.Boolean, true));
|
||||
event.createExtraMeta(new Metadata(14, MetaType1_13_2.Boolean, true));
|
||||
}
|
||||
return e.getData();
|
||||
});
|
||||
registerMetaHandler().filter(Entity1_14Types.ZOMBIE, true, 13).handle(e -> {
|
||||
byte value = (byte) e.getData().getValue();
|
||||
filter().filterFamily(Entity1_14Types.ZOMBIE).index(13).handler((event, meta) -> {
|
||||
byte value = (byte) meta.getValue();
|
||||
if ((value & 4) != 0) {
|
||||
e.createMeta(new Metadata(16, MetaType1_13_2.Boolean, true));
|
||||
event.createExtraMeta(new Metadata(16, MetaType1_13_2.Boolean, true));
|
||||
}
|
||||
return e.getData();
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.ZOMBIE, true).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int index = e.getIndex();
|
||||
if (index >= 16) {
|
||||
meta.setId(index + 1);
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
filter().filterFamily(Entity1_14Types.ZOMBIE).addIndex(16);
|
||||
|
||||
// Remove bed location
|
||||
registerMetaHandler().filter(Entity1_14Types.LIVINGENTITY, true).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int index = e.getIndex();
|
||||
filter().filterFamily(Entity1_14Types.LIVINGENTITY).handler((event, meta) -> {
|
||||
int index = event.index();
|
||||
if (index == 12) {
|
||||
Position position = (Position) meta.getValue();
|
||||
if (position != null) {
|
||||
// Use bed
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x33, null, e.getUser());
|
||||
wrapper.write(Type.VAR_INT, e.getEntity().getEntityId());
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x33, null, event.user());
|
||||
wrapper.write(Type.VAR_INT, event.entityId());
|
||||
wrapper.write(Type.POSITION, position);
|
||||
|
||||
try {
|
||||
@ -491,50 +463,34 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
}
|
||||
|
||||
throw RemovedValueException.EX;
|
||||
event.cancel();
|
||||
} else if (index > 12) {
|
||||
meta.setId(index - 1);
|
||||
event.setIndex(index - 1);
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int index = e.getIndex();
|
||||
if (index == 6) {
|
||||
throw RemovedValueException.EX;
|
||||
} else if (index > 6) {
|
||||
meta.setId(index - 1);
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
// Something
|
||||
filter().removeIndex(6);
|
||||
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
int typeId = meta.getMetaType().getTypeID();
|
||||
filter().handler((event, meta) -> {
|
||||
int typeId = meta.metaType().typeId();
|
||||
if (typeId > 15) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("New 1.14 metadata was not handled: " + meta + " entity: " + e.getEntity().getType());
|
||||
return null;
|
||||
ViaBackwards.getPlatform().getLogger().warning("New 1.14 metadata was not handled: " + meta + " entity: " + event.entityType());
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.OCELOT, 13).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
meta.setId(15);
|
||||
filter().type(Entity1_14Types.OCELOT).index(13).handler((event, meta) -> {
|
||||
event.setIndex(15);
|
||||
meta.setMetaType(MetaType1_13_2.VarInt);
|
||||
meta.setValue(0);
|
||||
return meta;
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_14Types.CAT).handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
if (meta.getId() == 15) {
|
||||
filter().type(Entity1_14Types.CAT).handler((event, meta) -> {
|
||||
if (event.index() == 15) {
|
||||
meta.setValue(1);
|
||||
} else if (meta.getId() == 13) {
|
||||
} else if (event.index() == 13) {
|
||||
meta.setValue((byte) ((byte) meta.getValue() & 0x4));
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
}
|
||||
|
||||
@ -566,7 +522,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_14Types.getTypeFromId(typeId);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.Rewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -26,8 +25,9 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
public class PlayerPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
|
||||
public class PlayerPackets1_14 extends RewriterBase<Protocol1_13_2To1_14> {
|
||||
|
||||
public PlayerPackets1_14(Protocol1_13_2To1_14 protocol) {
|
||||
super(protocol);
|
||||
|
@ -18,17 +18,17 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.Rewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.rewriter.RewriterBase;
|
||||
|
||||
public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
|
||||
public class SoundPackets1_14 extends RewriterBase<Protocol1_13_2To1_14> {
|
||||
|
||||
public SoundPackets1_14(Protocol1_13_2To1_14 protocol) {
|
||||
super(protocol);
|
||||
@ -55,7 +55,7 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
|
||||
int category = wrapper.read(Type.VAR_INT);
|
||||
int entityId = wrapper.read(Type.VAR_INT);
|
||||
|
||||
EntityTracker.StoredEntity storedEntity = wrapper.user().get(EntityTracker.class).get(protocol).getEntity(entityId);
|
||||
StoredEntityData storedEntity = wrapper.user().getEntityTracker(protocol.getClass()).entityData(entityId);
|
||||
EntityPositionStorage1_14 entityStorage;
|
||||
if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
|
||||
|
@ -19,19 +19,20 @@ package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappings;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.data.CommandRewriter1_13_1;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
@ -215,12 +216,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
// Register EntityTracker if it doesn't exist yet.
|
||||
if (!user.has(EntityTracker.class))
|
||||
user.put(new EntityTracker(user));
|
||||
|
||||
// Init protocol in EntityTracker
|
||||
user.get(EntityTracker.class).initProtocol(this);
|
||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, Entity1_13Types.EntityType.PLAYER));
|
||||
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld(user));
|
||||
|
@ -18,7 +18,6 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
|
||||
@ -34,6 +33,8 @@ import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13_1> {
|
||||
|
||||
public EntityPackets1_13_1(Protocol1_13To1_13_1 protocol) {
|
||||
@ -73,14 +74,14 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
|
||||
}
|
||||
|
||||
// Track Entity
|
||||
addTrackedEntity(wrapper, entityId, entType);
|
||||
tracker(wrapper.user()).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, Entity1_13Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, Entity1_13Types.EntityType.LIGHTNING_BOLT);
|
||||
registerTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, Entity1_13Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, Entity1_13Types.EntityType.LIGHTNING_BOLT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -106,13 +107,8 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0));
|
||||
handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0), storage);
|
||||
|
||||
// Don't handle new ids / base meta since it's not used for this version
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(Types1_13.METADATA_LIST, 0, storage.getMetaDataList());
|
||||
List<Metadata> metadata = wrapper.get(Types1_13.METADATA_LIST, 0);
|
||||
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -134,58 +130,46 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_13.SPAWN_PAINTING, Entity1_13Types.EntityType.PAINTING);
|
||||
registerTracker(ClientboundPackets1_13.SPAWN_PAINTING, Entity1_13Types.EntityType.PAINTING);
|
||||
registerJoinGame(ClientboundPackets1_13.JOIN_GAME, Entity1_13Types.EntityType.PLAYER);
|
||||
registerRespawn(ClientboundPackets1_13.RESPAWN);
|
||||
registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Rewrite items & blocks
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
if (meta.getMetaType() == MetaType1_13.Slot) {
|
||||
filter().handler((event, meta) -> {
|
||||
if (meta.metaType() == MetaType1_13.Slot) {
|
||||
InventoryPackets1_13_1.toClient((Item) meta.getValue());
|
||||
} else if (meta.getMetaType() == MetaType1_13.BlockID) {
|
||||
} else if (meta.metaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (meta.getMetaType() == MetaType1_13.PARTICLE) {
|
||||
} else if (meta.metaType() == MetaType1_13.PARTICLE) {
|
||||
rewriteParticle((Particle) meta.getValue());
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
// Remove shooter UUID
|
||||
registerMetaHandler().
|
||||
filter(Entity1_13Types.EntityType.ABSTRACT_ARROW, true, 7)
|
||||
.removed();
|
||||
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_ARROW).cancel(7);
|
||||
|
||||
// Move colors to old position
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.SPECTRAL_ARROW, 8)
|
||||
.handleIndexChange(7);
|
||||
filter().type(Entity1_13Types.EntityType.SPECTRAL_ARROW).index(8).toIndex(7);
|
||||
|
||||
// Move loyalty level to old position
|
||||
registerMetaHandler().filter(Entity1_13Types.EntityType.TRIDENT, 8)
|
||||
.handleIndexChange(7);
|
||||
filter().type(Entity1_13Types.EntityType.TRIDENT).index(8).toIndex(7);
|
||||
|
||||
// Rewrite Minecart blocks
|
||||
registerMetaHandler()
|
||||
.filter(Entity1_13Types.EntityType.MINECART_ABSTRACT, true, 9)
|
||||
.handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
|
||||
int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
|
||||
return meta;
|
||||
});
|
||||
filter().filterFamily(Entity1_13Types.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
|
||||
int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_14_4to1_15;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappings;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
|
||||
@ -27,9 +26,11 @@ import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateR
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPackets1_15;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets.EntityPackets1_15;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
@ -105,10 +106,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
|
||||
if (!user.has(ImmediateRespawn.class)) {
|
||||
user.put(new ImmediateRespawn(user));
|
||||
}
|
||||
if (!user.has(EntityTracker.class)) {
|
||||
user.put(new EntityTracker(user));
|
||||
}
|
||||
user.get(EntityTracker.class).initProtocol(this);
|
||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, Entity1_15Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_15 getBlockItemPackets() {
|
||||
|
@ -17,21 +17,17 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
|
||||
@ -74,7 +70,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
}
|
||||
});
|
||||
|
||||
registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
|
||||
registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -96,7 +92,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
handler(wrapper -> {
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = Entity1_15Types.getTypeFromId(type);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type));
|
||||
});
|
||||
}
|
||||
@ -130,9 +126,9 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, Entity1_15Types.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, Entity1_15Types.LIGHTNING_BOLT);
|
||||
registerExtraTracker(ClientboundPackets1_15.SPAWN_PAINTING, Entity1_15Types.PAINTING);
|
||||
registerTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, Entity1_15Types.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, Entity1_15Types.LIGHTNING_BOLT);
|
||||
registerTracker(ClientboundPackets1_15.SPAWN_PAINTING, Entity1_15Types.PAINTING);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PLAYER, new PacketRemapper() {
|
||||
@Override
|
||||
@ -150,7 +146,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_15.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
|
||||
|
||||
// Attributes (get rid of generic.flyingSpeed for the Bee remap)
|
||||
@ -161,7 +157,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
map(Type.INT);
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType entityType = getEntityType(wrapper.user(), entityId);
|
||||
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
|
||||
if (entityType != Entity1_15Types.BEE) return;
|
||||
|
||||
int size = wrapper.get(Type.INT, 0);
|
||||
@ -199,62 +195,35 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
MetaType type = meta.getMetaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
Item item = (Item) meta.getValue();
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
int blockstate = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
rewriteParticle((Particle) meta.getValue());
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
registerMetaTypeHandler(MetaType1_14.Slot, MetaType1_14.BlockID, MetaType1_14.PARTICLE, null);
|
||||
|
||||
registerMetaHandler().filter(Entity1_15Types.LIVINGENTITY, true).handle(e -> {
|
||||
int index = e.getIndex();
|
||||
if (index == 12) {
|
||||
throw RemovedValueException.EX;
|
||||
} else if (index > 12) {
|
||||
e.getData().setId(index - 1);
|
||||
}
|
||||
return e.getData();
|
||||
});
|
||||
filter().filterFamily(Entity1_15Types.LIVINGENTITY).removeIndex(12);
|
||||
|
||||
registerMetaHandler().filter(Entity1_15Types.BEE, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_15Types.BEE, 16).removed();
|
||||
filter().type(Entity1_15Types.BEE).cancel(15);
|
||||
filter().type(Entity1_15Types.BEE).cancel(16);
|
||||
|
||||
mapEntity(Entity1_15Types.BEE, Entity1_15Types.PUFFERFISH).jsonName("Bee").spawnMetadata(storage -> {
|
||||
mapEntityTypeWithData(Entity1_15Types.BEE, Entity1_15Types.PUFFERFISH).jsonName("Bee").spawnMetadata(storage -> {
|
||||
storage.add(new Metadata(14, MetaType1_14.Boolean, false));
|
||||
storage.add(new Metadata(15, MetaType1_14.VarInt, 2));
|
||||
});
|
||||
|
||||
registerMetaHandler().filter(Entity1_15Types.ENDERMAN, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_15Types.TRIDENT, 10).removed();
|
||||
filter().type(Entity1_15Types.ENDERMAN).cancel(16);
|
||||
filter().type(Entity1_15Types.TRIDENT).cancel(10);
|
||||
|
||||
registerMetaHandler().filter(Entity1_15Types.WOLF).handle(e -> {
|
||||
int index = e.getIndex();
|
||||
if (index >= 17) {
|
||||
e.getData().setId(index + 1); // redundant health removed in 1.15
|
||||
}
|
||||
return e.getData();
|
||||
});
|
||||
registerMetaHandler().filter(Entity1_15Types.WOLF, 8).handle(e -> {
|
||||
e.createMeta(new Metadata(17/*WOLF_HEALTH*/, MetaType1_14.Float, e.getData().getValue()));
|
||||
return e.getData();
|
||||
// Redundant health removed in 1.15
|
||||
filter().type(Entity1_15Types.WOLF).addIndex(17);
|
||||
filter().type(Entity1_15Types.WOLF).index(8).handler((event, meta) -> {
|
||||
event.createExtraMeta(new Metadata(17/*WOLF_HEALTH*/, MetaType1_14.Float, event.meta().value()));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_15Types.getTypeFromId(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldEntityId(final int newId) {
|
||||
public int newEntityId(final int newId) {
|
||||
return EntityTypeMapping.getOldEntityId(newId);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_14to1_14_1;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.packets.EntityPackets1_14_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
|
||||
|
||||
@ -36,6 +38,6 @@ public class Protocol1_14To1_14_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_15Types.PLAYER));
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -29,6 +29,8 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntityPackets1_14_1 extends LegacyEntityRewriter<Protocol1_14To1_14_1> {
|
||||
|
||||
public EntityPackets1_14_1(Protocol1_14To1_14_1 protocol) {
|
||||
@ -37,12 +39,12 @@ public class EntityPackets1_14_1 extends LegacyEntityRewriter<Protocol1_14To1_14
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerExtraTracker(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, Entity1_14Types.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, Entity1_14Types.LIGHTNING_BOLT);
|
||||
registerExtraTracker(ClientboundPackets1_14.SPAWN_PAINTING, Entity1_14Types.PAINTING);
|
||||
registerExtraTracker(ClientboundPackets1_14.SPAWN_PLAYER, Entity1_14Types.PLAYER);
|
||||
registerExtraTracker(ClientboundPackets1_14.JOIN_GAME, Entity1_14Types.PLAYER, Type.INT);
|
||||
registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES);
|
||||
registerTracker(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, Entity1_14Types.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, Entity1_14Types.LIGHTNING_BOLT);
|
||||
registerTracker(ClientboundPackets1_14.SPAWN_PAINTING, Entity1_14Types.PAINTING);
|
||||
registerTracker(ClientboundPackets1_14.SPAWN_PLAYER, Entity1_14Types.PLAYER);
|
||||
registerTracker(ClientboundPackets1_14.JOIN_GAME, Entity1_14Types.PLAYER, Type.INT);
|
||||
registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_ENTITY, new PacketRemapper() {
|
||||
@Override
|
||||
@ -79,10 +81,10 @@ public class EntityPackets1_14_1 extends LegacyEntityRewriter<Protocol1_14To1_14
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
// Register Type ID
|
||||
addTrackedEntity(wrapper, entityId, Entity1_14Types.getTypeFromId(type));
|
||||
tracker(wrapper.user()).addEntity(entityId, Entity1_14Types.getTypeFromId(type));
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_14.METADATA_LIST, 0));
|
||||
handleMeta(wrapper.user(), entityId, storage);
|
||||
List<Metadata> metadata = wrapper.get(Types1_14.METADATA_LIST, 0);
|
||||
handleMetadata(entityId, metadata, wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -94,13 +96,13 @@ public class EntityPackets1_14_1 extends LegacyEntityRewriter<Protocol1_14To1_14
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaHandler().filter(Entity1_14Types.VILLAGER, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_14Types.VILLAGER, 16).handleIndexChange(15);
|
||||
registerMetaHandler().filter(Entity1_14Types.WANDERING_TRADER, 15).removed();
|
||||
filter().type(Entity1_14Types.VILLAGER).cancel(15);
|
||||
filter().type(Entity1_14Types.VILLAGER).index(16).toIndex(15);
|
||||
filter().type(Entity1_14Types.WANDERING_TRADER).cancel(15);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_14Types.getTypeFromId(typeId);
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,11 @@ import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockIt
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
|
||||
@ -133,9 +135,9 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
});
|
||||
|
||||
new TagRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
|
||||
new TagRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
|
||||
|
||||
new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16.STATISTICS);
|
||||
new StatisticsRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_16.STATISTICS);
|
||||
|
||||
registerServerbound(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {
|
||||
@Override
|
||||
@ -200,13 +202,14 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
user.put(new PlayerSneakStorage(user));
|
||||
user.put(new WorldNameTracker(user));
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_16 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter getTranslatableRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -75,7 +74,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
map(Type.BYTE); // 7 - Yaw
|
||||
map(Type.INT); // 8 - Data
|
||||
handler(wrapper -> {
|
||||
EntityType entityType = getTypeFromId(wrapper.get(Type.VAR_INT, 1));
|
||||
EntityType entityType = typeFromId(wrapper.get(Type.VAR_INT, 1));
|
||||
if (entityType == Entity1_16Types.LIGHTNING_BOLT) {
|
||||
// Map to old weather entity packet
|
||||
wrapper.cancel();
|
||||
@ -89,7 +88,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
spawnLightningPacket.send(Protocol1_15_2To1_16.class, true, true);
|
||||
}
|
||||
});
|
||||
handler(getSpawnTracketWithDataHandler(Entity1_16Types.FALLING_BLOCK));
|
||||
handler(getSpawnTrackerWithDataHandler(Entity1_16Types.FALLING_BLOCK));
|
||||
}
|
||||
});
|
||||
|
||||
@ -156,7 +155,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
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), Entity1_16Types.PLAYER);
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
|
||||
|
||||
wrapper.write(Type.STRING, "default"); // Level type
|
||||
|
||||
@ -172,11 +171,11 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_16.SPAWN_EXPERIENCE_ORB, Entity1_16Types.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_16.SPAWN_EXPERIENCE_ORB, Entity1_16Types.EXPERIENCE_ORB);
|
||||
// F Spawn Global Object, it is no longer with us :(
|
||||
registerExtraTracker(ClientboundPackets1_16.SPAWN_PAINTING, Entity1_16Types.PAINTING);
|
||||
registerExtraTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16Types.PLAYER);
|
||||
registerEntityDestroy(ClientboundPackets1_16.DESTROY_ENTITIES);
|
||||
registerTracker(ClientboundPackets1_16.SPAWN_PAINTING, Entity1_16Types.PAINTING);
|
||||
registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16Types.PLAYER);
|
||||
registerRemoveEntities(ClientboundPackets1_16.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.ENTITY_PROPERTIES, new PacketRemapper() {
|
||||
@ -244,9 +243,8 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
MetaType type = meta.getMetaType();
|
||||
filter().handler((event, meta) -> {
|
||||
MetaType type = meta.metaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
@ -254,52 +252,49 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
rewriteParticle((Particle) meta.getValue());
|
||||
} else if (type == MetaType1_14.OptChat) {
|
||||
JsonElement text = meta.getCastedValue();
|
||||
JsonElement text = meta.value();
|
||||
if (text != null) {
|
||||
protocol.getTranslatableRewriter().processText(text);
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
mapEntityDirect(Entity1_16Types.ZOMBIFIED_PIGLIN, Entity1_15Types.ZOMBIE_PIGMAN);
|
||||
mapEntityType(Entity1_16Types.ZOMBIFIED_PIGLIN, Entity1_15Types.ZOMBIE_PIGMAN);
|
||||
mapTypes(Entity1_16Types.values(), Entity1_15Types.class);
|
||||
|
||||
mapEntity(Entity1_16Types.HOGLIN, Entity1_16Types.COW).jsonName("Hoglin");
|
||||
mapEntity(Entity1_16Types.ZOGLIN, Entity1_16Types.COW).jsonName("Zoglin");
|
||||
mapEntity(Entity1_16Types.PIGLIN, Entity1_16Types.ZOMBIFIED_PIGLIN).jsonName("Piglin");
|
||||
mapEntity(Entity1_16Types.STRIDER, Entity1_16Types.MAGMA_CUBE).jsonName("Strider");
|
||||
mapEntityTypeWithData(Entity1_16Types.HOGLIN, Entity1_16Types.COW).jsonName("Hoglin");
|
||||
mapEntityTypeWithData(Entity1_16Types.ZOGLIN, Entity1_16Types.COW).jsonName("Zoglin");
|
||||
mapEntityTypeWithData(Entity1_16Types.PIGLIN, Entity1_16Types.ZOMBIFIED_PIGLIN).jsonName("Piglin");
|
||||
mapEntityTypeWithData(Entity1_16Types.STRIDER, Entity1_16Types.MAGMA_CUBE).jsonName("Strider");
|
||||
|
||||
registerMetaHandler().filter(Entity1_16Types.ZOGLIN, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.HOGLIN, 15).removed();
|
||||
filter().type(Entity1_16Types.ZOGLIN).cancel(16);
|
||||
filter().type(Entity1_16Types.HOGLIN).cancel(15);
|
||||
|
||||
registerMetaHandler().filter(Entity1_16Types.PIGLIN, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.PIGLIN, 17).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.PIGLIN, 18).removed();
|
||||
filter().type(Entity1_16Types.PIGLIN).cancel(16);
|
||||
filter().type(Entity1_16Types.PIGLIN).cancel(17);
|
||||
filter().type(Entity1_16Types.PIGLIN).cancel(18);
|
||||
|
||||
registerMetaHandler().filter(Entity1_16Types.STRIDER, 15).handle(meta -> {
|
||||
boolean baby = meta.getData().getCastedValue();
|
||||
meta.getData().setValue(baby ? 1 : 3);
|
||||
meta.getData().setMetaType(MetaType1_14.VarInt);
|
||||
return meta.getData();
|
||||
filter().type(Entity1_16Types.STRIDER).index(15).handler((event, meta) -> {
|
||||
boolean baby = meta.value();
|
||||
meta.setValue(baby ? 1 : 3);
|
||||
meta.setMetaType(MetaType1_14.VarInt);
|
||||
});
|
||||
registerMetaHandler().filter(Entity1_16Types.STRIDER, 16).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.STRIDER, 17).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.STRIDER, 18).removed();
|
||||
filter().type(Entity1_16Types.STRIDER).cancel(16);
|
||||
filter().type(Entity1_16Types.STRIDER).cancel(17);
|
||||
filter().type(Entity1_16Types.STRIDER).cancel(18);
|
||||
|
||||
registerMetaHandler().filter(Entity1_16Types.FISHING_BOBBER, 8).removed();
|
||||
filter().type(Entity1_16Types.FISHING_BOBBER).cancel(8);
|
||||
|
||||
registerMetaHandler().filter(Entity1_16Types.ABSTRACT_ARROW, true, 8).removed();
|
||||
registerMetaHandler().filter(Entity1_16Types.ABSTRACT_ARROW, true).handle(meta -> {
|
||||
if (meta.getIndex() >= 8) {
|
||||
meta.getData().setId(meta.getIndex() + 1);
|
||||
filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).cancel(8);
|
||||
filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).handler((event, meta) -> {
|
||||
if (event.index() >= 8) {
|
||||
event.setIndex(event.index() + 1); // TODO is this right...?
|
||||
}
|
||||
return meta.getData();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_16Types.getTypeFromId(typeId);
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,12 @@ import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandR
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||
@ -127,14 +129,14 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
}
|
||||
});
|
||||
|
||||
new TagRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.TAGS, RegistryType.ENTITY);
|
||||
new TagRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_16_2.TAGS, RegistryType.ENTITY);
|
||||
|
||||
new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_16_2.STATISTICS);
|
||||
new StatisticsRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_16_2.STATISTICS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16_2Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_16_2 getBlockItemPackets() {
|
||||
|
@ -23,15 +23,10 @@ import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
@ -49,12 +44,12 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerSpawnTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
|
||||
registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
|
||||
registerSpawnTracker(ClientboundPackets1_16_2.SPAWN_MOB);
|
||||
registerExtraTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
|
||||
registerExtraTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
|
||||
registerEntityDestroy(ClientboundPackets1_16_2.DESTROY_ENTITIES);
|
||||
registerTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
|
||||
registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
|
||||
registerRemoveEntities(ClientboundPackets1_16_2.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_14.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() {
|
||||
@ -109,39 +104,17 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
MetaType type = meta.getMetaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
|
||||
} else if (type == MetaType1_14.OptChat) {
|
||||
JsonElement text = meta.getCastedValue();
|
||||
if (text != null) {
|
||||
protocol.getTranslatableRewriter().processText(text);
|
||||
}
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
rewriteParticle((Particle) meta.getValue());
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
registerMetaTypeHandler(MetaType1_14.Slot, MetaType1_14.BlockID, MetaType1_14.PARTICLE, MetaType1_14.OptChat);
|
||||
|
||||
mapTypes(Entity1_16_2Types.values(), Entity1_16Types.class);
|
||||
mapEntity(Entity1_16_2Types.PIGLIN_BRUTE, Entity1_16_2Types.PIGLIN).jsonName("Piglin Brute");
|
||||
mapEntityTypeWithData(Entity1_16_2Types.PIGLIN_BRUTE, Entity1_16_2Types.PIGLIN).jsonName("Piglin Brute");
|
||||
|
||||
registerMetaHandler().filter(Entity1_16_2Types.ABSTRACT_PIGLIN, true).handle(meta -> {
|
||||
if (meta.getIndex() == 15) {
|
||||
meta.getData().setId(16);
|
||||
} else if (meta.getIndex() == 16) {
|
||||
meta.getData().setId(15);
|
||||
}
|
||||
return meta.getData();
|
||||
});
|
||||
filter().filterFamily(Entity1_16_2Types.ABSTRACT_PIGLIN).index(15).toIndex(16);
|
||||
filter().filterFamily(Entity1_16_2Types.ABSTRACT_PIGLIN).index(16).toIndex(15);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_16_2Types.getTypeFromId(typeId);
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,11 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntList;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
@ -79,7 +81,7 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
soundRewriter.registerNamedSound(ClientboundPackets1_17.NAMED_SOUND);
|
||||
soundRewriter.registerStopSound(ClientboundPackets1_17.STOP_SOUND);
|
||||
|
||||
TagRewriter tagRewriter = new TagRewriter(this, entityPackets::getOldEntityId);
|
||||
TagRewriter tagRewriter = new TagRewriter(this, entityPackets::newEntityId);
|
||||
registerClientbound(ClientboundPackets1_17.TAGS, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -137,7 +139,7 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
});
|
||||
|
||||
new StatisticsRewriter(this, entityPackets::getOldEntityId).register(ClientboundPackets1_17.STATISTICS);
|
||||
new StatisticsRewriter(this, entityPackets::newEntityId).register(ClientboundPackets1_17.STATISTICS);
|
||||
|
||||
registerClientbound(ClientboundPackets1_17.RESOURCE_PACK, new PacketRemapper() {
|
||||
@Override
|
||||
@ -225,9 +227,10 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_17Types.PLAYER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_17 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data.MapColorRewrites;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
@ -143,8 +143,8 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.VAR_INT); // Z
|
||||
map(Type.BOOLEAN); // Trust edges
|
||||
handler(wrapper -> {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
int startFromSection = Math.max(0, -(tracker.getCurrentMinY() >> 4));
|
||||
EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_16_4To1_17.class);
|
||||
int startFromSection = Math.max(0, -(tracker.currentMinY() >> 4));
|
||||
|
||||
long[] skyLightMask = wrapper.read(Type.LONG_ARRAY_PRIMITIVE);
|
||||
long[] blockLightMask = wrapper.read(Type.LONG_ARRAY_PRIMITIVE);
|
||||
@ -158,8 +158,8 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
wrapper.write(Type.VAR_INT, cutLightMask(emptySkyLightMask, startFromSection));
|
||||
wrapper.write(Type.VAR_INT, cutLightMask(emptyBlockLightMask, startFromSection));
|
||||
|
||||
writeLightArrays(wrapper, BitSet.valueOf(skyLightMask), cutSkyLightMask, startFromSection, tracker.getCurrentWorldSectionHeight());
|
||||
writeLightArrays(wrapper, BitSet.valueOf(blockLightMask), cutBlockLightMask, startFromSection, tracker.getCurrentWorldSectionHeight());
|
||||
writeLightArrays(wrapper, BitSet.valueOf(skyLightMask), cutSkyLightMask, startFromSection, tracker.currentWorldSectionHeight());
|
||||
writeLightArrays(wrapper, BitSet.valueOf(blockLightMask), cutBlockLightMask, startFromSection, tracker.currentWorldSectionHeight());
|
||||
});
|
||||
}
|
||||
|
||||
@ -242,14 +242,14 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
int currentWorldSectionHeight = tracker.getCurrentWorldSectionHeight();
|
||||
EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_16_4To1_17.class);
|
||||
int currentWorldSectionHeight = tracker.currentWorldSectionHeight();
|
||||
|
||||
Chunk chunk = wrapper.read(new Chunk1_17Type(currentWorldSectionHeight));
|
||||
wrapper.write(new Chunk1_16_2Type(), chunk);
|
||||
|
||||
// Cut sections
|
||||
int startFromSection = Math.max(0, -(tracker.getCurrentMinY() >> 4));
|
||||
int startFromSection = Math.max(0, -(tracker.currentMinY() >> 4));
|
||||
chunk.setBiomeData(Arrays.copyOfRange(chunk.getBiomeData(), startFromSection * 64, (startFromSection * 64) + 1024));
|
||||
|
||||
chunk.setBitmask(cutMask(chunk.getChunkMask(), startFromSection, false));
|
||||
|
@ -23,16 +23,13 @@ import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4T
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_17;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
@ -49,11 +46,11 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerSpawnTrackerWithData(ClientboundPackets1_17.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
|
||||
registerTrackerWithData(ClientboundPackets1_17.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
|
||||
registerSpawnTracker(ClientboundPackets1_17.SPAWN_MOB);
|
||||
registerExtraTracker(ClientboundPackets1_17.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
|
||||
registerExtraTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
|
||||
registerTracker(ClientboundPackets1_17.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
|
||||
registerTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
|
||||
registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_14.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_16_2.DESTROY_ENTITIES, new PacketRemapper() {
|
||||
@ -61,7 +58,7 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.read(Type.VAR_INT);
|
||||
getEntityTracker(wrapper.user()).removeEntity(entityId);
|
||||
tracker(wrapper.user()).removeEntity(entityId);
|
||||
|
||||
// Write into single value array
|
||||
int[] array = {entityId};
|
||||
@ -87,7 +84,7 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_16_2Types.PLAYER, Type.INT));
|
||||
handler(getWorldDataTracker(1));
|
||||
handler(worldDataTrackerHandler(1));
|
||||
handler(wrapper -> {
|
||||
CompoundTag registry = wrapper.get(Type.NBT, 0);
|
||||
CompoundTag biomeRegsitry = registry.get("minecraft:worldgen/biome");
|
||||
@ -116,10 +113,8 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.NBT); // Dimension data
|
||||
handler(getWorldDataTracker(0));
|
||||
handler(wrapper -> {
|
||||
reduceExtendedHeight(wrapper.get(Type.NBT, 0), true);
|
||||
});
|
||||
handler(worldDataTrackerHandler(0));
|
||||
handler(wrapper -> reduceExtendedHeight(wrapper.get(Type.NBT, 0), true));
|
||||
}
|
||||
});
|
||||
|
||||
@ -157,21 +152,11 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
meta.setMetaType(MetaType1_14.byId(meta.getMetaType().getTypeID()));
|
||||
filter().handler((event, meta) -> {
|
||||
meta.setMetaType(MetaType1_14.byId(meta.metaType().typeId()));
|
||||
|
||||
MetaType type = meta.getMetaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
|
||||
} else if (type == MetaType1_14.OptChat) {
|
||||
JsonElement text = meta.getCastedValue();
|
||||
if (text != null) {
|
||||
protocol.getTranslatableRewriter().processText(text);
|
||||
}
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
MetaType type = meta.metaType();
|
||||
if (type == MetaType1_14.PARTICLE) {
|
||||
Particle particle = (Particle) meta.getValue();
|
||||
if (particle.getId() == 15) { // Dust / Dust Transition
|
||||
// Remove transition target color values 4-6
|
||||
@ -180,55 +165,46 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
|
||||
// No nice mapping possible without tracking entity positions and doing particle tasks
|
||||
particle.setId(0);
|
||||
particle.getArguments().clear();
|
||||
return meta;
|
||||
return;
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
} else if (type == MetaType1_14.Pose) {
|
||||
// Goat LONG_JUMP added at 6
|
||||
int pose = meta.getCastedValue();
|
||||
int pose = meta.value();
|
||||
if (pose == 6) {
|
||||
meta.setValue(1); // FALL_FLYING
|
||||
} else if (pose > 6) {
|
||||
meta.setValue(pose - 1);
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
});
|
||||
|
||||
// Particles have already been handled
|
||||
registerMetaTypeHandler(MetaType1_14.Slot, MetaType1_14.BlockID, null, MetaType1_14.OptChat);
|
||||
|
||||
mapTypes(Entity1_17Types.values(), Entity1_16_2Types.class);
|
||||
registerMetaHandler().filter(Entity1_17Types.AXOLOTL, 17).removed();
|
||||
registerMetaHandler().filter(Entity1_17Types.AXOLOTL, 18).removed();
|
||||
registerMetaHandler().filter(Entity1_17Types.AXOLOTL, 19).removed();
|
||||
filter().type(Entity1_17Types.AXOLOTL).cancel(17);
|
||||
filter().type(Entity1_17Types.AXOLOTL).cancel(18);
|
||||
filter().type(Entity1_17Types.AXOLOTL).cancel(19);
|
||||
|
||||
registerMetaHandler().filter(Entity1_17Types.GLOW_SQUID, 16).removed();
|
||||
filter().type(Entity1_17Types.GLOW_SQUID).cancel(16);
|
||||
|
||||
registerMetaHandler().filter(Entity1_17Types.GOAT, 17).removed();
|
||||
filter().type(Entity1_17Types.GOAT).cancel(17);
|
||||
|
||||
mapEntity(Entity1_17Types.AXOLOTL, Entity1_17Types.TROPICAL_FISH).jsonName("Axolotl");
|
||||
mapEntity(Entity1_17Types.GOAT, Entity1_17Types.SHEEP).jsonName("Goat");
|
||||
mapEntityTypeWithData(Entity1_17Types.AXOLOTL, Entity1_17Types.TROPICAL_FISH).jsonName("Axolotl");
|
||||
mapEntityTypeWithData(Entity1_17Types.GOAT, Entity1_17Types.SHEEP).jsonName("Goat");
|
||||
|
||||
mapEntity(Entity1_17Types.GLOW_SQUID, Entity1_17Types.SQUID).jsonName("Glow Squid");
|
||||
mapEntity(Entity1_17Types.GLOW_ITEM_FRAME, Entity1_17Types.ITEM_FRAME);
|
||||
mapEntityTypeWithData(Entity1_17Types.GLOW_SQUID, Entity1_17Types.SQUID).jsonName("Glow Squid");
|
||||
mapEntityTypeWithData(Entity1_17Types.GLOW_ITEM_FRAME, Entity1_17Types.ITEM_FRAME);
|
||||
|
||||
registerMetaHandler().filter(Entity1_17Types.SHULKER).handle(meta -> {
|
||||
if (meta.getIndex() >= 17) {
|
||||
meta.getData().setId(meta.getIndex() + 1); // TODO Handle attachment pos?
|
||||
}
|
||||
return meta.getData();
|
||||
});
|
||||
filter().type(Entity1_17Types.SHULKER).addIndex(17); // TODO Handle attachment pos?
|
||||
|
||||
registerMetaHandler().filter(7).removed(); // Ticks frozen
|
||||
registerMetaHandler().handle(meta -> {
|
||||
if (meta.getIndex() > 7) {
|
||||
meta.getData().setId(meta.getIndex() - 1);
|
||||
}
|
||||
return meta.getData();
|
||||
});
|
||||
filter().removeIndex(7); // Ticks frozen
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_17Types.getTypeFromId(typeId);
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,12 @@ import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets.BlockItemPackets1_10;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets.EntityPackets1_10;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
@ -94,7 +96,7 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
|
||||
initEntityTracker(user);
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_10Types.EntityType.PLAYER));
|
||||
}
|
||||
|
||||
public EntityPackets1_10 getEntityPackets() {
|
||||
|
@ -23,7 +23,6 @@ import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -138,13 +137,9 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<Protocol1_9_4T
|
||||
});
|
||||
|
||||
// Rewrite metadata items
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item
|
||||
data.setValue(handleItemToClient((Item) data.getValue()));
|
||||
|
||||
return data;
|
||||
protocol.getEntityPackets().filter().handler((event, meta) -> {
|
||||
if (meta.metaType().type().equals(Type.ITEM)) // Is Item
|
||||
meta.setValue(handleItemToClient((Item) meta.getValue()));
|
||||
});
|
||||
|
||||
// Particle
|
||||
|
@ -19,8 +19,7 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.MetaStorage;
|
||||
import com.viaversion.viabackwards.api.exceptions.RemovedValueException;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
@ -37,6 +36,7 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10> {
|
||||
@ -74,7 +74,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
@ -85,8 +85,8 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_10Types.EntityType.EXPERIENCE_ORB);
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_10Types.EntityType.WEATHER);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_10Types.EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_10Types.EntityType.WEATHER);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
||||
@Override
|
||||
@ -113,35 +113,25 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
EntityType type = tracker(wrapper.user()).entityType(entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
storage
|
||||
);
|
||||
List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
EntityData entityData = entityDataForType(type);
|
||||
if (entityData != null) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.getReplacementId());
|
||||
WrappedMetadata storage = new WrappedMetadata(metadata);
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
|
||||
if (entityData.hasBaseMeta())
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
entityData.defaultMeta().createMeta(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_10Types.EntityType.PAINTING);
|
||||
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_10Types.EntityType.PAINTING);
|
||||
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_10Types.EntityType.PLAYER);
|
||||
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
|
||||
|
||||
@ -161,61 +151,43 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
}
|
||||
});
|
||||
|
||||
registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
mapEntity(Entity1_10Types.EntityType.POLAR_BEAR, Entity1_10Types.EntityType.SHEEP).mobName("Polar Bear");
|
||||
mapEntityTypeWithData(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)
|
||||
registerMetaHandler().filter(Entity1_10Types.EntityType.POLAR_BEAR, 13).handle((e -> {
|
||||
Metadata data = e.getData();
|
||||
boolean b = (boolean) data.getValue();
|
||||
filter().type(Entity1_10Types.EntityType.POLAR_BEAR).index(13).handler((event, meta) -> {
|
||||
boolean b = (boolean) meta.getValue();
|
||||
|
||||
data.setMetaType(MetaType1_9.Byte);
|
||||
data.setValue(b ? (byte) (14 & 0x0F) : (byte) (0));
|
||||
|
||||
return data;
|
||||
}));
|
||||
meta.setMetaType(MetaType1_9.Byte);
|
||||
meta.setValue(b ? (byte) (14 & 0x0F) : (byte) (0));
|
||||
});
|
||||
|
||||
|
||||
// Handle husk (index 13 -> Zombie Type)
|
||||
registerMetaHandler().filter(Entity1_10Types.EntityType.ZOMBIE, 13).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if ((int) data.getValue() == 6) // Is type Husk
|
||||
data.setValue(0);
|
||||
|
||||
return data;
|
||||
filter().type(Entity1_10Types.EntityType.ZOMBIE).index(13).handler((event, meta) -> {
|
||||
if ((int) meta.getValue() == 6) { // Is type Husk
|
||||
meta.setValue(0);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle Stray (index 12 -> Skeleton Type)
|
||||
registerMetaHandler().filter(Entity1_10Types.EntityType.SKELETON, 12).handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if ((int) data.getValue() == 2)
|
||||
data.setValue(0); // Change to default skeleton
|
||||
|
||||
return data;
|
||||
filter().type(Entity1_10Types.EntityType.SKELETON).index(12).handler((event, meta) -> {
|
||||
if ((int) meta.getValue() == 2) {
|
||||
meta.setValue(0); // Change to default skeleton
|
||||
}
|
||||
});
|
||||
|
||||
// Handle the missing NoGravity tag for every metadata
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getId() == 5)
|
||||
throw RemovedValueException.EX;
|
||||
else if (data.getId() >= 5)
|
||||
data.setId(data.getId() - 1);
|
||||
|
||||
return data;
|
||||
});
|
||||
filter().removeIndex(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return Entity1_10Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user