3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Handle particles with 0 parameters

Dieser Commit ist enthalten in:
Matsv 2018-04-04 21:09:54 +02:00
Ursprung c0c1a6bbcf
Commit d066c2596b
2 geänderte Dateien mit 55 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -80,8 +80,8 @@ public class ParticleRewriter {
*/
}
public static Particle rewriteParticle(int particleId, int[] data) {
if (particles.size() >= particleId) {
public static Particle rewriteParticle(int particleId, Integer[] data) {
if (particleId >= particles.size()) {
Via.getPlatform().getLogger().severe("Failed to transform particles with id " + particleId + " and data " + Arrays.toString(data));
return null;
}
@ -99,14 +99,14 @@ public class ParticleRewriter {
}
interface ParticleDataHandler {
Particle handler(Particle particle, int[] data);
Particle handler(Particle particle, Integer[] data);
}
// TODO TEST
private static ParticleDataHandler reddustHandler() {
return new ParticleDataHandler() {
@Override
public Particle handler(Particle particle, int[] data) {
public Particle handler(Particle particle, Integer[] data) {
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1)); // Red 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 0)); // Green 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 0)); // Blue 0 - 1
@ -120,12 +120,12 @@ public class ParticleRewriter {
private static ParticleDataHandler iconcrackHandler() {
return new ParticleDataHandler() {
@Override
public Particle handler(Particle particle, int[] data) {
public Particle handler(Particle particle, Integer[] data) {
Item item;
if (data.length == 1)
item = new Item((short) data[0], (byte) 1, (short) 0, null);
item = new Item(data[0].shortValue(), (byte) 1, (short) 0, null);
else if (data.length == 2)
item = new Item((short) data[0], (byte) 1, (short) data[1], null);
item = new Item(data[0].shortValue(), (byte) 1, data[1].shortValue(), null);
else
return particle;
@ -139,7 +139,7 @@ public class ParticleRewriter {
private static ParticleDataHandler blockHandler() {
return new ParticleDataHandler() {
@Override
public Particle handler(Particle particle, int[] data) {
public Particle handler(Particle particle, Integer[] data) {
return particle;
}
};
@ -149,7 +149,7 @@ public class ParticleRewriter {
private static ParticleDataHandler blockdustHandler() {
return new ParticleDataHandler() {
@Override
public Particle handler(Particle particle, int[] data) {
public Particle handler(Particle particle, Integer[] data) {
return particle;
}
};
@ -159,7 +159,7 @@ public class ParticleRewriter {
private static ParticleDataHandler fallingdustHandler() {
return new ParticleDataHandler() {
@Override
public Particle handler(Particle particle, int[] data) {
public Particle handler(Particle particle, Integer[] data) {
return particle;
}
};
@ -171,7 +171,7 @@ public class ParticleRewriter {
private final int id;
private final ParticleDataHandler handler;
public Particle handle(Particle particle, int[] data) {
public Particle handle(Particle particle, Integer[] data) {
if (handler != null)
return handler.handler(particle, data);
return particle;

Datei anzeigen

@ -17,6 +17,8 @@ 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.protocols.protocolsnapshotto1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.Particle;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.ParticleRewriter;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.providers.BlockEntityProvider;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.providers.PaintingProvider;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.BlockStorage;
@ -191,11 +193,50 @@ public class WorldPackets {
protocol.registerOutgoing(State.PLAY, 0x22, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
// TODO: This packet has changed
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) {
wrapper.cancel();
public void handle(PacketWrapper wrapper) throws Exception {
int particleId = wrapper.get(Type.INT, 0);
// Get the data (Arrays are overrated)
int dataCount = 0;
// Particles with 1 data [BlockCrack,BlockDust,FallingDust]
if (particleId == 37 || particleId == 38 || particleId == 46)
dataCount = 1;
// Particles with 2 data [IconCrack]
else if (particleId == 36)
dataCount = 2;
Integer[] data = new Integer[dataCount];
for (int i = 0; i < data.length; i++)
data[i] = wrapper.read(Type.VAR_INT);
Particle particle = ParticleRewriter.rewriteParticle(particleId, data);
// Cancel if null
if (particle == null) {
wrapper.cancel();
return;
}
// System.out.println("Old particle " + particleId + " " + Arrays.toString(data) + " new Particle" + particle);
wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue());
}
});
}