Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 00:22:53 +01:00
Cleanup entity tracking/rewrites and item rewrites (#155)
* Cleanup entity tracking and rewrites * Fix * Item rewriter cleanup
Dieser Commit ist enthalten in:
Ursprung
1d12eb0b95
Commit
8e032f6499
@ -40,6 +40,7 @@ public class EntityData {
|
||||
}
|
||||
|
||||
public interface MetaCreator {
|
||||
|
||||
void handle(MetaStorage storage);
|
||||
}
|
||||
}
|
||||
|
@ -41,15 +41,14 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
}
|
||||
|
||||
protected Item handleItemToClient(Item i) {
|
||||
if (i == null)
|
||||
return null;
|
||||
if (!replacementData.containsKey(i.getIdentifier()))
|
||||
return i;
|
||||
if (i == null) return null;
|
||||
|
||||
BlockItemSettings data = replacementData.get(i.getIdentifier());
|
||||
if (data == null) return i;
|
||||
|
||||
Item original = ItemUtil.copyItem(i);
|
||||
if (data.hasRepItem()) {
|
||||
i = ItemUtil.copyItem(data.getRepItem());
|
||||
ItemUtil.copyItem(i, data.getRepItem());
|
||||
|
||||
if (i.getTag() == null)
|
||||
i.setTag(new CompoundTag(""));
|
||||
@ -58,9 +57,11 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
i.getTag().put(createViaNBT(original));
|
||||
|
||||
// Keep original data
|
||||
if (original.getTag() != null)
|
||||
for (Tag ai : original.getTag())
|
||||
if (original.getTag() != null) {
|
||||
for (Tag ai : original.getTag()) {
|
||||
i.getTag().put(ai);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle colors
|
||||
if (i.getTag().contains("display")) {
|
||||
|
@ -33,6 +33,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -64,15 +65,11 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
}
|
||||
|
||||
protected Optional<EntityData> getEntityData(EntityType type) {
|
||||
if (!entityTypes.containsKey(type))
|
||||
return Optional.empty();
|
||||
return Optional.of(entityTypes.get(type));
|
||||
return Optional.ofNullable(entityTypes.get(type));
|
||||
}
|
||||
|
||||
protected Optional<EntityData> getObjectData(ObjectType type) {
|
||||
if (!objectTypes.containsKey(type))
|
||||
return Optional.empty();
|
||||
return Optional.of(objectTypes.get(type));
|
||||
return Optional.ofNullable(objectTypes.get(type));
|
||||
}
|
||||
|
||||
protected EntityData regEntType(EntityType oldEnt, EntityType replacement) {
|
||||
@ -256,6 +253,89 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
registerEntityDestroy(packetId, packetId);
|
||||
}
|
||||
|
||||
protected PacketHandler getObjectTrackerHandler() {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerHandler(Type intType, int typeIndex) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Number id = (Number) wrapper.get(intType, typeIndex);
|
||||
addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), getTypeFromId(id.intValue()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerHandler() {
|
||||
return getTrackerHandler(Type.VAR_INT, 1);
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(wrapper.user(), (int) wrapper.get(intType, 0), entityType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0));
|
||||
handleMeta(wrapper.user(), entityId, storage);
|
||||
|
||||
Optional<EntityData> optEntDat = getEntityData(type);
|
||||
if (optEntDat.isPresent()) {
|
||||
EntityData data = optEntDat.get();
|
||||
|
||||
int replacementId = getOldEntityId(data.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, replacementId);
|
||||
if (data.hasBaseMeta()) {
|
||||
data.getDefaultMeta().handle(storage);
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(metaType, 0, storage.getMetaDataList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
List<Metadata> metaDataList = handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(metaType, 0))).getMetaDataList();
|
||||
wrapper.set(metaType, 0, metaDataList);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getDimensionHandler(int index) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, index);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected EntityTracker.ProtocolEntityTracker getEntityTracker(UserConnection user) {
|
||||
return user.get(EntityTracker.class).get(getProtocol());
|
||||
}
|
||||
@ -283,4 +363,19 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
protected void setDisplayNameJson(boolean displayNameJson) {
|
||||
isDisplayNameJson = displayNameJson;
|
||||
}
|
||||
|
||||
protected abstract EntityType getTypeFromId(int typeId);
|
||||
|
||||
protected EntityType getObjectTypeFromId(int typeId) {
|
||||
return getTypeFromId(typeId);
|
||||
}
|
||||
|
||||
// Only needs to be overriden when getMobSpawnTracker is used
|
||||
protected Optional<Integer> getOptOldEntityId(int newId) {
|
||||
return Optional.of(newId);
|
||||
}
|
||||
|
||||
protected int getOldEntityId(int newId) {
|
||||
return newId;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
@ -41,7 +42,7 @@ import java.util.Optional;
|
||||
public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11> {
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_10To1_11 protocol) {
|
||||
/* Item packets */
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
|
||||
@ -51,13 +52,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Slot Value
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
|
||||
// Handle Llama
|
||||
handler(new PacketHandler() {
|
||||
@ -110,22 +105,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
|
||||
});
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3C);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@ -169,13 +149,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
handler(itemRewriter.itemToServerHandler(Type.ITEM));
|
||||
|
||||
// Llama slot
|
||||
handler(new PacketHandler() {
|
||||
@ -198,25 +172,9 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
|
||||
);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18);
|
||||
|
||||
/* Block packets */
|
||||
|
||||
// Chunk packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -30,7 +30,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -53,16 +52,7 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
map(Type.INT); // 8 - data
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.getTypeFromId(wrapper.get(Type.BYTE, 0), true)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -131,16 +121,7 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
map(Types1_9.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
// Track entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.getTypeFromId(wrapper.get(Type.UNSIGNED_BYTE, 0), false)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
|
||||
|
||||
// Rewrite entity type / metadata
|
||||
handler(new PacketHandler() {
|
||||
@ -186,25 +167,8 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_11Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_11Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
}
|
||||
});
|
||||
|
||||
@ -213,14 +177,7 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -237,33 +194,7 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_9.METADATA_LIST); // 7 - Metadata list
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@ -290,7 +221,6 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
wrapper.setId(0x1E); // Change Game State
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 10); // Play Elder Guardian animation
|
||||
wrapper.write(Type.FLOAT, 0F);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -508,4 +438,13 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
||||
return new Metadata(14, MetaType1_9.VarInt, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.DoubleTag;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -35,7 +35,6 @@ import java.util.Collections;
|
||||
public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12> {
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_11_1To1_12 protocol) {
|
||||
/* Item packets */
|
||||
|
||||
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
|
||||
@Override
|
||||
@ -74,59 +73,16 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Slot Value
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Set slot packet
|
||||
itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16);
|
||||
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x14, 0x14, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.ITEM_ARRAY); // 1 - Window Values
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
|
||||
for (int i = 0; i < stacks.length; i++)
|
||||
stacks[i] = handleItemToClient(stacks[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14);
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3E, 0x3C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3E, 0x3C);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@ -200,22 +156,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x1B, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x1B, 0x18);
|
||||
|
||||
/* Block packets */
|
||||
|
||||
@ -235,8 +176,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Block Change Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
|
||||
@ -253,8 +193,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Multi Block Change Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() {
|
||||
@ -273,8 +212,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Update Block Entity
|
||||
protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() {
|
||||
|
@ -25,33 +25,17 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
||||
p.registerOutgoing(State.PLAY, 0x26, 0x25); // Entity Relative Move
|
||||
p.registerOutgoing(State.PLAY, 0x27, 0x26); // Entity Look and Relative Move
|
||||
p.registerOutgoing(State.PLAY, 0x28, 0x27); // Entity Look
|
||||
p.registerOutgoing(State.PLAY, 0x30, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}); // Unlock Recipes TODO does ViaVersion cancel the packet if the new id is -1?
|
||||
|
||||
p.cancelOutgoing(State.PLAY, 0x30); // Unlock Recipes
|
||||
|
||||
// 0x31 -> 0x30 Destroy Entities handled in EntityPackets1_12.java
|
||||
p.registerOutgoing(State.PLAY, 0x32, 0x31); // Remove Entity Effect
|
||||
p.registerOutgoing(State.PLAY, 0x33, 0x32); // Resource Pack Send
|
||||
// 0x34 -> 0x33 Respawn handled in EntityPackets1_12.java
|
||||
p.registerOutgoing(State.PLAY, 0x35, 0x34); // Entity Head Look
|
||||
p.registerOutgoing(State.PLAY, 0x36, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}); // Advancement Progress
|
||||
|
||||
p.cancelOutgoing(State.PLAY, 0x36); // Advancement Progress
|
||||
|
||||
p.registerOutgoing(State.PLAY, 0x37, 0x35); // World Border
|
||||
p.registerOutgoing(State.PLAY, 0x38, 0x36); //Camera
|
||||
p.registerOutgoing(State.PLAY, 0x39, 0x37); // Held Item Change (ClientBound)
|
||||
@ -73,17 +57,9 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
||||
p.registerOutgoing(State.PLAY, 0x49, 0x47); // Player List Header And Footer
|
||||
p.registerOutgoing(State.PLAY, 0x4A, 0x48); // Collect Item
|
||||
p.registerOutgoing(State.PLAY, 0x4B, 0x49); // Entity Teleport
|
||||
p.registerOutgoing(State.PLAY, 0x4C, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}); // Advancements
|
||||
|
||||
p.cancelOutgoing(State.PLAY, 0x4C); // Advancements
|
||||
|
||||
p.registerOutgoing(State.PLAY, 0x4D, 0x4A); // Entity Properties
|
||||
p.registerOutgoing(State.PLAY, 0x4E, 0x4B); // Entity Effect
|
||||
|
||||
|
@ -12,7 +12,6 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
@ -30,12 +29,12 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_12;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_11_1To1_12 protocol) {
|
||||
// Spawn Object
|
||||
@ -53,16 +52,7 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
map(Type.INT); // 8 - data
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_12Types.getTypeFromId(wrapper.get(Type.BYTE, 0), true)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -131,48 +121,10 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
map(Types1_12.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
// Track entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_12Types.getTypeFromId(wrapper.get(Type.VAR_INT, 1), false)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(getTrackerHandler());
|
||||
|
||||
// Rewrite entity type / metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
storage
|
||||
);
|
||||
|
||||
Optional<EntityData> optEntDat = getEntityData(type);
|
||||
if (optEntDat.isPresent()) {
|
||||
EntityData data = optEntDat.get();
|
||||
wrapper.set(Type.VAR_INT, 1, data.getReplacementId());
|
||||
if (data.hasBaseMeta())
|
||||
data.getDefaultMeta().handle(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_12.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -192,33 +144,7 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_12.METADATA_LIST); // 7 - Metadata list
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_12Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_12.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, Entity1_12Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@ -230,16 +156,9 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_12Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_12Types.EntityType.PLAYER, Type.INT));
|
||||
|
||||
handler(getDimensionHandler(1));
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -249,15 +168,6 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
}
|
||||
});
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
|
||||
// Send fake inventory achievement
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -279,14 +189,7 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -390,4 +293,14 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
throw RemovedValueException.EX;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_12Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(final int typeId) {
|
||||
return Entity1_12Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ package nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
@ -24,7 +23,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -47,16 +45,7 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
map(Type.INT); // 8 - data
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.getTypeFromId(wrapper.get(Type.BYTE, 0), true)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -106,48 +95,10 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
map(Types1_9.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
// Track entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.getTypeFromId(wrapper.get(Type.VAR_INT, 1), false)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(getTrackerHandler());
|
||||
|
||||
// Rewrite entity type / metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
storage
|
||||
);
|
||||
|
||||
Optional<EntityData> optEntDat = getEntityData(type);
|
||||
if (optEntDat.isPresent()) {
|
||||
EntityData data = optEntDat.get();
|
||||
wrapper.set(Type.VAR_INT, 1, data.getReplacementId());
|
||||
if (data.hasBaseMeta())
|
||||
data.getDefaultMeta().handle(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -162,25 +113,8 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_11Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_11Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
}
|
||||
});
|
||||
|
||||
@ -189,14 +123,7 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -213,33 +140,7 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_9.METADATA_LIST); // 7 - Metadata list
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_11Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@ -258,4 +159,14 @@ public class EntityPackets1_11_1 extends EntityRewriter<Protocol1_11To1_11_1> {
|
||||
// Handle non-existing pig metadata (index 14 - boost time)
|
||||
registerMetaHandler().filter(Entity1_11Types.EntityType.PIG, 14).removed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(final int typeId) {
|
||||
return Entity1_11Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
@ -24,59 +25,16 @@ public class ItemPackets1_11_1 extends BlockItemRewriter<Protocol1_11To1_11_1> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_11To1_11_1 protocol) {
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Slot Value
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Set slot packet
|
||||
itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16);
|
||||
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x14, 0x14, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.ITEM_ARRAY); // 1 - Window Values
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
|
||||
for (int i = 0; i < stacks.length; i++)
|
||||
stacks[i] = handleItemToClient(stacks[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14);
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3C);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@ -110,44 +68,10 @@ public class ItemPackets1_11_1 extends BlockItemRewriter<Protocol1_11To1_11_1> {
|
||||
});
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x07, 0x07, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot
|
||||
map(Type.BYTE); // 2 - Button
|
||||
map(Type.SHORT); // 3 - Action number
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerClickWindow(Type.ITEM, 0x07, 0x07);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18);
|
||||
|
||||
// Handle item metadata
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
|
@ -8,20 +8,20 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityTypeMapping {
|
||||
private static Map<Integer, Integer> entityTypes = new HashMap<>();
|
||||
private static final Map<Integer, Integer> TYPES = new HashMap<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
|
||||
field.setAccessible(true);
|
||||
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null);
|
||||
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
|
||||
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.TYPES.put(type1_13, type1_12));
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<Integer> getOldId(int type1_13) {
|
||||
return Optional.ofNullable(entityTypes.get(type1_13));
|
||||
return Optional.ofNullable(TYPES.get(type1_13));
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
@ -205,21 +206,16 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
}
|
||||
});
|
||||
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
// Windows Items
|
||||
protocol.out(State.PLAY, 0x15, 0x14, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
map(Type.FLAT_ITEM_ARRAY, Type.ITEM_ARRAY);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] items = wrapper.get(Type.ITEM_ARRAY, 0);
|
||||
for (int i = 0; i < items.length; i++)
|
||||
items[i] = handleItemToClient(items[i]);
|
||||
wrapper.set(Type.ITEM_ARRAY, 0, items);
|
||||
}
|
||||
});
|
||||
|
||||
handler(itemRewriter.itemArrayHandler(Type.ITEM_ARRAY));
|
||||
}
|
||||
});
|
||||
|
||||
@ -230,14 +226,8 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
map(Type.BYTE);
|
||||
map(Type.SHORT);
|
||||
map(Type.FLAT_ITEM, Type.ITEM);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
item = handleItemToClient(item);
|
||||
wrapper.set(Type.ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -425,14 +415,8 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
map(Type.VAR_INT);
|
||||
map(Type.VAR_INT);
|
||||
map(Type.FLAT_ITEM, Type.ITEM);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
item = handleItemToClient(item);
|
||||
wrapper.set(Type.ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -443,14 +427,8 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
public void registerMap() {
|
||||
map(Type.SHORT);
|
||||
map(Type.ITEM, Type.FLAT_ITEM);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
item = handleItemToServer(item);
|
||||
wrapper.set(Type.FLAT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
|
||||
handler(itemRewriter.itemToServerHandler(Type.FLAT_ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -464,14 +442,8 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
map(Type.SHORT);
|
||||
map(Type.VAR_INT);
|
||||
map(Type.ITEM, Type.FLAT_ITEM);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
item = handleItemToServer(item);
|
||||
wrapper.set(Type.FLAT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
|
||||
handler(itemRewriter.itemToServerHandler(Type.FLAT_ITEM));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -712,11 +684,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
||||
if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) {
|
||||
StringTag name = display.get("Name");
|
||||
StringTag via = display.get(NBT_TAG_NAME + "|Name");
|
||||
name.setValue(
|
||||
via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(
|
||||
name.getValue()
|
||||
)
|
||||
);
|
||||
name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue()));
|
||||
display.remove(NBT_TAG_NAME + "|Name");
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
@ -10,7 +8,6 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMappin
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
@ -24,7 +21,6 @@ import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -46,22 +42,9 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
map(Type.BYTE);
|
||||
map(Type.BYTE);
|
||||
map(Type.INT);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
byte type = wrapper.get(Type.BYTE, 0);
|
||||
EntityType entityType = Entity1_13Types.getTypeFromId(type, true);
|
||||
if (entityType == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
|
||||
return;
|
||||
}
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
entityType
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
@ -125,11 +108,8 @@ public class EntityPackets1_13 extends EntityRewriter<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.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
entityType
|
||||
);
|
||||
addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
Optional<Integer> oldId = EntityTypeMapping.getOldId(type);
|
||||
if (!oldId.isPresent()) {
|
||||
if (!hasData(entityType))
|
||||
@ -140,38 +120,8 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
}
|
||||
});
|
||||
|
||||
// Handle entity type & metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
storage
|
||||
);
|
||||
|
||||
Optional<EntityData> optEntDat = getEntityData(type);
|
||||
if (optEntDat.isPresent()) {
|
||||
EntityData data = optEntDat.get();
|
||||
|
||||
Optional<Integer> replacementId = EntityTypeMapping.getOldId(data.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, replacementId.orElse(Entity1_12Types.EntityType.ZOMBIE.getId()));
|
||||
if (data.hasBaseMeta())
|
||||
data.getDefaultMeta().handle(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_12.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
// Rewrite entity type / metadata
|
||||
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -188,52 +138,18 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
map(Type.BYTE);
|
||||
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_13Types.EntityType.PLAYER
|
||||
);
|
||||
handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_12.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Spawn Painting
|
||||
// Spawn Painting
|
||||
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.UUID);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_13Types.EntityType.PAINTING
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(getTrackerHandler(Entity1_13Types.EntityType.PAINTING, Type.VAR_INT));
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
@ -253,45 +169,18 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_12Types.EntityType.PLAYER
|
||||
);
|
||||
handler(getTrackerHandler(Entity1_13Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
}
|
||||
});
|
||||
|
||||
// Save dimension
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Respawn Packet (save dimension id)
|
||||
protocol.registerOutgoing(State.PLAY, 0x38, 0x35, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -427,4 +316,19 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
|
||||
// TODO REWRITE BLOCKS IN MINECART
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(final int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getOldEntityId(final int newId) {
|
||||
return EntityTypeMapping.getOldId(newId).orElse(newId);
|
||||
}
|
||||
}
|
||||
|
@ -20,17 +20,7 @@ import us.myles.ViaVersion.packets.State;
|
||||
public class Protocol1_12To1_12_1 extends BackwardsProtocol {
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerOutgoing(State.PLAY, 0x2b, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}); // TODO
|
||||
cancelOutgoing(State.PLAY, 0x2B); //TODO
|
||||
registerOutgoing(State.PLAY, 0x2c, 0x2b);
|
||||
registerOutgoing(State.PLAY, 0x2d, 0x2c);
|
||||
registerOutgoing(State.PLAY, 0x2e, 0x2d);
|
||||
@ -68,17 +58,7 @@ public class Protocol1_12To1_12_1 extends BackwardsProtocol {
|
||||
registerOutgoing(State.PLAY, 0x4e, 0x4d);
|
||||
registerOutgoing(State.PLAY, 0x4f, 0x4e);
|
||||
|
||||
registerIncoming(State.PLAY, -1, 0x1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}); // TODO
|
||||
cancelIncoming(State.PLAY, 0x01); //TODO
|
||||
registerIncoming(State.PLAY, 0x1, 0x2);
|
||||
registerIncoming(State.PLAY, 0x2, 0x3);
|
||||
registerIncoming(State.PLAY, 0x3, 0x4);
|
||||
|
@ -93,30 +93,11 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol {
|
||||
registerOutgoing(State.PLAY, 0x55, 0x4F); // c
|
||||
registerOutgoing(State.PLAY, 0x56, 0x50); // c
|
||||
|
||||
//Update View Position
|
||||
registerOutgoing(State.PLAY, 0x40, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
packetWrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//Update View Distance
|
||||
registerOutgoing(State.PLAY, 0x41, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
packetWrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Update View Position
|
||||
cancelOutgoing(State.PLAY, 0x40);
|
||||
|
||||
// Update View Distance
|
||||
cancelOutgoing(State.PLAY, 0x41);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x57, 0x51, new PacketRemapper() { // c
|
||||
@Override
|
||||
|
@ -20,6 +20,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
@ -139,44 +140,13 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
});
|
||||
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x14, 0x15, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0);
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
stacks[i] = handleItemToClient(stacks[i]);
|
||||
}
|
||||
wrapper.set(Type.FLAT_VAR_INT_ITEM_ARRAY, 0, stacks);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Window items packet
|
||||
itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x14, 0x15);
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x17, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
|
||||
item = handleItemToClient(item);
|
||||
wrapper.set(Type.FLAT_VAR_INT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x16, 0x17);
|
||||
|
||||
// Trade list
|
||||
protocol.out(State.PLAY, 0x27, 0x19, new PacketRemapper() {
|
||||
@ -249,13 +219,7 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = handleItemToClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
wrapper.set(Type.FLAT_VAR_INT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
handler(itemRewriter.itemToClientHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -374,43 +338,10 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
|
||||
*/
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x09, 0x08, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot
|
||||
map(Type.BYTE); // 2 - Button
|
||||
map(Type.SHORT); // 3 - Action number
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = handleItemToServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
wrapper.set(Type.FLAT_VAR_INT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x08);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x26, 0x24, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
|
||||
item = handleItemToServer(item);
|
||||
wrapper.set(Type.FLAT_VAR_INT_ITEM, 0, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x24);
|
||||
|
||||
// Block break animation
|
||||
protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() {
|
||||
@ -643,24 +574,6 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
|
||||
}
|
||||
});
|
||||
|
||||
//respawn
|
||||
protocol.registerOutgoing(State.PLAY, 0x3A, 0x38, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0); // todo - do we need to store it from difficulty packet?
|
||||
wrapper.user().get(ChunkLightStorage.class).clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn position
|
||||
protocol.registerOutgoing(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -3,12 +3,12 @@ package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.meta.MetaHandler;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.EntityTypeMapping;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
@ -22,7 +22,6 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
@ -32,6 +31,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_13_2To1_14 protocol) {
|
||||
// Spawn Object
|
||||
@ -48,22 +48,8 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
map(Type.BYTE); // 7 - Yaw
|
||||
map(Type.INT); // 8 - Data
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
byte type = wrapper.get(Type.BYTE, 0);
|
||||
Entity1_14Types.EntityType entityType = Entity1_14Types.getTypeFromId(type);
|
||||
if (entityType == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.14 entity type " + type);
|
||||
return;
|
||||
}
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
entityType
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
@ -171,37 +157,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
});
|
||||
|
||||
// Handle entity type & metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityType type = getEntityType(wrapper.user(), entityId);
|
||||
|
||||
MetaStorage storage = new MetaStorage(wrapper.get(Types1_13_2.METADATA_LIST, 0));
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
entityId,
|
||||
storage
|
||||
);
|
||||
|
||||
Optional<EntityData> optEntDat = getEntityData(type);
|
||||
if (optEntDat.isPresent()) {
|
||||
EntityData data = optEntDat.get();
|
||||
|
||||
Optional<Integer> replacementId = EntityTypeMapping.getOldId(data.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, replacementId.orElse(Entity1_13Types.EntityType.ZOMBIE.getId()));
|
||||
if (data.hasBaseMeta())
|
||||
data.getDefaultMeta().handle(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
wrapper.set(
|
||||
Types1_13_2.METADATA_LIST,
|
||||
0,
|
||||
storage.getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getMobSpawnRewriter(Types1_13_2.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -227,23 +183,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
addTrackedEntity(wrapper.user(), entityId, entType);
|
||||
wrapper.set(Types1_13_2.METADATA_LIST, 0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
entityId,
|
||||
new MetaStorage(wrapper.get(Types1_13_2.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerAndMetaHandler(Types1_13_2.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@ -251,9 +191,9 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
registerEntityDestroy(0x37, 0x35);
|
||||
|
||||
// Entity Metadata packet
|
||||
registerMetadataRewriter(0x43, 0x3F, Types1_14.METADATA_LIST, Types1_13.METADATA_LIST);
|
||||
registerMetadataRewriter(0x43, 0x3F, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
|
||||
|
||||
//join game
|
||||
// Join game
|
||||
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -261,24 +201,36 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(getTrackerHandler(Entity1_14Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Store the player
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
|
||||
// Register Type ID
|
||||
addTrackedEntity(wrapper.user(), entityId, Entity1_14Types.EntityType.PLAYER);
|
||||
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
|
||||
wrapper.passthrough(Type.STRING); // Level Type
|
||||
wrapper.read(Type.VAR_INT); //Read View Distance
|
||||
wrapper.read(Type.VAR_INT); // Read View Distance
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Respawn
|
||||
protocol.registerOutgoing(State.PLAY, 0x3A, 0x38, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0); // todo - do we need to store it from difficulty packet?
|
||||
wrapper.user().get(ChunkLightStorage.class).clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -521,4 +473,14 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_14Types.getTypeFromId(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getOldEntityId(final int newId) {
|
||||
return EntityTypeMapping.getOldId(newId).orElse(newId);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
||||
@ -15,7 +15,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
|
||||
@ -54,11 +53,7 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
}
|
||||
|
||||
// Track Entity
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
entityId,
|
||||
entType
|
||||
);
|
||||
addTrackedEntity(wrapper.user(), entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -89,39 +84,19 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
map(Types1_13.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(type, false);
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
entityType
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler());
|
||||
|
||||
// Rewrite Metadata
|
||||
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
|
||||
);
|
||||
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()
|
||||
);
|
||||
wrapper.set(Types1_13.METADATA_LIST, 0, storage.getMetaDataList());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -140,37 +115,11 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_13.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_13Types.EntityType.PLAYER
|
||||
);
|
||||
handler(getTrackerAndMetaHandler(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_13.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Spawn Painting
|
||||
// Spawn Painting
|
||||
registerExtraTracker(0x04, Entity1_13Types.EntityType.PAINTING);
|
||||
|
||||
// Join Game
|
||||
@ -181,27 +130,8 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_12Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Save dimension
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_13Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
}
|
||||
});
|
||||
|
||||
@ -212,14 +142,7 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
map(Type.INT); // 0 - Dimension ID\
|
||||
|
||||
// Save dimension
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -232,7 +155,6 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
|
||||
// Rewrite items & blocks
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
@ -273,4 +195,14 @@ public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
|
||||
return meta;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(final int typeId) {
|
||||
return Entity1_13Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
}
|
||||
|
@ -5,54 +5,22 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
public class InventoryPackets1_13_1 {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
|
||||
/*
|
||||
Outgoing packets
|
||||
*/
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets1_13_1::toClient, InventoryPackets1_13_1::toServer);
|
||||
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.FLAT_ITEM_ARRAY); // 1 - Window Values
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.FLAT_ITEM_ARRAY, 0);
|
||||
for (Item stack : stacks)
|
||||
toClient(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerWindowItems(Type.FLAT_ITEM_ARRAY, 0x15, 0x15);
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.FLAT_ITEM); // 2 - Slot Value
|
||||
itemRewriter.registerSetSlot(Type.FLAT_ITEM, 0x17, 0x17);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
toClient(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Plugin Message
|
||||
// Plugin Message
|
||||
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -90,67 +58,14 @@ public class InventoryPackets1_13_1 {
|
||||
});
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.FLAT_ITEM); // 2 - Item
|
||||
itemRewriter.registerEntityEquipment(Type.FLAT_ITEM, 0x42, 0x42);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
toClient(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
Incoming packets
|
||||
*/
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot
|
||||
map(Type.BYTE); // 2 - Button
|
||||
map(Type.SHORT); // 3 - Action number
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.FLAT_ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
toServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerClickWindow(Type.FLAT_ITEM, 0x08, 0x08);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.FLAT_ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.FLAT_ITEM, 0);
|
||||
toServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerCreativeInvAction(Type.FLAT_ITEM, 0x24, 0x24);
|
||||
}
|
||||
|
||||
public static void toClient(Item item) {
|
||||
@ -158,7 +73,7 @@ public class InventoryPackets1_13_1 {
|
||||
item.setIdentifier(getOldItemId(item.getIdentifier()));
|
||||
}
|
||||
|
||||
//1.13.1 Item Id
|
||||
// 1.13.1 Item Id
|
||||
public static int getNewItemId(int itemId) {
|
||||
if (itemId >= 443) {
|
||||
return itemId + 5;
|
||||
@ -171,7 +86,7 @@ public class InventoryPackets1_13_1 {
|
||||
item.setIdentifier(getNewItemId(item.getIdentifier()));
|
||||
}
|
||||
|
||||
//1.13 Item Id
|
||||
// 1.13 Item Id
|
||||
public static int getOldItemId(int newId) {
|
||||
if (newId >= 448) {
|
||||
return newId - 5;
|
||||
|
@ -13,17 +13,7 @@ public class Protocol1_14_3To1_14_4 extends BackwardsProtocol {
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// Acknowledge Player Digging - added in pre4
|
||||
registerOutgoing(State.PLAY, 0x5c, -1, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelOutgoing(State.PLAY, 0x5C);
|
||||
|
||||
// Trade list
|
||||
registerOutgoing(State.PLAY, 0x27, 0x27, new PacketRemapper() {
|
||||
|
@ -2,14 +2,14 @@ package nl.matsv.viabackwards.protocol.protocol1_14to1_14_1;
|
||||
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.packets.EntityPackets;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.packets.EntityPackets1_14_1;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
|
||||
public class Protocol1_14To1_14_1 extends BackwardsProtocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
new EntityPackets().register(this);
|
||||
new EntityPackets1_14_1().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,13 +5,14 @@ import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
public class EntityPackets extends EntityRewriter<Protocol1_14To1_14_1> {
|
||||
public class EntityPackets1_14_1 extends EntityRewriter<Protocol1_14To1_14_1> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_14To1_14_1 protocol) {
|
||||
@ -30,13 +31,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_14To1_14_1> {
|
||||
map(Type.UUID); // 1 - UUID
|
||||
map(Type.VAR_INT); // 2 - Type
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), Entity1_14Types.getTypeFromId(type));
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler());
|
||||
}
|
||||
});
|
||||
|
||||
@ -75,21 +70,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_14To1_14_1> {
|
||||
});
|
||||
|
||||
// Entity Metadata
|
||||
protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Types1_14.METADATA_LIST); // 1 - Metadata list
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Types1_14.METADATA_LIST, 0,
|
||||
handleMeta(wrapper.user(), entityId, new MetaStorage(wrapper.get(Types1_14.METADATA_LIST, 0))).getMetaDataList());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerMetadataRewriter(0x43, 0x43, Types1_14.METADATA_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,4 +79,9 @@ public class EntityPackets extends EntityRewriter<Protocol1_14To1_14_1> {
|
||||
registerMetaHandler().filter(Entity1_14Types.EntityType.VILLAGER, 16).handleIndexChange(15);
|
||||
registerMetaHandler().filter(Entity1_14Types.EntityType.WANDERING_TRADER, 15).removed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_14Types.getTypeFromId(typeId);
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
@ -28,61 +29,16 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10> {
|
||||
|
||||
protected void registerPackets(Protocol1_9_4To1_10 protocol) {
|
||||
/* Item packets */
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Slot Value
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16);
|
||||
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x14, 0x14, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.ITEM_ARRAY); // 1 - Window Values
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
|
||||
for (int i = 0; i < stacks.length; i++)
|
||||
stacks[i] = handleItemToClient(stacks[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14);
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
wrapper.set(Type.ITEM, 0, handleItemToClient(stack));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3C);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@ -116,47 +72,13 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
|
||||
});
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x07, 0x07, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot
|
||||
map(Type.BYTE); // 2 - Button
|
||||
map(Type.SHORT); // 3 - Action number
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
itemRewriter.registerClickWindow(Type.ITEM, 0x07, 0x07);
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.ITEM); // 1 - Clicked Item
|
||||
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18);
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = wrapper.get(Type.ITEM, 0);
|
||||
handleItemToServer(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/* Block packets */
|
||||
|
||||
// Chunk packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -30,12 +30,9 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_11Types.getTypeFromId;
|
||||
|
||||
public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
|
||||
@Override
|
||||
@ -56,16 +53,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
map(Type.INT); // 8 - data
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
getTypeFromId(wrapper.get(Type.BYTE, 0), true)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -134,16 +122,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
map(Types1_9.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
// Track entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_10Types.getTypeFromId(wrapper.get(Type.UNSIGNED_BYTE, 0), false)
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
|
||||
|
||||
// Rewrite entity type / metadata
|
||||
handler(new PacketHandler() {
|
||||
@ -190,25 +169,8 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.INT, 0),
|
||||
Entity1_10Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_10Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
}
|
||||
});
|
||||
|
||||
@ -217,14 +179,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(getDimensionHandler(0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -241,33 +196,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_9.METADATA_LIST); // 7 - Metadata list
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
addTrackedEntity(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
Entity1_10Types.EntityType.PLAYER
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite Metadata
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_9.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 0),
|
||||
new MetaStorage(wrapper.get(Types1_9.METADATA_LIST, 0))
|
||||
).getMetaDataList()
|
||||
);
|
||||
}
|
||||
});
|
||||
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@ -326,4 +255,14 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int typeId) {
|
||||
return Entity1_10Types.getTypeFromId(typeId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int typeId) {
|
||||
return Entity1_10Types.getTypeFromId(typeId, true);
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,28 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
|
||||
public class ItemUtil {
|
||||
|
||||
/**
|
||||
* Sets all the data of the item into the original item.
|
||||
*
|
||||
* @param original item to be modified
|
||||
* @param item item to replicate the data from
|
||||
* @return modified original item
|
||||
*/
|
||||
public static void copyItem(Item original, Item item) {
|
||||
original.setIdentifier(item.getIdentifier());
|
||||
original.setAmount(item.getAmount());
|
||||
original.setData(item.getData());
|
||||
original.setTag(item.getTag() != null ? item.getTag().clone() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new item object with the same data as the given one.
|
||||
*
|
||||
* @param item item to be copied
|
||||
* @return a new copy of the item
|
||||
*/
|
||||
public static Item copyItem(Item item) {
|
||||
if (item == null) return null;
|
||||
return new Item(item.getId(), item.getAmount(), item.getData(), item.getTag() != null ? item.getTag().clone() : null);
|
||||
return new Item(item.getIdentifier(), item.getAmount(), item.getData(), item.getTag() != null ? item.getTag().clone() : null);
|
||||
}
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -61,7 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>2.1.4-19w38b</version>
|
||||
<version>2.1.4-19w39a</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren