Rewrite block action, effect, tags and advancements; palette rewriting

This commit is contained in:
creeper123123321 2018-08-10 19:21:35 -03:00
parent dfe1850b93
commit ff3bc9a0cd
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
5 changed files with 149 additions and 26 deletions

View File

@ -23,13 +23,13 @@ public class MetadataRewriter {
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data));
metadata.setValue(Protocol18w32aTO1_13.getNewBlockStateId(data));
}
if (type == null) continue;
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
// New block format
int data = (int) metadata.getValue();
metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data));
metadata.setValue(Protocol18w32aTO1_13.getNewBlockStateId(data));
}
if(type.is(EntityType.ITEM)){

View File

@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol18w32ato1_13;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
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;
@ -30,7 +31,7 @@ public class Protocol18w32aTO1_13 extends Protocol {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String s = wrapper.passthrough(Type.STRING);
if(s.length() > 256){
if (s.length() > 256) {
wrapper.cancel();
}
}
@ -48,7 +49,7 @@ public class Protocol18w32aTO1_13 extends Protocol {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT);
if(hand == 1){
if (hand == 1) {
wrapper.cancel();
}
}
@ -66,7 +67,7 @@ public class Protocol18w32aTO1_13 extends Protocol {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
if(action == 0){
if (action == 0) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.VAR_INT);
@ -78,6 +79,76 @@ public class Protocol18w32aTO1_13 extends Protocol {
});
}
});
// Advancements
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier
// Parent
if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING);
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.STRING); // Title
wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.passthrough(Type.FLAT_ITEM);
InventoryPackets.toClient(icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y
}
wrapper.passthrough(Type.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array
}
}
}
});
}
});
registerOutgoing(State.PLAY, 0x55, 0x55, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.read(Type.VAR_INT); // block tags
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
Integer[] blocks = wrapper.passthrough(Type.VAR_INT_ARRAY);
for (int j = 0; j < blocks.length; j++) {
blocks[j] = getNewBlockId(blocks[j]);
}
}
int itemTagsSize = wrapper.read(Type.VAR_INT); // item tags
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY);
for (int j = 0; j < items.length; j++) {
items[j] = InventoryPackets.getNewItemId(items[j]);
}
}
}
});
}
});
}
@Override
@ -88,7 +159,7 @@ public class Protocol18w32aTO1_13 extends Protocol {
}
public static int getMapBlockId(int blockId) {
public static int getNewBlockStateId(int blockId) {
if (blockId > 8573) {
blockId += 17;
} else if (blockId > 8463) {
@ -101,4 +172,12 @@ public class Protocol18w32aTO1_13 extends Protocol {
return blockId;
}
public static int getNewBlockId(final int oldBlockId) {
int blockId = oldBlockId;
if (oldBlockId >= 561) {
blockId += 5;
}
return blockId;
}
}

View File

@ -43,7 +43,7 @@ public class EntityPackets {
if (entType != null) {
if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, Protocol18w32aTO1_13.getMapBlockId(data));
wrapper.set(Type.INT, 0, Protocol18w32aTO1_13.getNewBlockStateId(data));
}
}
// Register Type ID

View File

@ -118,15 +118,25 @@ public class InventoryPackets {
public static void toClient(Item item) {
if (item == null) return;
if(item.getId() >= 443){
item.setId((short) (item.getId() + 5));
item.setId((short) getNewItemId(item.getId()));
}
public static int getNewItemId(int itemId) {
if (itemId >= 443) {
return itemId + 5;
}
return itemId;
}
public static void toServer(Item item) {
if (item == null) return;
if(item.getId() >= 448){
item.setId((short) (item.getId() - 5));
item.setId((short) getOldItemId(item.getId()));
}
public static int getOldItemId(int newId) {
if (newId >= 448) {
return newId - 5;
}
return newId;
}
}

View File

@ -26,18 +26,13 @@ public class WorldPackets {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int block = section.getBlock(x, y, z);
section.setFlatBlock(x, y, z, Protocol18w32aTO1_13.getMapBlockId(block));
}
for (ChunkSection section : chunk.getSections()) {
if (section != null) {
for (int i = 0; i < section.getPalette().size(); i++) {
section.getPalette().set(
i,
Protocol18w32aTO1_13.getNewBlockStateId(section.getPalette().get(i))
);
}
}
}
@ -47,6 +42,23 @@ public class WorldPackets {
}
});
// Block Action
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION); // Location
map(Type.UNSIGNED_BYTE); // Action id
map(Type.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, Protocol18w32aTO1_13.getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
// Block Change
protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() {
@Override
@ -58,7 +70,7 @@ public class WorldPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, Protocol18w32aTO1_13.getMapBlockId(id));
wrapper.set(Type.VAR_INT, 0, Protocol18w32aTO1_13.getNewBlockStateId(id));
}
});
}
@ -77,7 +89,29 @@ public class WorldPackets {
// Convert ids
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
int id = record.getBlockId();
record.setBlockId(Protocol18w32aTO1_13.getMapBlockId(id));
record.setBlockId(Protocol18w32aTO1_13.getNewBlockStateId(id));
}
}
});
}
});
// Effect packet
protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // Effect Id
map(Type.POSITION); // Location
map(Type.INT); // Data
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data));
} else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, data = Protocol18w32aTO1_13.getNewBlockStateId(data));
}
}
});
@ -140,7 +174,7 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0);
if(id == 3 || id == 20){
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol18w32aTO1_13.getMapBlockId(data));
wrapper.set(Type.VAR_INT, 0, Protocol18w32aTO1_13.getNewBlockStateId(data));
}
}
});