Remap tridents, fix falling dust and lingering potions (#140)

* Fix falling dust particle for 1.9 clients

* Fix concurrent meta addition / lingering potions
Fixes #125

* Remap trident and trident sounds
This commit is contained in:
Nassim 2019-09-07 14:49:05 +02:00 committed by Myles
parent 781ef86af6
commit e6059845aa
6 changed files with 105 additions and 34 deletions

View File

@ -14,5 +14,6 @@ import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
public interface MetaHandler { public interface MetaHandler {
Metadata handle(MetaHandlerEvent e) throws RemovedValueException; Metadata handle(MetaHandlerEvent e) throws RemovedValueException;
} }

View File

@ -10,33 +10,43 @@
package nl.matsv.viabackwards.api.entities.meta; package nl.matsv.viabackwards.api.entities.meta;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Getter @Getter
@AllArgsConstructor @RequiredArgsConstructor
public class MetaHandlerEvent { public class MetaHandlerEvent {
private UserConnection user; private final UserConnection user;
private EntityTracker.StoredEntity entity; private final EntityTracker.StoredEntity entity;
private int index = -1; private final int index;
private Metadata data; private final Metadata data;
@Getter private final MetaStorage storage;
private MetaStorage storage; private List<Metadata> extraData;
public boolean hasData() { public boolean hasData() {
return data != null; return data != null;
} }
public Optional<Metadata> getMetaByIndex(int index) { public Optional<Metadata> getMetaByIndex(int index) {
for (Metadata meta : getStorage().getMetaDataList()) for (Metadata meta : storage.getMetaDataList())
if (index == meta.getId()) if (index == meta.getId())
return Optional.of(meta); return Optional.of(meta);
return Optional.empty(); return Optional.empty();
} }
public void clearExtraData() {
extraData = null;
}
public void createMeta(Metadata metadata) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).add(metadata);
}
} }

View File

@ -120,16 +120,31 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
List<Metadata> newList = new CopyOnWriteArrayList<>(); List<Metadata> newList = new CopyOnWriteArrayList<>();
for (MetaHandlerSettings settings : metaHandlers) { for (MetaHandlerSettings settings : metaHandlers) {
List<Metadata> extraData = null;
for (Metadata md : storage.getMetaDataList()) { for (Metadata md : storage.getMetaDataList()) {
Metadata nmd = md; Metadata nmd = md;
MetaHandlerEvent event = null;
try { try {
if (settings.isGucci(type, nmd)) if (settings.isGucci(type, nmd)) {
nmd = settings.getHandler().handle(new MetaHandlerEvent(user, entity, nmd.getId(), nmd, storage)); event = new MetaHandlerEvent(user, entity, nmd.getId(), nmd, storage);
nmd = settings.getHandler().handle(event);
if (nmd == null) if (event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
event.clearExtraData();
}
}
if (nmd == null) {
throw new RemovedValueException(); throw new RemovedValueException();
}
newList.add(nmd); newList.add(nmd);
} catch (RemovedValueException ignored) { } catch (RemovedValueException e) {
// add the additionally created data here in case of an interruption
if (event != null && event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData());
}
} catch (Exception e) { } catch (Exception e) {
if (Via.getManager().isDebug()) { if (Via.getManager().isDebug()) {
Logger log = ViaBackwards.getPlatform().getLogger(); Logger log = ViaBackwards.getPlatform().getLogger();
@ -139,12 +154,18 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
} }
} }
} }
storage.setMetaDataList(new ArrayList<>(newList));
List<Metadata> newData = new ArrayList<>(newList);
if (extraData != null) {
newData.addAll(extraData);
}
storage.setMetaDataList(newData);
newList.clear(); newList.clear();
} }
// Handle Entity Name // Handle Entity Name
Optional<Metadata> opMd = storage.get(getDisplayNameIndex()); Optional<Metadata> opMd = storage.get(displayNameIndex);
if (opMd.isPresent()) { if (opMd.isPresent()) {
Optional<EntityData> opEd = getEntityData(type); Optional<EntityData> opEd = getEntityData(type);
if (opEd.isPresent()) { if (opEd.isPresent()) {
@ -152,7 +173,7 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
EntityData entData = opEd.get(); EntityData entData = opEd.get();
if (entData.getMobName() != null && if (entData.getMobName() != null &&
(data.getValue() == null || ((String) data.getValue()).isEmpty()) && (data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) { data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
String mobName = entData.getMobName(); String mobName = entData.getMobName();
if (isDisplayNameJson) { if (isDisplayNameJson) {
mobName = ChatRewriter.legacyTextToJson(mobName); mobName = ChatRewriter.legacyTextToJson(mobName);

View File

@ -17,6 +17,16 @@ public class SoundMapping {
Arrays.fill(sounds, (short) -1); Arrays.fill(sounds, (short) -1);
mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds")); mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
// Simulate some trident sounds
sounds[628] = 138; // throw -> shoot
sounds[629] = 137; // hit -> hit_player
sounds[630] = 137; // hit_ground -> hit
sounds[631] = 139; // riptide_1 -> shoot
sounds[632] = 139; // riptide_2
sounds[633] = 139; // riptide_3
sounds[634] = 139; // throw -> shoot
// no fitting thunder remap
} }
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {

View File

@ -12,6 +12,7 @@ import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
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.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
@ -26,6 +27,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> { public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
@ -65,13 +67,16 @@ public class EntityPackets1_13 extends EntityRewriter<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 {
Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0)); Optional<EntityType1_13.ObjectType> optionalType = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) { if (!optionalType.isPresent()) return;
final EntityType1_13.ObjectType type = optionalType.get();
if (type == EntityType1_13.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Type.INT, 0);
int combined = BlockItemPackets1_13.toOldId(blockState); int combined = BlockItemPackets1_13.toOldId(blockState);
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12); combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
wrapper.set(Type.INT, 0, combined); wrapper.set(Type.INT, 0, combined);
} else if (type.isPresent() && type.get() == EntityType1_13.ObjectType.ITEM_FRAME) { } else if (type == EntityType1_13.ObjectType.ITEM_FRAME) {
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 0);
switch (data) { switch (data) {
case 3: case 3:
@ -85,6 +90,8 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
break; break;
} }
wrapper.set(Type.INT, 0, data); wrapper.set(Type.INT, 0, data);
} else if (type == EntityType1_13.ObjectType.TRIDENT) {
wrapper.set(Type.BYTE, 0, (byte) EntityType1_13.ObjectType.TIPPED_ARROW.getId());
} }
} }
}); });
@ -347,15 +354,12 @@ public class EntityPackets1_13 extends EntityRewriter<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 {
wrapper.set( final List<Metadata> metaDataList = handleMeta(
Types1_12.METADATA_LIST,
0,
handleMeta(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0)) new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
).getMetaDataList() ).getMetaDataList();
); wrapper.set(Types1_12.METADATA_LIST, 0, metaDataList);
} }
}); });
} }
@ -385,7 +389,6 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
// Turtle // Turtle
regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle"); regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle");
// Rewrite Meta types // Rewrite Meta types
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
@ -482,15 +485,14 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
Metadata meta = e.getData(); Metadata meta = e.getData();
Particle particle = (Particle) meta.getValue(); Particle particle = (Particle) meta.getValue();
// TODO Rewrite particle ids ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
e.getStorage().add(new Metadata(9, MetaType1_12.VarInt, 0)); e.createMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
e.getStorage().add(new Metadata(10, MetaType1_12.VarInt, 0)); e.createMeta(new Metadata(10, MetaType1_12.VarInt, 0)); //TODO particle data
e.getStorage().add(new Metadata(11, MetaType1_12.VarInt, 0)); e.createMeta(new Metadata(11, MetaType1_12.VarInt, 0)); //TODO particle data
throw new RemovedValueException(); throw new RemovedValueException();
}); });
// TODO REWRITE BLOCKS IN MINECART // TODO REWRITE BLOCKS IN MINECART
} }
} }

View File

@ -223,6 +223,33 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
return data; return data;
}); });
// Particle
protocol.registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
map(Type.BOOLEAN);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 46) { // new falling_dust
wrapper.set(Type.INT, 0, 38); // -> block_dust
}
}
});
}
});
} }
@Override @Override