Skip to content

Commit

Permalink
last public revision for animating vanilla skulls
Browse files Browse the repository at this point in the history
this feature will be removed here in the future and implemented in Geyser's Hurricane plugin.
  • Loading branch information
MrBsng committed Dec 1, 2023
1 parent 2c29ffa commit 90dea90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 57 deletions.
31 changes: 6 additions & 25 deletions src/main/java/com/tbyt/AnimateHeadsForGeyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void animateForGeyserPlayer(Connection playerConn) {
}
if (activeHead.getBlock().isBlockPowered())
continue;
Boolean nearbyRedstoneBlock = findNearbyRedstoneBlock(activeHead);
if (!nearbyRedstoneBlock) {
if(!activeHead.getBlock().isBlockIndirectlyPowered()) {
headsToRemove.add(activeHead);
// send deanimate packet
switch (currentMaterial) {
Expand Down Expand Up @@ -115,8 +114,7 @@ public void animateForGeyserPlayer(Connection playerConn) {
Material materialOfBlock = headBlock.getType();
// if Block is actually a dragon or piglin head block.
if (IsHead(materialOfBlock)) {
Boolean nearbyRedstoneBlock = findNearbyRedstoneBlock(headBlock.getLocation());
if (headBlock.isBlockPowered() || nearbyRedstoneBlock) {
if (headBlock.isBlockPowered() || headBlock.isBlockIndirectlyPowered()) {
if (!headsToAnimate.contains(headBlock.getLocation()))
headsToAnimate.add(headBlock.getLocation());
}
Expand Down Expand Up @@ -151,23 +149,6 @@ public void animateForGeyserPlayer(Connection playerConn) {
}
}

// server does not pick up isBlockPowered if redstone block is powering adjacent
// to the head.
public boolean findNearbyRedstoneBlock(Location location) {
ArrayList<Material> adjacentMaterials = new ArrayList<Material>();
adjacentMaterials.add(location.clone().add(-1, 0, 0).getBlock().getType());
adjacentMaterials.add(location.clone().add(1, 0, 0).getBlock().getType());
adjacentMaterials.add(location.clone().add(0, -1, 0).getBlock().getType());
adjacentMaterials.add(location.clone().add(0, 1, 0).getBlock().getType());
adjacentMaterials.add(location.clone().add(0, 0, -1).getBlock().getType());
adjacentMaterials.add(location.clone().add(0, 0, 1).getBlock().getType());
for (Material nearbyBlock : adjacentMaterials) {
if (nearbyBlock.equals(Material.REDSTONE_BLOCK))
return true;
}
return false;
}

public boolean IsHead(Material material) {
switch (material) {
case DRAGON_HEAD:
Expand All @@ -184,10 +165,10 @@ public boolean IsHead(Material material) {
}

// animate or deanimate bedrock animations for vanilla skulls.
public void sendAnimatePacket(Connection playerConn, Block head, int HeadType, int AnimationStatus) {
public void sendAnimatePacket(Connection playerConn, Block head, int headType, int animationStatus) {
NbtMapBuilder builder = NbtMap.builder();
builder.putByte("DoingAnimation", (byte) AnimationStatus);
builder.putInt("MouthTickCount", AnimationStatus);
builder.putByte("DoingAnimation", (byte) animationStatus);
builder.putInt("MouthTickCount", animationStatus);
// if head is not on a Wall.
if (head.getBlockData() instanceof Rotatable) {
Rotatable HeadRotation = (Rotatable) head.getBlockData();
Expand Down Expand Up @@ -248,7 +229,7 @@ public void sendAnimatePacket(Connection playerConn, Block head, int HeadType, i
builder.put("Rotation", rotationDegree);
} else
builder.put("Rotation", 0f);
builder.putByte("SkullType", (byte) HeadType);
builder.putByte("SkullType", (byte) headType);
builder.putString("id", "Skull");
builder.putByte("isMovable", (byte) 1);
builder.putInt("X", head.getX());
Expand Down
50 changes: 18 additions & 32 deletions src/main/java/com/tbyt/BedrockParity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.event.bedrock.SessionJoinEvent;
import org.geysermc.api.Geyser;
import org.geysermc.api.connection.Connection;

import org.geysermc.floodgate.api.FloodgateApi;
import java.util.UUID;
import java.util.function.Predicate;
import org.geysermc.api.Geyser;
import org.geysermc.geyser.GeyserImpl;

public class BedrockParity extends JavaPlugin implements EventRegistrar {
public class BedrockParity extends JavaPlugin {
private Predicate<UUID> playerChecker;
@Override
public void onEnable() {
Expand Down Expand Up @@ -49,34 +45,24 @@ public void onEnable() {
getLogger().info("Sweeping Edge Book Fix in Anvil is manually disabled.");
if(this.getConfig().getInt("animate-head-blocks-distance")!=0)
{
//https://wiki.geysermc.org/geyser/events/
//commented out because floodgate currently breaks this. Have to manually subscribe instead of using @subscribe
//GeyserApi.api().eventBus().register(this, this);
GeyserApi.api().eventBus().subscribe(this, SessionJoinEvent.class, this::onGeyserPlayerJoin);
getLogger().info("Animating Heads for Bedrock Players is enabled.");
int animateHeadBlockDistance = this.getConfig().getInt("animate-head-blocks-distance");
AnimateHeadsForGeyser animateHeadsForGeyser = new AnimateHeadsForGeyser(this, animateHeadBlockDistance, Bukkit.getViewDistance());
Bukkit.getPluginManager().registerEvents(animateHeadsForGeyser, this);
BukkitScheduler scheduler = getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
//Player player : Bukkit.getOnlinePlayers()
for (Connection playerConn : Geyser.api().onlineConnections()) {
// Update every 4 ticks
animateHeadsForGeyser.animateForGeyserPlayer(playerConn);
}
}
}, 0L, 4L);
}
else
getLogger().info("Animating Heads for Bedrock Players is manually disabled.");
}
}

public void onGeyserPlayerJoin(SessionJoinEvent event) {
int animateHeadBlockDistance = this.getConfig().getInt("animate-head-blocks-distance");
if((this.getConfig().getInt("animate-head-blocks-distance")!=0) && playerChecker != null)
{
AnimateHeadsForGeyser animateHeadsForGeyser = new AnimateHeadsForGeyser(this, animateHeadBlockDistance, Bukkit.getViewDistance());
//there are no server events needing to be registered at this time in the AnimateHeadsForGeyser class.
Bukkit.getPluginManager().registerEvents(animateHeadsForGeyser, this);
BukkitScheduler scheduler = getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
for (Connection playerConn : Geyser.api().onlineConnections()) {
// Update every 4 ticks
animateHeadsForGeyser.animateForGeyserPlayer(playerConn);
}
}
}, 0L, 4L);
}
}
}

0 comments on commit 90dea90

Please sign in to comment.