mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-18 16:17:45 +01:00
Handle 1.13 areaeffectcloud particle data
This commit is contained in:
parent
1857244eae
commit
9d3bec1aa1
@ -10,12 +10,10 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.api.rewriters;
|
package nl.matsv.viabackwards.api.rewriters;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
|
|
||||||
public abstract class Rewriter<T extends BackwardsProtocol> {
|
public abstract class Rewriter<T extends BackwardsProtocol> {
|
||||||
@Getter
|
protected T protocol;
|
||||||
private T protocol;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register everything
|
* Register everything
|
||||||
@ -39,4 +37,8 @@ public abstract class Rewriter<T extends BackwardsProtocol> {
|
|||||||
* Register rewrites
|
* Register rewrites
|
||||||
*/
|
*/
|
||||||
protected abstract void registerRewrites();
|
protected abstract void registerRewrites();
|
||||||
|
|
||||||
|
public T getProtocol() {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,40 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPack
|
|||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.api.type.types.Particle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ParticleMapping {
|
public class ParticleMapping {
|
||||||
private static final ParticleData[] particles;
|
private static final ParticleData[] particles;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
ParticleHandler blockHandler = new ParticleHandler() {
|
||||||
|
@Override
|
||||||
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||||
|
return rewrite(wrapper.read(Type.VAR_INT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData> data) {
|
||||||
|
return rewrite((int) data.get(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] rewrite(int newType) {
|
||||||
|
int blockType = BlockItemPackets1_13.toOldId(newType);
|
||||||
|
|
||||||
|
int type = blockType >> 4;
|
||||||
|
int meta = blockType & 15;
|
||||||
|
|
||||||
|
return new int[]{type + (meta << 12)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
particles = new ParticleData[]{
|
particles = new ParticleData[]{
|
||||||
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
|
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
|
||||||
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
|
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
|
||||||
rewrite(35), // (2->35) minecraft:barrier -> barrier
|
rewrite(35), // (2->35) minecraft:barrier -> barrier
|
||||||
rewrite(37, ParticleMapping::blockHandler),
|
rewrite(37, blockHandler),
|
||||||
// (3->37) minecraft:block -> blockcrack
|
// (3->37) minecraft:block -> blockcrack
|
||||||
rewrite(4), // (4->4) minecraft:bubble -> bubble
|
rewrite(4), // (4->4) minecraft:bubble -> bubble
|
||||||
rewrite(29), // (5->29) minecraft:cloud -> cloud
|
rewrite(29), // (5->29) minecraft:cloud -> cloud
|
||||||
@ -36,20 +60,28 @@ public class ParticleMapping {
|
|||||||
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
|
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
|
||||||
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
|
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
|
||||||
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
|
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
|
||||||
rewrite(30, ((protocol, wrapper) -> {
|
rewrite(30, new ParticleHandler() {
|
||||||
float r = wrapper.read(Type.FLOAT);
|
@Override
|
||||||
float g = wrapper.read(Type.FLOAT);
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||||
float b = wrapper.read(Type.FLOAT);
|
float r = wrapper.read(Type.FLOAT);
|
||||||
float scale = wrapper.read(Type.FLOAT);
|
float g = wrapper.read(Type.FLOAT);
|
||||||
|
float b = wrapper.read(Type.FLOAT);
|
||||||
|
float scale = wrapper.read(Type.FLOAT);
|
||||||
|
|
||||||
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
|
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
|
||||||
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
|
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
|
||||||
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
|
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
|
||||||
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
|
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
|
||||||
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
|
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
|
||||||
|
|
||||||
return new Integer[0];
|
return null;
|
||||||
})), // (11->30) minecraft:dust -> reddust
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData> data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}), // (11->30) minecraft:dust -> reddust
|
||||||
rewrite(13), // (12->13) minecraft:effect -> spell
|
rewrite(13), // (12->13) minecraft:effect -> spell
|
||||||
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
|
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
|
||||||
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit
|
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit
|
||||||
@ -58,7 +90,7 @@ public class ParticleMapping {
|
|||||||
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
|
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
|
||||||
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
|
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
|
||||||
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
|
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
|
||||||
rewrite(46, ParticleMapping::blockHandler),
|
rewrite(46, blockHandler),
|
||||||
// (20->46) minecraft:falling_dust -> fallingdust
|
// (20->46) minecraft:falling_dust -> fallingdust
|
||||||
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
|
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
|
||||||
rewrite(6), // (22->6) minecraft:fishing -> wake
|
rewrite(6), // (22->6) minecraft:fishing -> wake
|
||||||
@ -66,11 +98,21 @@ public class ParticleMapping {
|
|||||||
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
|
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
|
||||||
rewrite(34), // (25->34) minecraft:heart -> heart
|
rewrite(34), // (25->34) minecraft:heart -> heart
|
||||||
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
|
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
|
||||||
rewrite(36, (protocol, wrapper) -> {
|
rewrite(36, new ParticleHandler() {
|
||||||
Item item = protocol.getBlockItemPackets().handleItemToClient(
|
@Override
|
||||||
wrapper.read(Type.FLAT_ITEM)
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||||
);
|
return rewrite(protocol, wrapper.read(Type.FLAT_ITEM));
|
||||||
return new Integer[]{item.getIdentifier(), (int) item.getData()};
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData> data) {
|
||||||
|
return rewrite(protocol, (Item) data.get(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
|
||||||
|
Item item = protocol.getBlockItemPackets().handleItemToClient(newItem);
|
||||||
|
return new int[]{item.getIdentifier(), item.getData()};
|
||||||
|
}
|
||||||
}), // (27->36) minecraft:item -> iconcrack
|
}), // (27->36) minecraft:item -> iconcrack
|
||||||
rewrite(33), // (28->33) minecraft:item_slime -> slime
|
rewrite(33), // (28->33) minecraft:item_slime -> slime
|
||||||
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
|
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
|
||||||
@ -97,15 +139,6 @@ public class ParticleMapping {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Integer[] blockHandler(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
|
||||||
int blockType = BlockItemPackets1_13.toOldId(wrapper.read(Type.VAR_INT));
|
|
||||||
|
|
||||||
int type = blockType >> 4;
|
|
||||||
int meta = blockType & 15;
|
|
||||||
|
|
||||||
return new Integer[]{type + (meta << 12)};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ParticleData getMapping(int id) {
|
public static ParticleData getMapping(int id) {
|
||||||
return particles[id];
|
return particles[id];
|
||||||
}
|
}
|
||||||
@ -119,20 +152,27 @@ public class ParticleMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ParticleHandler {
|
interface ParticleHandler {
|
||||||
Integer[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception;
|
|
||||||
|
int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception;
|
||||||
|
|
||||||
|
int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData> data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public static class ParticleData {
|
public static class ParticleData {
|
||||||
private static final Integer[] A = new Integer[0];
|
|
||||||
private final int historyId;
|
private final int historyId;
|
||||||
private ParticleHandler handler;
|
private ParticleHandler handler;
|
||||||
|
|
||||||
public Integer[] rewriteData(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
public int[] rewriteData(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||||
if (handler == null) return A;
|
if (handler == null) return null;
|
||||||
return handler.rewrite(protocol, wrapper);
|
return handler.rewrite(protocol, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int[] rewriteMeta(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData> data) {
|
||||||
|
if (handler == null) return null;
|
||||||
|
return handler.rewrite(protocol, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
|||||||
else if (typeId == 6) {
|
else if (typeId == 6) {
|
||||||
meta.setMetaType(MetaType1_12.Slot);
|
meta.setMetaType(MetaType1_12.Slot);
|
||||||
Item item = (Item) meta.getValue();
|
Item item = (Item) meta.getValue();
|
||||||
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item));
|
meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discontinue particles
|
// Discontinue particles
|
||||||
@ -396,9 +396,18 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
|||||||
Particle particle = (Particle) meta.getValue();
|
Particle particle = (Particle) meta.getValue();
|
||||||
|
|
||||||
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
|
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
|
||||||
|
|
||||||
|
int firstArg = 0;
|
||||||
|
int secondArg = 0;
|
||||||
|
int[] particleArgs = data.rewriteMeta(protocol, particle.getArguments());
|
||||||
|
if (particleArgs != null && particleArgs.length != 0) {
|
||||||
|
firstArg = particleArgs[0];
|
||||||
|
secondArg = particleArgs.length == 2 ? particleArgs[1] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
e.createMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
|
e.createMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
|
||||||
e.createMeta(new Metadata(10, MetaType1_12.VarInt, 0)); //TODO particle data
|
e.createMeta(new Metadata(10, MetaType1_12.VarInt, firstArg));
|
||||||
e.createMeta(new Metadata(11, MetaType1_12.VarInt, 0)); //TODO particle data
|
e.createMeta(new Metadata(11, MetaType1_12.VarInt, secondArg));
|
||||||
|
|
||||||
throw RemovedValueException.EX;
|
throw RemovedValueException.EX;
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,6 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.types.Particle;
|
|
||||||
import us.myles.ViaVersion.packets.State;
|
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.ChatRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||||
@ -129,14 +128,14 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
|||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
Particle particle = new Particle(wrapper.get(Type.INT, 0));
|
ParticleMapping.ParticleData old = ParticleMapping.getMapping(wrapper.get(Type.INT, 0));
|
||||||
|
|
||||||
ParticleMapping.ParticleData old = ParticleMapping.getMapping(particle.getId());
|
|
||||||
|
|
||||||
wrapper.set(Type.INT, 0, old.getHistoryId());
|
wrapper.set(Type.INT, 0, old.getHistoryId());
|
||||||
|
|
||||||
for (int i : old.rewriteData(protocol, wrapper))
|
int[] data = old.rewriteData(protocol, wrapper);
|
||||||
wrapper.write(Type.VAR_INT, i);
|
if (data != null) {
|
||||||
|
for (int i : data)
|
||||||
|
wrapper.write(Type.VAR_INT, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user