Skip to content

Commit

Permalink
Implemented glowing images
Browse files Browse the repository at this point in the history
- Updated FakeImage
- Updated FakeItemFrame

> Closes #16
  • Loading branch information
josemmo committed Dec 27, 2021
1 parent 99b9fe4 commit 1fcb388
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -349,10 +349,11 @@ private void load() {

// Generate frames
frames = new FakeItemFrame[width*height];
boolean glowing = hasFlag(FLAG_GLOWING);
for (int col=0; col<width; col++) {
for (int row=0; row<height; row++) {
Location frameLocation = location.clone().add(getLocationVector.apply(col, row));
frames[height*col+row] = new FakeItemFrame(frameLocation, face, rotation, maps[col][row]);
frames[height*col+row] = new FakeItemFrame(frameLocation, face, rotation, glowing, maps[col][row]);
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/io/josemmo/bukkit/plugin/renderer/FakeItemFrame.java
Expand Up @@ -6,6 +6,7 @@
import io.josemmo.bukkit.plugin.packets.DestroyEntityPacket;
import io.josemmo.bukkit.plugin.packets.EntityMetadataPacket;
import io.josemmo.bukkit.plugin.packets.SpawnEntityPacket;
import io.josemmo.bukkit.plugin.utils.Internals;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Rotation;
Expand All @@ -19,11 +20,13 @@
public class FakeItemFrame extends FakeEntity {
public static final int MIN_FRAME_ID = Integer.MAX_VALUE / 4;
public static final int MAX_FRAME_ID = Integer.MAX_VALUE;
private static final boolean SUPPORTS_GLOWING = Internals.MINECRAFT_VERSION >= 17;
private static final AtomicInteger lastFrameId = new AtomicInteger(MAX_FRAME_ID);
private final int id;
private final Location location;
private final BlockFace face;
private final Rotation rotation;
private final boolean glowing;
private final FakeMap[] maps;

/**
Expand All @@ -44,13 +47,21 @@ private static int getNextId() {
* @param location Frame location
* @param face Block face
* @param rotation Frame rotation
* @param glowing Whether is glowing or regular frame
* @param maps Fake maps to animate
*/
public FakeItemFrame(@NotNull Location location, @NotNull BlockFace face, @NotNull Rotation rotation, @NotNull FakeMap[] maps) {
public FakeItemFrame(
@NotNull Location location,
@NotNull BlockFace face,
@NotNull Rotation rotation,
boolean glowing,
@NotNull FakeMap[] maps
) {
this.id = getNextId();
this.location = location;
this.face = face;
this.rotation = rotation;
this.glowing = glowing;
this.maps = maps;
plugin.fine("Created FakeItemFrame#" + this.id + " using " + this.maps.length + " FakeMap(s)");
}
Expand Down Expand Up @@ -100,7 +111,7 @@ public void spawn(@NotNull Player player) {
// Create item frame entity
SpawnEntityPacket framePacket = new SpawnEntityPacket();
framePacket.setId(id)
.setEntityType(EntityType.ITEM_FRAME)
.setEntityType((glowing && SUPPORTS_GLOWING) ? EntityType.GLOW_ITEM_FRAME : EntityType.ITEM_FRAME)
.setPosition(x, y, z)
.setRotation(pitch, yaw)
.setData(orientation);
Expand Down

0 comments on commit 1fcb388

Please sign in to comment.