mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-01-22 23:41:27 +01:00
Some more cleanup
This commit is contained in:
parent
1c1ec10a0a
commit
5d974858fe
@ -1,11 +1,9 @@
|
||||
package us.myles.ViaVersion.api.rewriters;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
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.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
@ -13,11 +11,11 @@ import us.myles.ViaVersion.packets.State;
|
||||
// If any of these methods become outdated, just create a new rewriter overriding the methods
|
||||
public class BlockRewriter {
|
||||
private final Protocol protocol;
|
||||
private final BlockIdRewriteFunction blockStateRewriter;
|
||||
private final BlockIdRewriteFunction blockRewriter;
|
||||
private final IdRewriteFunction blockStateRewriter;
|
||||
private final IdRewriteFunction blockRewriter;
|
||||
private final Type<Position> positionType;
|
||||
|
||||
public BlockRewriter(Protocol protocol, Type<Position> positionType, BlockIdRewriteFunction blockStateRewriter, BlockIdRewriteFunction blockRewriter) {
|
||||
public BlockRewriter(Protocol protocol, Type<Position> positionType, IdRewriteFunction blockStateRewriter, IdRewriteFunction blockRewriter) {
|
||||
this.protocol = protocol;
|
||||
this.positionType = positionType;
|
||||
this.blockStateRewriter = blockStateRewriter;
|
||||
@ -69,7 +67,7 @@ public class BlockRewriter {
|
||||
registerBlockChange(oldPacketId, newPacketId);
|
||||
}
|
||||
|
||||
public void registerEffect(int oldPacketId, int newPacketId, int playRecordId, int blockBreakId, ItemRewriter.ItemIdRewriteFunction itemIdRewriteFunction) {
|
||||
public void registerEffect(int oldPacketId, int newPacketId, int playRecordId, int blockBreakId, IdRewriteFunction itemIdRewriteFunction) {
|
||||
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -91,6 +89,11 @@ public class BlockRewriter {
|
||||
|
||||
public void registerSpawnParticle(Type<?> coordType, int oldPacketId, int newPacketId, int blockId, int fallingDustId, int itemId,
|
||||
ItemRewriter.RewriteFunction itemRewriteFunction, Type<Item> itemType) {
|
||||
registerSpawnParticle(coordType, oldPacketId, newPacketId, blockId, fallingDustId, itemId, null, itemRewriteFunction, itemType);
|
||||
}
|
||||
|
||||
public void registerSpawnParticle(Type<?> coordType, int oldPacketId, int newPacketId, int blockId, int fallingDustId, int itemId,
|
||||
IdRewriteFunction particleRewriteFunction, ItemRewriter.RewriteFunction itemRewriteFunction, Type<Item> itemType) {
|
||||
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -104,26 +107,25 @@ public class BlockRewriter {
|
||||
map(Type.FLOAT); // 7 - Offset Z
|
||||
map(Type.FLOAT); // 8 - Particle Data
|
||||
map(Type.INT); // 9 - Particle Count
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
if (id == blockId || id == fallingDustId) {
|
||||
int data = wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.set(Type.VAR_INT, 0, blockStateRewriter.rewrite(data));
|
||||
} else if (id == itemId) {
|
||||
// Has to be like this, until we make *everything* object oriented inside of each protocol :(
|
||||
itemRewriteFunction.rewrite(wrapper.passthrough(itemType));
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
if (id == -1) return;
|
||||
if (id == blockId || id == fallingDustId) {
|
||||
int data = wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.set(Type.VAR_INT, 0, blockStateRewriter.rewrite(data));
|
||||
} else if (id == itemId) {
|
||||
// Has to be like this, until we make *everything* object oriented inside of each protocol :(
|
||||
itemRewriteFunction.rewrite(wrapper.passthrough(itemType));
|
||||
}
|
||||
|
||||
if (particleRewriteFunction != null) {
|
||||
int newId = particleRewriteFunction.rewrite(id);
|
||||
if (newId != id) {
|
||||
wrapper.set(Type.INT, 0, newId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockIdRewriteFunction {
|
||||
|
||||
int rewrite(int itemId);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package us.myles.ViaVersion.api.rewriters;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IdRewriteFunction {
|
||||
|
||||
int rewrite(int id);
|
||||
}
|
@ -85,7 +85,7 @@ public class ItemRewriter {
|
||||
});
|
||||
}
|
||||
|
||||
public void registerSetCooldown(int oldPacketId, int newPacketId, ItemIdRewriteFunction itemIDRewriteFunction) {
|
||||
public void registerSetCooldown(int oldPacketId, int newPacketId, IdRewriteFunction itemIDRewriteFunction) {
|
||||
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -120,10 +120,4 @@ public class ItemRewriter {
|
||||
|
||||
void rewrite(Item item);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ItemIdRewriteFunction {
|
||||
|
||||
int rewrite(int itemId);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
@ -14,6 +13,7 @@ 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.remapper.ValueCreator;
|
||||
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||
@ -39,6 +39,7 @@ public class WorldPackets {
|
||||
}
|
||||
|
||||
public static void register(final Protocol protocol) {
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, null, Protocol1_14To1_13_2::getNewBlockStateId, Protocol1_14To1_13_2::getNewBlockId);
|
||||
|
||||
// Block Break Animation
|
||||
protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() {
|
||||
@ -107,24 +108,7 @@ public class WorldPackets {
|
||||
});
|
||||
|
||||
// Multi Block Change
|
||||
protocol.registerOutgoing(State.PLAY, 0x0F, 0x0F, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Convert ids
|
||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||
int id = record.getBlockId();
|
||||
record.setBlockId(Protocol1_14To1_13_2.getNewBlockStateId(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
blockRewriter.registerMultiBlockChange(0x0F, 0x0F);
|
||||
|
||||
// Explosion
|
||||
protocol.registerOutgoing(State.PLAY, 0x1E, 0x1C, new PacketRemapper() {
|
||||
@ -302,39 +286,9 @@ public class WorldPackets {
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn Particle
|
||||
protocol.registerOutgoing(State.PLAY, 0x24, 0x23, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Particle ID
|
||||
map(Type.BOOLEAN); // 1 - Long Distance
|
||||
map(Type.FLOAT); // 2 - X
|
||||
map(Type.FLOAT); // 3 - Y
|
||||
map(Type.FLOAT); // 4 - Z
|
||||
map(Type.FLOAT); // 5 - Offset X
|
||||
map(Type.FLOAT); // 6 - Offset Y
|
||||
map(Type.FLOAT); // 7 - Offset Z
|
||||
map(Type.FLOAT); // 8 - Particle Data
|
||||
map(Type.INT); // 9 - Particle Count
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
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, Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
} else if (id == 27) {
|
||||
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
}
|
||||
|
||||
int newId = MetadataRewriter1_14To1_13_2.getNewParticleId(id);
|
||||
if (newId != id) {
|
||||
wrapper.set(Type.INT, 0, newId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Spawn particle
|
||||
blockRewriter.registerSpawnParticle(Type.FLOAT, 0x24, 0x23, 3, 20, 27,
|
||||
MetadataRewriter1_14To1_13_2::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
// Join Game
|
||||
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
|
||||
|
Loading…
Reference in New Issue
Block a user