mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-18 16:17:45 +01:00
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:
parent
781ef86af6
commit
e6059845aa
@ -14,5 +14,6 @@ import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
|
||||
public interface MetaHandler {
|
||||
|
||||
Metadata handle(MetaHandlerEvent e) throws RemovedValueException;
|
||||
}
|
||||
|
@ -10,33 +10,43 @@
|
||||
|
||||
package nl.matsv.viabackwards.api.entities.meta;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class MetaHandlerEvent {
|
||||
private UserConnection user;
|
||||
private EntityTracker.StoredEntity entity;
|
||||
private int index = -1;
|
||||
private Metadata data;
|
||||
@Getter
|
||||
private MetaStorage storage;
|
||||
private final UserConnection user;
|
||||
private final EntityTracker.StoredEntity entity;
|
||||
private final int index;
|
||||
private final Metadata data;
|
||||
private final MetaStorage storage;
|
||||
private List<Metadata> extraData;
|
||||
|
||||
public boolean hasData() {
|
||||
return data != null;
|
||||
}
|
||||
|
||||
public Optional<Metadata> getMetaByIndex(int index) {
|
||||
for (Metadata meta : getStorage().getMetaDataList())
|
||||
for (Metadata meta : storage.getMetaDataList())
|
||||
if (index == meta.getId())
|
||||
return Optional.of(meta);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void clearExtraData() {
|
||||
extraData = null;
|
||||
}
|
||||
|
||||
public void createMeta(Metadata metadata) {
|
||||
(extraData != null ? extraData : (extraData = new ArrayList<>())).add(metadata);
|
||||
}
|
||||
}
|
||||
|
@ -120,16 +120,31 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
List<Metadata> newList = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (MetaHandlerSettings settings : metaHandlers) {
|
||||
List<Metadata> extraData = null;
|
||||
for (Metadata md : storage.getMetaDataList()) {
|
||||
Metadata nmd = md;
|
||||
MetaHandlerEvent event = null;
|
||||
try {
|
||||
if (settings.isGucci(type, nmd))
|
||||
nmd = settings.getHandler().handle(new MetaHandlerEvent(user, entity, nmd.getId(), nmd, storage));
|
||||
if (settings.isGucci(type, nmd)) {
|
||||
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();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
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();
|
||||
}
|
||||
|
||||
// Handle Entity Name
|
||||
Optional<Metadata> opMd = storage.get(getDisplayNameIndex());
|
||||
Optional<Metadata> opMd = storage.get(displayNameIndex);
|
||||
if (opMd.isPresent()) {
|
||||
Optional<EntityData> opEd = getEntityData(type);
|
||||
if (opEd.isPresent()) {
|
||||
@ -152,7 +173,7 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
EntityData entData = opEd.get();
|
||||
if (entData.getMobName() != null &&
|
||||
(data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
|
||||
data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) {
|
||||
data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
|
||||
String mobName = entData.getMobName();
|
||||
if (isDisplayNameJson) {
|
||||
mobName = ChatRewriter.legacyTextToJson(mobName);
|
||||
|
@ -17,6 +17,16 @@ public class SoundMapping {
|
||||
|
||||
Arrays.fill(sounds, (short) -1);
|
||||
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) {
|
||||
|
@ -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.data.EntityTypeMapping;
|
||||
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.minecraft.item.Item;
|
||||
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_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) {
|
||||
Optional<EntityType1_13.ObjectType> optionalType = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
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 combined = BlockItemPackets1_13.toOldId(blockState);
|
||||
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
|
||||
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);
|
||||
switch (data) {
|
||||
case 3:
|
||||
@ -85,6 +90,8 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
break;
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(
|
||||
Types1_12.METADATA_LIST,
|
||||
0,
|
||||
handleMeta(
|
||||
final List<Metadata> metaDataList = handleMeta(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.VAR_INT, 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
|
||||
regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle");
|
||||
|
||||
|
||||
// Rewrite Meta types
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
@ -482,15 +485,14 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||
Metadata meta = e.getData();
|
||||
Particle particle = (Particle) meta.getValue();
|
||||
|
||||
// TODO Rewrite particle ids
|
||||
e.getStorage().add(new Metadata(9, MetaType1_12.VarInt, 0));
|
||||
e.getStorage().add(new Metadata(10, MetaType1_12.VarInt, 0));
|
||||
e.getStorage().add(new Metadata(11, MetaType1_12.VarInt, 0));
|
||||
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
|
||||
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(11, MetaType1_12.VarInt, 0)); //TODO particle data
|
||||
|
||||
throw new RemovedValueException();
|
||||
});
|
||||
|
||||
// TODO REWRITE BLOCKS IN MINECART
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +223,33 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user