Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-09 17:50:23 +01:00
Add support for 1.8 boss bars
Automatically converts legacy boss bars to 1.9 ones using ViaVersions's boss API. I suggest you add a config option Note: also fixed crash on wither/dragon spawn
Dieser Commit ist enthalten in:
Ursprung
c9e1360951
Commit
319e793cd6
@ -91,6 +91,7 @@ public enum MetaIndex {
|
|||||||
WITHER_TARGET2(Wither.class, 18, Type.Int, 12, NewType.VarInt),
|
WITHER_TARGET2(Wither.class, 18, Type.Int, 12, NewType.VarInt),
|
||||||
WITHER_TARGET3(Wither.class, 19, Type.Int, 13, NewType.VarInt),
|
WITHER_TARGET3(Wither.class, 19, Type.Int, 13, NewType.VarInt),
|
||||||
WITHER_INVULN_TIME(Wither.class, 20, Type.Int, 14, NewType.VarInt),
|
WITHER_INVULN_TIME(Wither.class, 20, Type.Int, 14, NewType.VarInt),
|
||||||
|
WITHER_PROPERTIES(Wither.class, 10, Type.Byte, NewType.Byte),
|
||||||
// wither skull
|
// wither skull
|
||||||
WITHERSKULL_INVULN(WitherSkull.class, 10, Type.Byte, 5, NewType.Boolean),
|
WITHERSKULL_INVULN(WitherSkull.class, 10, Type.Byte, 5, NewType.Boolean),
|
||||||
// guardian
|
// guardian
|
||||||
@ -123,7 +124,10 @@ public enum MetaIndex {
|
|||||||
ITEMFRAME_ITEM(ItemFrame.class, 8, Type.Slot, 5, NewType.Slot),
|
ITEMFRAME_ITEM(ItemFrame.class, 8, Type.Slot, 5, NewType.Slot),
|
||||||
ITEMFRAME_ROTATION(ItemFrame.class, 9, Type.Byte, 6, NewType.VarInt),
|
ITEMFRAME_ROTATION(ItemFrame.class, 9, Type.Byte, 6, NewType.VarInt),
|
||||||
// ender crystal
|
// ender crystal
|
||||||
ENDERCRYSTAL_HEALTH(EnderCrystal.class, 8, Type.Int, NewType.Discontinued),;
|
ENDERCRYSTAL_HEALTH(EnderCrystal.class, 8, Type.Int, NewType.Discontinued),
|
||||||
|
// Ender dragon
|
||||||
|
ENDERDRAGON_FLAG(EnderDragon.class, 15, Type.Byte, NewType.Discontinued),
|
||||||
|
ENDERDRAGON_PHASE(EnderDragon.class, 11, Type.Int, NewType.VarInt);
|
||||||
|
|
||||||
private Class<?> clazz;
|
private Class<?> clazz;
|
||||||
private int newIndex;
|
private int newIndex;
|
||||||
|
@ -207,7 +207,7 @@ public class MetadataRewriter {
|
|||||||
private MetaIndex index;
|
private MetaIndex index;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
private Entry(MetaIndex index, Object value, int id) {
|
public Entry(MetaIndex index, Object value, int id) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.oldID = id;
|
this.oldID = id;
|
||||||
|
@ -15,7 +15,12 @@ import us.myles.ViaVersion.CancelException;
|
|||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.ConnectionInfo;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
|
import us.myles.ViaVersion.api.boss.BossBar;
|
||||||
|
import us.myles.ViaVersion.api.boss.BossColor;
|
||||||
|
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||||
|
import us.myles.ViaVersion.metadata.MetaIndex;
|
||||||
import us.myles.ViaVersion.metadata.MetadataRewriter;
|
import us.myles.ViaVersion.metadata.MetadataRewriter;
|
||||||
|
import us.myles.ViaVersion.metadata.MetadataRewriter.Entry;
|
||||||
import us.myles.ViaVersion.packets.PacketType;
|
import us.myles.ViaVersion.packets.PacketType;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
@ -40,6 +45,7 @@ public class OutgoingTransformer {
|
|||||||
private final Map<Integer, Integer> vehicleMap = new HashMap<>();
|
private final Map<Integer, Integer> vehicleMap = new HashMap<>();
|
||||||
private final Set<Integer> validBlocking = new HashSet<>();
|
private final Set<Integer> validBlocking = new HashSet<>();
|
||||||
private final Set<Integer> knownHolograms = new HashSet<>();
|
private final Set<Integer> knownHolograms = new HashSet<>();
|
||||||
|
private final Map<Integer, BossBar> bossBarMap = new HashMap<>();
|
||||||
private boolean autoTeam = false;
|
private boolean autoTeam = false;
|
||||||
|
|
||||||
public OutgoingTransformer(ConnectionInfo info) {
|
public OutgoingTransformer(ConnectionInfo info) {
|
||||||
@ -384,6 +390,12 @@ public class OutgoingTransformer {
|
|||||||
clientEntityTypes.remove(entityID);
|
clientEntityTypes.remove(entityID);
|
||||||
knownHolograms.remove(entityID);
|
knownHolograms.remove(entityID);
|
||||||
PacketUtil.writeVarInt(entityID, output);
|
PacketUtil.writeVarInt(entityID, output);
|
||||||
|
|
||||||
|
// Remvoe boss bar
|
||||||
|
BossBar bar = bossBarMap.remove(entityID);
|
||||||
|
if(bar != null) {
|
||||||
|
bar.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -832,6 +844,14 @@ public class OutgoingTransformer {
|
|||||||
for (MetadataRewriter.Entry entry : list) {
|
for (MetadataRewriter.Entry entry : list) {
|
||||||
handleMetadata(entityID, entry, type);
|
handleMetadata(entityID, entry, type);
|
||||||
}
|
}
|
||||||
|
// Fix: wither (crash fix)
|
||||||
|
if(type == EntityType.WITHER) {
|
||||||
|
list.add(new Entry(MetaIndex.WITHER_PROPERTIES, (byte) 0, 10));
|
||||||
|
}
|
||||||
|
// Fix: Dragon (crash fix)
|
||||||
|
if(type == EntityType.ENDER_DRAGON) {
|
||||||
|
list.add(new Entry(MetaIndex.ENDERDRAGON_PHASE, 0, 11));
|
||||||
|
}
|
||||||
MetadataRewriter.writeMetadata1_9(type, list, output);
|
MetadataRewriter.writeMetadata1_9(type, list, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -875,6 +895,39 @@ public class OutgoingTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add config option
|
||||||
|
// Boss bar
|
||||||
|
if(type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
|
||||||
|
if(entry.getOldID() == 2) {
|
||||||
|
BossBar bar = bossBarMap.get(entityID);
|
||||||
|
String title = (String) entry.getValue();
|
||||||
|
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
|
||||||
|
if(bar == null) {
|
||||||
|
bar = ViaVersion.getInstance().createBossBar(title, BossColor.PURPLE, BossStyle.SOLID);
|
||||||
|
bossBarMap.put(entityID, bar);
|
||||||
|
bar.addPlayer(info.getPlayer());
|
||||||
|
bar.show();
|
||||||
|
} else {
|
||||||
|
bar.setTitle((String) entry.getValue());
|
||||||
|
}
|
||||||
|
} else if(entry.getOldID() == 6) {
|
||||||
|
BossBar bar = bossBarMap.get(entityID);
|
||||||
|
// Make health range between 0 and 1
|
||||||
|
float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
|
||||||
|
float health = Math.max(0.0f, Math.min(((float) entry.getValue()) / maxHealth, 1.0f));
|
||||||
|
System.out.println(health + " " + entry.getValue());
|
||||||
|
if(bar == null) {
|
||||||
|
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
|
||||||
|
bar = ViaVersion.getInstance().createBossBar(title, health, BossColor.PURPLE, BossStyle.SOLID);
|
||||||
|
bossBarMap.put(entityID, bar);
|
||||||
|
bar.addPlayer(info.getPlayer());
|
||||||
|
bar.show();
|
||||||
|
} else {
|
||||||
|
bar.setHealth(health);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren