mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Spawn dispenser mobs the same way Bukkit does, closes #18
This commit is contained in:
parent
63fcd3a2b1
commit
0af3603354
@ -1,6 +1,7 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.util.BlockUtils;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -55,7 +56,7 @@ public class SpawnListener extends PlexListener
|
|||||||
if (SPAWN_EGGS.contains(itemType))
|
if (SPAWN_EGGS.contains(itemType))
|
||||||
{
|
{
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location blockLoc = block.getLocation().add(0.5, 0.5, 0.5).add(((Directional)block.getBlockData()).getFacing().getDirection().multiply(0.8));
|
Location blockLoc = BlockUtils.relative(block.getLocation(), ((Directional)block.getBlockData()).getFacing()).add(.5, 0, .5);
|
||||||
EntityType eggType = spawnEggToEntityType(itemType);
|
EntityType eggType = spawnEggToEntityType(itemType);
|
||||||
if (eggType != null)
|
if (eggType != null)
|
||||||
{
|
{
|
||||||
|
21
server/src/main/java/dev/plex/util/BlockUtils.java
Normal file
21
server/src/main/java/dev/plex/util/BlockUtils.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
public class BlockUtils
|
||||||
|
{
|
||||||
|
public static Location relative(Location origin, BlockFace face)
|
||||||
|
{
|
||||||
|
return switch (face)
|
||||||
|
{
|
||||||
|
case UP -> origin.add(0, 1, 0);
|
||||||
|
case DOWN -> origin.subtract(0, 1, 0);
|
||||||
|
case NORTH -> origin.subtract(0, 0, 1);
|
||||||
|
case SOUTH -> origin.add(0, 0, 1);
|
||||||
|
case WEST -> origin.subtract(1, 0, 0);
|
||||||
|
case EAST -> origin.add(1, 0, 0);
|
||||||
|
default -> origin.add(face.getModX(), face.getModY(), face.getModZ());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user