Cache player names for holograms of loaders (#88)

This commit is contained in:
OmerBenGera 2024-03-15 11:55:05 +02:00
parent 2b05c098d5
commit 901f630d89
9 changed files with 36 additions and 18 deletions

View File

@ -27,6 +27,7 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
public final List<EntityHolograms> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -67,6 +68,8 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
@Override
@ -117,9 +120,8 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
}
private void updateName(EntityHolograms hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -28,6 +28,7 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
public final List<EntityHolograms> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
@Override
@ -131,9 +134,8 @@ public final class TileEntityChunkLoader extends TileEntity implements ITickable
}
private void updateName(EntityHolograms hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -30,6 +30,7 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
private final ChunkLoaderBlockEntityTicker ticker;
private final ServerLevel serverLevel;
private final BlockPos blockPos;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -75,6 +76,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
public void tick() {
@ -133,9 +136,8 @@ public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEn
}
private void updateName(EntityHologram hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")

View File

@ -27,6 +27,7 @@ public final class TileEntityChunkLoader extends TileEntity implements IUpdatePl
public final List<EntityHolograms> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private final String cachedPlacerName;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
@ -67,6 +68,8 @@ public final class TileEntityChunkLoader extends TileEntity implements IUpdatePl
currentY += 0.23;
holograms.add(hologram);
}
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
}
@Override
@ -117,9 +120,8 @@ public final class TileEntityChunkLoader extends TileEntity implements IUpdatePl
}
private void updateName(EntityHolograms hologram, String line) {
String placerName = Optional.ofNullable(chunkLoader.getWhoPlaced().getName()).orElse("");
hologram.setHologramName(line
.replace("{0}", placerName)
.replace("{0}", this.cachedPlacerName)
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")