Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-20 06:50:10 +01:00
Fix the Item Rewriter, implement 1.12 block rewrites & handle fallingblocks
Dieser Commit ist enthalten in:
Ursprung
d113e11c3b
Commit
2a1f6602ba
@ -72,8 +72,8 @@ public class EntityType1_12 {
|
||||
ENTITY_ILLAGER_ABSTRACT(-1, ENTITY_INSENTIENT),
|
||||
EVOCATION_ILLAGER(34, ENTITY_ILLAGER_ABSTRACT),
|
||||
VEX(35, ENTITY_INSENTIENT),
|
||||
VINDICATION_ILLAGER(36, ENTITY_INSENTIENT),
|
||||
ILLUSION_ILLAGER(37, ENTITY_ILLAGER_ABSTRACT),
|
||||
VINDICATION_ILLAGER(36, ENTITY_ILLAGER_ABSTRACT),
|
||||
ILLUSION_ILLAGER(37, EVOCATION_ILLAGER),
|
||||
|
||||
// Vehicles
|
||||
MINECART_ABSTRACT(-1, ENTITY),
|
||||
|
@ -45,21 +45,22 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
return i;
|
||||
BlockItemSettings data = replacementData.get((int) i.getId());
|
||||
|
||||
Item original = ItemUtil.copyItem(i);
|
||||
if (data.hasRepItem()) {
|
||||
i = ItemUtil.copyItem(data.getRepItem());
|
||||
|
||||
if (i.getTag() == null)
|
||||
i.setTag(new CompoundTag(""));
|
||||
i.getTag().put(createViaNBT(i));
|
||||
i.getTag().put(createViaNBT(original));
|
||||
|
||||
if (i.getTag() != null)
|
||||
for (Tag ai : i.getTag())
|
||||
i.getTag().put(ai);
|
||||
i.setAmount(i.getAmount());
|
||||
i.setAmount(original.getAmount());
|
||||
// Keep original data when -1
|
||||
if (i.getData() == -1)
|
||||
i.setData(original.getData());
|
||||
}
|
||||
if (data.hasItemTagHandler()) {
|
||||
if (!i.getTag().contains("ViaBackwards|" + getProtocolName()))
|
||||
i.getTag().put(createViaNBT(i));
|
||||
i.getTag().put(createViaNBT(original));
|
||||
data.getItemHandler().handle(i);
|
||||
}
|
||||
|
||||
@ -88,7 +89,7 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
return item;
|
||||
}
|
||||
|
||||
protected int handleBlockID(int idx) {
|
||||
public int handleBlockID(int idx) {
|
||||
int type = idx >> 4;
|
||||
int meta = idx & 15;
|
||||
|
||||
@ -99,13 +100,13 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
return (b.getId() << 4 | (b.getData() & 15));
|
||||
}
|
||||
|
||||
protected Block handleBlock(int block, int data) {
|
||||
public Block handleBlock(int block, int data) {
|
||||
if (!containsBlock(block))
|
||||
return null;
|
||||
|
||||
Block b = replacementData.get(block).getRepBlock();
|
||||
Block b = replacementData.get(block).getRepBlock().clone();
|
||||
// For some blocks, the data can still be useful (:
|
||||
if (b.getData() != -1)
|
||||
if (b.getData() == -1)
|
||||
b.setData(data);
|
||||
return b;
|
||||
}
|
||||
|
@ -22,14 +22,16 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
@Getter
|
||||
public class Protocol1_11_1To1_12 extends BackwardsProtocol {
|
||||
// TODO store all rewriters and make them easy accessible?
|
||||
private EntityPackets1_12 entityPackets;
|
||||
private BlockItemPackets1_12 blockItemPackets;
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
new ChangedPacketIds().register(this);
|
||||
(entityPackets = new EntityPackets1_12()).register(this);
|
||||
(blockItemPackets = new BlockItemPackets1_12()).register(this);
|
||||
new SoundPackets1_12().register(this);
|
||||
new BlockItemPackets1_12().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,15 +12,241 @@ package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets;
|
||||
|
||||
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
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_12;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
||||
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;
|
||||
|
||||
public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12> {
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_11_1To1_12 protocol) {
|
||||
/* Item packets */
|
||||
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 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]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Type.BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Input Item
|
||||
wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
|
||||
if (secondItem)
|
||||
wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Second Item
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Type.INT); // Number of tools uses
|
||||
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x08, 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/* Block packets */
|
||||
|
||||
// Chunk packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
|
||||
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.9.4 Chunk type since nothing changed.
|
||||
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
|
||||
|
||||
handleChunk(chunk);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Block Change Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.POSITION); // 0 - Block Position
|
||||
map(Type.VAR_INT); // 1 - Block
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int idx = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Multi Block Change Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int count = wrapper.passthrough(Type.VAR_INT); // Array length
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords
|
||||
|
||||
int id = wrapper.read(Type.VAR_INT); // Block ID
|
||||
wrapper.write(Type.VAR_INT, handleBlockID(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Update Block Entity
|
||||
protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.POSITION); // 0 - Position
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Action
|
||||
map(Type.NBT); // 2 - NBT
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Remove bed color
|
||||
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11)
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
|
||||
Metadata data = e.getData();
|
||||
|
||||
if (data.getMetaType().equals(MetaType1_12.Slot)) // Is Item
|
||||
data.setValue(handleItemToClient((Item) data.getValue()));
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
// Client Status
|
||||
protocol.registerIncoming(State.PLAY, 0x04, 0x03, new PacketRemapper() {
|
||||
@Override
|
||||
@ -41,6 +267,25 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Concrete -> Stained clay? (Also got a new name Terracota?)
|
||||
rewrite(251)
|
||||
.repItem(new Item((short) 159, (byte) 1, (short) -1, getNamedTag("1.12 Concrete")))
|
||||
.repBlock(new Block(159, -1)); // TODO color provided by name
|
||||
|
||||
// Concrete Powder -> Wool
|
||||
rewrite(252)
|
||||
.repItem(new Item((short) 35, (byte) 1, (short) -1, getNamedTag("1.12 Concrete Powder")))
|
||||
.repBlock(new Block(35, -1)); // TODO color provided by name
|
||||
|
||||
// Knowledge book -> book
|
||||
rewrite(453)
|
||||
.repItem(new Item((short) 340, (byte) 1, (short) 0, getNamedTag("1.12 Knowledge Book"))); // TODO glow
|
||||
|
||||
// Glazed Terracotta -> Stained Clay
|
||||
for (int i = 235; i < 250; i++) {
|
||||
rewrite(i).repItem(new Item((short) 159, (byte) 1, (short) (i - 235), getNamedTag("1.12 Glazed Terracotta")))
|
||||
.repBlock(new Block(159, (i - 235))); // TODO color provided by name
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class ChangedPacketIds extends Rewriter<Protocol1_11_1To1_12> {
|
||||
// 0x3B -> 0x39 Entity Metadata handled in EntityPackets1_12.java
|
||||
p.registerOutgoing(State.PLAY, 0x3C, 0x3A); // Attach Entity
|
||||
p.registerOutgoing(State.PLAY, 0x3D, 0x3B); // Entity Velocity
|
||||
p.registerOutgoing(State.PLAY, 0x3E, 0x3C); // Entity Equipment
|
||||
// 0x3E -> 0x3C Entity Equipment handled in BlockItemPackets1_12.java
|
||||
p.registerOutgoing(State.PLAY, 0x3F, 0x3D); // Set Experience
|
||||
p.registerOutgoing(State.PLAY, 0x40, 0x3E); // Update Health
|
||||
p.registerOutgoing(State.PLAY, 0x41, 0x3F); // ScoreBoard Objective
|
||||
@ -93,7 +93,7 @@ public class ChangedPacketIds extends Rewriter<Protocol1_11_1To1_12> {
|
||||
p.registerIncoming(State.PLAY, 0x05, 0x04); // Client Settings
|
||||
p.registerIncoming(State.PLAY, 0x06, 0x05); // Confirm Transaction (Serverbound)
|
||||
p.registerIncoming(State.PLAY, 0x07, 0x06); // Enchant Item
|
||||
p.registerIncoming(State.PLAY, 0x08, 0x07); // Click Window
|
||||
// 0x08 -> 0x07 Click Window handled in BlockItemPackets1_12.java
|
||||
p.registerIncoming(State.PLAY, 0x09, 0x08); // Close Window (Serverbound)
|
||||
p.registerIncoming(State.PLAY, 0x0A, 0x09); // Plugin message (Serverbound)
|
||||
p.registerIncoming(State.PLAY, 0x0B, 0x0A); // Use Entity
|
||||
@ -112,7 +112,7 @@ public class ChangedPacketIds extends Rewriter<Protocol1_11_1To1_12> {
|
||||
p.registerIncoming(State.PLAY, 0x18, 0x16); // Resource Pack Status
|
||||
p.registerIncoming(State.PLAY, 0x19, -1); // Advancement Tab
|
||||
p.registerIncoming(State.PLAY, 0x1A, 0x17); // Held Item Change (Serverbound)
|
||||
p.registerIncoming(State.PLAY, 0x1B, 0x18); // Creative Inventory Action
|
||||
// 0x1B -> 0x18 Creative Inventory Action handled in BlockItemPackets.java
|
||||
p.registerIncoming(State.PLAY, 0x1C, 0x19); // Update Sign
|
||||
p.registerIncoming(State.PLAY, 0x1D, 0x1A); // Animatin (Serverbound)
|
||||
p.registerIncoming(State.PLAY, 0x1E, 0x1B); // Spectate
|
||||
|
@ -17,6 +17,7 @@ import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
|
||||
import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -81,6 +82,23 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replace falling blocks
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<EntityType1_12.ObjectType> type = ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get().equals(ObjectType.FALLING_BLOCK)) {
|
||||
int objectData = wrapper.get(Type.INT, 0);
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data);
|
||||
|
||||
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -344,9 +362,9 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
||||
regEntType(EntityType.PARROT, EntityType.BAT).spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
|
||||
regEntType(EntityType.ILLUSION_ILLAGER, EntityType.EVOCATION_ILLAGER);
|
||||
|
||||
// Handle Illager TODO wtf does this metadata do?
|
||||
registerMetaHandler().filter(EntityType.ENTITY_ILLAGER_ABSTRACT, true, 12).removed();
|
||||
registerMetaHandler().filter(EntityType.ENTITY_ILLAGER_ABSTRACT, true, 13).handleIndexChange(12);
|
||||
// Handle Illager TODO wtf does this metadata do? Is aggresive it is a bitmask?
|
||||
registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 12).removed();
|
||||
registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 13).handleIndexChange(12);
|
||||
|
||||
// Parrot remove animal metadata
|
||||
registerMetaHandler().filter(EntityType.PARROT, 12).removed(); // Is baby
|
||||
|
@ -20,4 +20,8 @@ import lombok.EqualsAndHashCode;
|
||||
public class Block {
|
||||
private int id;
|
||||
private int data;
|
||||
|
||||
public Block clone() {
|
||||
return new Block(id, data);
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren