Skip to content

Commit

Permalink
Fix billboard and background
Browse files Browse the repository at this point in the history
Fix holograms not loading when fetching the newest version failed
  • Loading branch information
OliverSchlueter committed Mar 18, 2023
1 parent 2c50b20 commit 0ab8560
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
31 changes: 12 additions & 19 deletions src/main/java/de/oliver/Hologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -64,8 +62,10 @@ public void spawn(ServerPlayer serverPlayer){
updateLocation(serverPlayer);
updateText(serverPlayer);
updateBillboard(serverPlayer);
updateBackground(serverPlayer);
updateScale(serverPlayer);
if(background != null){
updateBackground(serverPlayer);
}
}

public void remove(ServerPlayer serverPlayer) {
Expand All @@ -76,10 +76,8 @@ public void remove(ServerPlayer serverPlayer) {
public void updateText(ServerPlayer serverPlayer){
entity.setText(getText());

List<SynchedEntityData.DataValue<?>> dataValues = entity.getEntityData().getNonDefaultValues();
if(serverPlayer != null && dataValues != null) {
ClientboundSetEntityDataPacket setEntityDataPacket = new ClientboundSetEntityDataPacket(entity.getId(), dataValues);
serverPlayer.connection.send(setEntityDataPacket);
if(serverPlayer != null) {
entity.getEntityData().refresh(serverPlayer);
}
}

Expand All @@ -95,10 +93,9 @@ public void updateLocation(ServerPlayer serverPlayer){
public void updateBillboard(ServerPlayer serverPlayer){
entity.setBillboardConstraints(billboard);

List<SynchedEntityData.DataValue<?>> dataValues = entity.getEntityData().getNonDefaultValues();
if(serverPlayer != null && dataValues != null) {
ClientboundSetEntityDataPacket setEntityDataPacket = new ClientboundSetEntityDataPacket(entity.getId(), dataValues);
serverPlayer.connection.send(setEntityDataPacket);

if(serverPlayer != null) {
entity.getEntityData().refresh(serverPlayer);
}
}

Expand All @@ -112,20 +109,16 @@ public void updateScale(ServerPlayer serverPlayer){
entity.setTransformation(transformation);


List<SynchedEntityData.DataValue<?>> dataValues = entity.getEntityData().getNonDefaultValues();
if(serverPlayer != null && dataValues != null) {
ClientboundSetEntityDataPacket setEntityDataPacket = new ClientboundSetEntityDataPacket(entity.getId(), dataValues);
serverPlayer.connection.send(setEntityDataPacket);
if(serverPlayer != null) {
entity.getEntityData().refresh(serverPlayer);
}
}

public void updateBackground(ServerPlayer serverPlayer){
entity.setBackgroundColor(background.getColor() | 0xC8000000);

List<SynchedEntityData.DataValue<?>> dataValues = entity.getEntityData().getNonDefaultValues();
if(serverPlayer != null && dataValues != null) {
ClientboundSetEntityDataPacket setEntityDataPacket = new ClientboundSetEntityDataPacket(entity.getId(), dataValues);
serverPlayer.connection.send(setEntityDataPacket);
if(serverPlayer != null) {
entity.getEntityData().refresh(serverPlayer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/oliver/commands/HologramCMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private boolean create(Player p, PlayerList playerList, String name){
List<String> lines = new ArrayList<>();
lines.add("Edit this line with /hologram edit " + name);

Hologram hologram = new Hologram(name, p.getLocation(), lines, Display.BillboardConstraints.CENTER, 1f, ChatFormatting.getByHexValue(Display.TextDisplay.INITIAL_BACKGROUND));
Hologram hologram = new Hologram(name, p.getLocation(), lines, Display.BillboardConstraints.CENTER, 1f, null);
hologram.create();
for (ServerPlayer player : playerList.players) {
hologram.spawn(player);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/oliver/utils/VersionFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static ComparableVersion fetch(String url){
try {
jsonString = getDataFromUrl(url);
} catch (IOException e) {
throw new RuntimeException(e);
return new ComparableVersion("0.0.0");
}

// Parse the JSON data into a Map
Expand Down

0 comments on commit 0ab8560

Please sign in to comment.