mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Remove MarkerHologram class, add parameter to Hologram constructor
This commit is contained in:
parent
6a2846a9c6
commit
323fcbe114
@ -20,8 +20,10 @@ import java.util.Set;
|
||||
public class Hologram implements Viewable {
|
||||
|
||||
private static final float OFFSET_Y = -0.9875f;
|
||||
private static final float MARKER_OFFSET_Y = -0.40625f;
|
||||
|
||||
private final Entity entity;
|
||||
private final float yOffset;
|
||||
|
||||
private Position position;
|
||||
private Component text;
|
||||
@ -75,45 +77,43 @@ public class Hologram implements Viewable {
|
||||
* @param autoViewable {@code true}if the hologram should be visible automatically, otherwise {@code false}.
|
||||
*/
|
||||
public Hologram(Instance instance, Position spawnPosition, Component text, boolean autoViewable) {
|
||||
this(instance, spawnPosition, text, autoViewable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link Hologram} with the given parameters.
|
||||
*
|
||||
* @param instance The instance where the hologram should be spawned.
|
||||
* @param spawnPosition The spawn position of this hologram.
|
||||
* @param text The text of this hologram.
|
||||
* @param autoViewable {@code true}if the hologram should be visible automatically, otherwise {@code false}.
|
||||
*/
|
||||
public Hologram(Instance instance, Position spawnPosition, Component text, boolean autoViewable, boolean marker) {
|
||||
this.entity = new Entity(EntityType.ARMOR_STAND);
|
||||
|
||||
ArmorStandMeta armorStandMeta = (ArmorStandMeta) entity.getEntityMeta();
|
||||
|
||||
armorStandMeta.setNotifyAboutChanges(false);
|
||||
|
||||
updateDefaultMeta(armorStandMeta);
|
||||
|
||||
armorStandMeta.setNotifyAboutChanges(true);
|
||||
|
||||
this.entity.setInstance(instance, spawnPosition.clone().add(0, getOffsetY(), 0));
|
||||
this.entity.setAutoViewable(autoViewable);
|
||||
|
||||
this.position = spawnPosition;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default {@link ArmorStandMeta} flags for this Hologram,
|
||||
* subclasses may override this method to modify the metadata.
|
||||
*
|
||||
* @param armorStandMeta the meta to update
|
||||
*/
|
||||
protected void updateDefaultMeta(ArmorStandMeta armorStandMeta) {
|
||||
armorStandMeta.setSmall(true);
|
||||
if(marker) {
|
||||
this.yOffset = MARKER_OFFSET_Y;
|
||||
armorStandMeta.setMarker(true);
|
||||
} else {
|
||||
this.yOffset = OFFSET_Y;
|
||||
armorStandMeta.setSmall(true);
|
||||
}
|
||||
armorStandMeta.setHasNoGravity(true);
|
||||
armorStandMeta.setCustomName(Component.empty());
|
||||
armorStandMeta.setCustomNameVisible(true);
|
||||
armorStandMeta.setInvisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vertical offset used to center the nametag,
|
||||
* subclasses may override this method to modify the position
|
||||
*
|
||||
* @return the vertical offset used to center the nametag
|
||||
*/
|
||||
protected float getOffsetY() {
|
||||
return OFFSET_Y;
|
||||
armorStandMeta.setNotifyAboutChanges(true);
|
||||
|
||||
this.entity.setInstance(instance, spawnPosition.clone().add(0, this.yOffset, 0));
|
||||
this.entity.setAutoViewable(autoViewable);
|
||||
|
||||
this.position = spawnPosition;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +132,7 @@ public class Hologram implements Viewable {
|
||||
*/
|
||||
public void setPosition(Position position) {
|
||||
checkRemoved();
|
||||
position.add(0, getOffsetY(), 0);
|
||||
position.add(0, this.yOffset, 0);
|
||||
this.position = position;
|
||||
this.entity.teleport(position);
|
||||
}
|
||||
|
@ -1,99 +0,0 @@
|
||||
package net.minestom.server.entity.hologram;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.metadata.other.ArmorStandMeta;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hologram that sets the marker flag of the Armor Stand, allowing players to place blocks inside of it
|
||||
*/
|
||||
public class MarkerHologram extends Hologram {
|
||||
|
||||
//Y Offset such that the spawnPosition represents the center of the rendered nametag
|
||||
private static final float OFFSET_Y = -0.40625f;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MarkerHologram} with the given parameters.
|
||||
*
|
||||
* @param instance The instance where the hologram should be spawned.
|
||||
* @param spawnPosition The spawn position of this hologram.
|
||||
* @param text The text of this hologram.
|
||||
* @param autoViewable {@code true}if the hologram should be visible automatically, otherwise {@code false}.
|
||||
* @deprecated Use {@link #MarkerHologram(Instance, Position, Component, boolean)}
|
||||
*/
|
||||
public MarkerHologram(Instance instance, Position spawnPosition, JsonMessage text, boolean autoViewable) {
|
||||
super(instance, spawnPosition, text, autoViewable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MarkerHologram} with the given parameters.
|
||||
*
|
||||
* @param instance The instance where the hologram should be spawned.
|
||||
* @param spawnPosition The spawn position of this hologram.
|
||||
* @param text The text of this hologram.
|
||||
* @deprecated Use {@link #MarkerHologram(Instance, Position, Component)}
|
||||
*/
|
||||
public MarkerHologram(Instance instance, Position spawnPosition, JsonMessage text) {
|
||||
super(instance, spawnPosition, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MarkerHologram} with the given parameters.
|
||||
*
|
||||
* @param instance The instance where the hologram should be spawned.
|
||||
* @param spawnPosition The spawn position of this hologram.
|
||||
* @param text The text of this hologram.
|
||||
*/
|
||||
public MarkerHologram(Instance instance, Position spawnPosition, Component text) {
|
||||
super(instance, spawnPosition, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MarkerHologram} with the given parameters.
|
||||
*
|
||||
* @param instance The instance where the hologram should be spawned.
|
||||
* @param spawnPosition The spawn position of this hologram.
|
||||
* @param text The text of this hologram.
|
||||
* @param autoViewable {@code true}if the hologram should be visible automatically, otherwise {@code false}.
|
||||
*/
|
||||
public MarkerHologram(Instance instance, Position spawnPosition, Component text, boolean autoViewable) {
|
||||
super(instance, spawnPosition, text, autoViewable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default {@link ArmorStandMeta} flags for this Hologram,
|
||||
* subclasses may override this method to modify the metadata.
|
||||
*
|
||||
* {@link MarkerHologram}: Set the marker flag to true
|
||||
*
|
||||
* @param armorStandMeta the meta to update
|
||||
*/
|
||||
@Override
|
||||
protected void updateDefaultMeta(ArmorStandMeta armorStandMeta) {
|
||||
super.updateDefaultMeta(armorStandMeta);
|
||||
|
||||
armorStandMeta.setMarker(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vertical offset used to center the nametag,
|
||||
* subclasses may override this method to modify the position
|
||||
*
|
||||
* {@link MarkerHologram}: Correct the Y offset for marker Armor Stands
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected float getOffsetY() {
|
||||
return OFFSET_Y;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user