Skip to content

Commit

Permalink
Adds SquareMaster
Browse files Browse the repository at this point in the history
Adds PackMaster
Adds RelativeLocation (big props to Wasabi_Thumbs)
Adds DisplayPackFloatingPet and childs
Adds SyncDisplayPackEntityAnimations
Fixes BlobSelector and BlobEditor not rerendering from collection.
  • Loading branch information
anjoismysign committed Mar 4, 2024
1 parent e12cb63 commit 9ac2508
Show file tree
Hide file tree
Showing 16 changed files with 657 additions and 127 deletions.
2 changes: 1 addition & 1 deletion ci-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.67</version>
<version>1.698.02</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.69</version>
<version>1.698.02</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.69</version>
<version>1.698.02</version>
<packaging>pom</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,13 @@ public <T> BlobSelector<T> customSelector(@NotNull String blobInventoryKey,
dataType, selectorList.get(), onReturn);
selector.setItemsPerPage(selector.getSlots(buttonRangeKey)
== null ? 1 : selector.getSlots(buttonRangeKey).size());
selector.setWhiteBackgroundName(buttonRangeKey);
if (display != null)
selector.selectElement(player,
onSelect,
null,
display);
display,
selectorList::get);
else
selector.selectElement(player,
onSelect,
Expand Down Expand Up @@ -556,7 +558,8 @@ public <T> BlobEditor<T> customEditor(@NotNull String blobInventoryKey,
playerSelector.selectElement(player,
onAdd,
null,
addDisplay);
addDisplay,
viewCollection);
}, viewCollection.get(), onReturn));
BlobEditor<T> editor = uber.thanks();
editor.setItemsPerPage(editor.getSlots(buttonRangeKey) == null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package us.mytheria.bloblib.displayentity;

import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;

public class BlockDisplayPackFloatingPet extends DisplayPackFloatingPet<BlockDisplay, BlockData> {
/**
* Creates a pet
*
* @param owner - the FloatingPet owner
* @param display - the display (like BlockData/ItemStack)
* (must be an item or a block)
* @param particle - the Particle to itemStack
* @param customName - the CustomName of the pet
* (if null will be used 'owner's Pet')
*/
public BlockDisplayPackFloatingPet(Player owner,
BlockData display,
@Nullable Particle particle,
@Nullable String customName,
DisplayFloatingPetSettings settings,
@NotNull PackMaster packMaster,
int index) {
super(owner, display, particle, customName, settings, packMaster, index);
}

void spawnEntity(Location location) {
BlobLib plugin = BlobLib.getInstance();
entity = (BlockDisplay) location.getWorld().spawnEntity(location,
EntityType.BLOCK_DISPLAY);
entity.setPersistent(false);
entity.setTeleportDuration(1);
setCustomName(getCustomName());
entity.setBlock(getDisplay());
initAnimations(plugin);
}

public void setDisplay(BlockData display) {
this.display = display;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public abstract class DisplayFloatingPet<T extends Display, R extends Cloneable>
private UUID owner;
private boolean activated, pauseLogic;
private String customName;
private SyncDisplayEntityAnimations animations;
private BukkitTask logicTask;
protected SyncDisplayEntityAnimations animations;
protected BukkitTask logicTask;
protected R display;
private final DisplayFloatingPetSettings settings;
protected final DisplayFloatingPetSettings settings;

/**
* Creates a pet
Expand All @@ -45,6 +45,7 @@ public abstract class DisplayFloatingPet<T extends Display, R extends Cloneable>
* @param particle - the Particle to itemStack
* @param customName - the CustomName of the pet
* (if null will be used 'owner's Pet')
* @param settings - the settings of the pet
*/
public DisplayFloatingPet(@NotNull Player owner,
@NotNull R display,
Expand Down Expand Up @@ -110,7 +111,7 @@ protected void initAnimations(JavaPlugin plugin) {
initLogic(plugin);
}

private void initLogic(JavaPlugin plugin) {
protected void initLogic(JavaPlugin plugin) {
EntityAnimationsCarrier animationsCarrier = settings.animationsCarrier();
logicTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
Player owner = findOwner();
Expand Down Expand Up @@ -140,11 +141,11 @@ private void moveAway() {
this.location = animations.moveAway(findOwnerOrFail(), location);
}

private void move() {
protected void move() {
this.location = animations.move(findOwnerOrFail(), location);
}

private void idle() {
protected void idle() {
this.location = animations.idle(findOwnerOrFail(), location);
}

Expand Down Expand Up @@ -265,7 +266,7 @@ public Location getLocation() {
return location;
}

private void setLocation(Location location) {
protected void setLocation(Location location) {
this.location = location;
}

Expand All @@ -281,7 +282,7 @@ public boolean isActive() {
return activated;
}

private void setActive(boolean activated) {
protected void setActive(boolean activated) {
this.activated = activated;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package us.mytheria.bloblib.displayentity;

import org.bukkit.Bukkit;
import org.bukkit.Particle;
import org.bukkit.entity.Display;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Represents a FloatingPet.
* Uses 1.20.2+ Bukkit API
*
* @param <T> - the Display entity
* @param <R> - (BlockData/ItemStack)
*/
public abstract class DisplayPackFloatingPet<T extends Display, R extends Cloneable>
extends DisplayFloatingPet<T, R> {
protected final PackMaster<DisplayPackFloatingPet<T, R>> packMaster;
private final int index, holdIndex;

/**
* Creates a pet
*
* @param owner - the FloatingPet owner
* @param display - the display (like BlockData/ItemStack)
* (must be an item or a block)
* @param particle - the Particle to itemStack
* @param customName - the CustomName of the pet
* (if null will be used 'owner's Pet')
* @param settings - the settings of the pet
*/
public DisplayPackFloatingPet(@NotNull Player owner,
@NotNull R display,
@Nullable Particle particle,
@Nullable String customName,
@NotNull DisplayFloatingPetSettings settings,
@NotNull PackMaster<DisplayPackFloatingPet<T, R>> packMaster,
int index) {
super(owner, display, particle, customName, settings);
this.packMaster = packMaster;
this.index = index;
this.holdIndex = packMaster.addComponent(this, index);
}

@Override
protected void initLogic(JavaPlugin plugin) {
EntityAnimationsCarrier animationsCarrier = settings.animationsCarrier();
logicTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
Player owner = findOwner();
if (owner == null || !owner.isOnline()) {
destroy();
return;
}
spawnParticles(animationsCarrier.particlesOffset(), 0);
if (!isPauseLogic())
move();
}, 0, 1);
}

@Override
public void destroy() {
super.destroy();
}

@Override
protected void initAnimations(JavaPlugin plugin) {
animations = new SyncDisplayPackEntityAnimations<>(this,
settings.animationsCarrier(),
packMaster,
holdIndex);
initLogic(plugin);
}

public int getIndex() {
return index;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package us.mytheria.bloblib.displayentity;

import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Transformation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.display.DisplayDecorator;

public class ItemDisplayPackFloatingPet extends DisplayPackFloatingPet<ItemDisplay, ItemStack> {
/**
* Creates a pet
*
* @param owner - the FloatingPet owner
* @param display - the display (like BlockData/ItemStack)
* (must be an item or a block)
* @param particle - the Particle to itemStack
* @param customName - the CustomName of the pet
* (if null will be used 'owner's Pet')
*/
public ItemDisplayPackFloatingPet(Player owner,
ItemStack display,
@Nullable Particle particle,
@Nullable String customName,
DisplayFloatingPetSettings settings,
@NotNull PackMaster packMaster,
int index) {
super(owner, display, particle, customName, settings, packMaster, index);
}

void spawnEntity(Location location) {
BlobLib plugin = BlobLib.getInstance();
entity = (ItemDisplay) location.getWorld().spawnEntity(location,
EntityType.ITEM_DISPLAY);
entity.setItemDisplayTransform(ItemDisplay.ItemDisplayTransform.FIXED);
entity.setPersistent(false);
entity.setTeleportDuration(1);
setCustomName(getCustomName());
entity.setItemStack(getDisplay());
Transformation transformation = entity.getTransformation();
entity.setTransformation(new Transformation(
transformation.getTranslation().add(0f, -0.5f, 0f),
transformation.getLeftRotation(), transformation.getScale(),
transformation.getRightRotation()));
DisplayDecorator<ItemDisplay> decorator = new DisplayDecorator<>(entity, plugin);
decorator.transformLeft(1, 0, 0, 90, 1);
initAnimations(plugin);
}

public void setDisplay(ItemStack display) {
this.display = display;
}
}
54 changes: 54 additions & 0 deletions src/main/java/us/mytheria/bloblib/displayentity/PackMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package us.mytheria.bloblib.displayentity;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector2d;
import us.mytheria.bloblib.entities.SquareMaster;
import us.mytheria.bloblib.gists.RelativeLocation;

import java.util.Map;
import java.util.Objects;

public class PackMaster<T> extends SquareMaster<T> {
private @NotNull Vector pivot;

public static <T> PackMaster<T> of(int maxPerRow,
double componentLength,
@NotNull Map<Integer, T> components,
@NotNull Vector pivot) {
Objects.requireNonNull(components, "'components' cannot be null!");
Objects.requireNonNull(pivot, "'pivot' cannot be null!");
return new PackMaster<>(maxPerRow, componentLength, components, pivot);
}

private PackMaster(int maxPerRow,
double componentLength,
@NotNull Map<Integer, T> components,
@NotNull Vector pivot) {
super(maxPerRow, componentLength, components);
this.pivot = pivot;
}

@NotNull
public Vector getPivot() {
return pivot;
}

public Location pivot(Player player, int index) {
Location location = player.getLocation().clone();
location.setPitch(Location.normalizePitch(0));
Vector2d offset = getOffset(index);
return RelativeLocation.getInstance()
.getRelativeLocation(location,
pivot.getX() - (offset.y * getComponentLength()),
pivot.getZ() + (offset.x * getComponentLength()),
pivot.getY());
}

public void setPivot(@NotNull Vector pivot) {
Objects.requireNonNull(pivot, "'pivot' cannot be null!");
this.pivot = pivot;
}
}
Loading

0 comments on commit 9ac2508

Please sign in to comment.