-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
e12cb63
commit 9ac2508
Showing
16 changed files
with
657 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/us/mytheria/bloblib/displayentity/BlockDisplayPackFloatingPet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/us/mytheria/bloblib/displayentity/DisplayPackFloatingPet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/us/mytheria/bloblib/displayentity/ItemDisplayPackFloatingPet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
src/main/java/us/mytheria/bloblib/displayentity/PackMaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.