mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-01-24 00:01:44 +01:00
Merge branch 'development'
This commit is contained in:
commit
13d380b2b9
28
Core/pom.xml
28
Core/pom.xml
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -119,14 +119,16 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.4</version>
|
||||
</dependency-->
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Need to include all NMS modules here -->
|
||||
<!-- Note when adding a new module: include the class in NmsManager -->
|
||||
<dependency>
|
||||
@ -279,18 +281,6 @@
|
||||
<version>1.7.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.myles.viaversion-bukkit</groupId>
|
||||
<artifactId>ViaVersion</artifactId>
|
||||
<version>2.1.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>protocolsupport</groupId>
|
||||
<artifactId>ProtocolSupport</artifactId>
|
||||
<version>4.29</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
|
@ -56,7 +56,7 @@ public class SongodaCore {
|
||||
/**
|
||||
* This has been added as of Rev 6
|
||||
*/
|
||||
private final static String coreVersion = "2.4.54";
|
||||
private final static String coreVersion = "2.4.55";
|
||||
|
||||
/**
|
||||
* This is specific to the website api
|
||||
@ -315,18 +315,18 @@ public class SongodaCore {
|
||||
|
||||
ShadedEventListener() {
|
||||
if ((via = Bukkit.getPluginManager().isPluginEnabled("ViaVersion"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p));
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
||||
} else if ((proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p));
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onLogin(PlayerLoginEvent event) {
|
||||
if (via) {
|
||||
ClientVersion.onLoginVia(event.getPlayer());
|
||||
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
|
||||
} else if (proto) {
|
||||
ClientVersion.onLoginProtocol(event.getPlayer());
|
||||
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,9 +341,9 @@ public class SongodaCore {
|
||||
void onEnable(PluginEnableEvent event) {
|
||||
// technically shouldn't have online players here, but idk
|
||||
if (!via && (via = event.getPlugin().getName().equals("ViaVersion"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p));
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
||||
} else if (!proto && (proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p));
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -67,11 +68,11 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
|
||||
public List<String> getSubCommands(String command) {
|
||||
SimpleNestedCommand nested = command == null ? null : commands.get(command.toLowerCase());
|
||||
return nested == null ? Collections.EMPTY_LIST : nested.children.keySet().stream().collect(Collectors.toList());
|
||||
return nested == null ? Collections.emptyList() : new ArrayList<>(nested.children.keySet());
|
||||
}
|
||||
|
||||
public Set<AbstractCommand> getAllCommands() {
|
||||
HashSet<AbstractCommand> all = new HashSet();
|
||||
HashSet<AbstractCommand> all = new HashSet<>();
|
||||
commands.values().stream()
|
||||
.filter(c -> c.parent != null && !all.contains(c.parent))
|
||||
.forEach(c -> {
|
||||
@ -90,7 +91,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
|
||||
public SimpleNestedCommand registerCommandDynamically(AbstractCommand abstractCommand) {
|
||||
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
|
||||
abstractCommand.getCommands().stream().forEach(cmd -> {
|
||||
abstractCommand.getCommands().forEach(cmd -> {
|
||||
CommandManager.registerCommandDynamically(plugin, cmd, this, this);
|
||||
commands.put(cmd.toLowerCase(), nested);
|
||||
PluginCommand pcmd = plugin.getCommand(cmd);
|
||||
@ -106,7 +107,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
|
||||
public SimpleNestedCommand addCommand(AbstractCommand abstractCommand) {
|
||||
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
|
||||
abstractCommand.getCommands().stream().forEach(cmd -> {
|
||||
abstractCommand.getCommands().forEach(cmd -> {
|
||||
commands.put(cmd.toLowerCase(), nested);
|
||||
PluginCommand pcmd = plugin.getCommand(cmd);
|
||||
if (pcmd != null) {
|
||||
@ -284,7 +285,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private List<String> fetchList(AbstractCommand abstractCommand, String[] args, CommandSender sender) {
|
||||
|
@ -6,19 +6,19 @@ import java.util.stream.Stream;
|
||||
public class SimpleNestedCommand {
|
||||
|
||||
final AbstractCommand parent;
|
||||
final LinkedHashMap<String, AbstractCommand> children = new LinkedHashMap();
|
||||
final LinkedHashMap<String, AbstractCommand> children = new LinkedHashMap<>();
|
||||
|
||||
protected SimpleNestedCommand(AbstractCommand parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public SimpleNestedCommand addSubCommand(AbstractCommand command) {
|
||||
command.getCommands().stream().forEach(cmd -> children.put(cmd.toLowerCase(), command));
|
||||
command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleNestedCommand addSubCommands(AbstractCommand... commands) {
|
||||
Stream.of(commands).forEach(command -> command.getCommands().stream().forEach(cmd -> children.put(cmd.toLowerCase(), command)));
|
||||
Stream.of(commands).forEach(command -> command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command)));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.stackers.Stacker;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
/**
|
||||
@ -67,4 +68,8 @@ public class EntityStackerManager {
|
||||
if (manager.isEnabled())
|
||||
manager.getCurrentHook().add(entity, amount);
|
||||
}
|
||||
|
||||
public static int getMinStackSize(EntityType type) {
|
||||
return manager.isEnabled() ? manager.getCurrentHook().getMinStackSize(type) : 1;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class StackMob extends Stacker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minimumEntityStack(EntityType type) {
|
||||
public int getMinStackSize(EntityType type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,6 @@ public abstract class Stacker implements Hook {
|
||||
|
||||
public abstract void add(LivingEntity entity, int amount);
|
||||
|
||||
public abstract int minimumEntityStack(EntityType type);
|
||||
public abstract int getMinStackSize(EntityType type);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.core.hooks.stackers;
|
||||
|
||||
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.stackable.entity.EntityStackManager;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -64,11 +65,11 @@ public class UltimateStacker extends Stacker {
|
||||
|
||||
@Override
|
||||
public void add(LivingEntity entity, int amount) {
|
||||
plugin.getEntityStackManager().getStack(entity).createDuplicates(amount);
|
||||
plugin.getEntityStackManager().addStack(entity, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minimumEntityStack(EntityType type) {
|
||||
public int getMinStackSize(EntityType type) {
|
||||
return ((Plugin) plugin).getConfig().getInt("Entities.Min Stack Amount");
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class WildStacker extends Stacker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minimumEntityStack(EntityType type) {
|
||||
public int getMinStackSize(EntityType type) {
|
||||
int min = plugin.getConfig().getInt("entities.minimum-limits." + type.name(), -1);
|
||||
if (min == -1) {
|
||||
min = plugin.getConfig().getInt("entities.minimum-limits.all", -1);
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.core.nms;
|
||||
|
||||
import com.songoda.core.nms.anvil.AnvilCore;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.logging.Level;
|
||||
@ -13,73 +14,90 @@ public class NmsManager {
|
||||
private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
private final static AnvilCore anvil;
|
||||
private final static NBTCore nbt;
|
||||
private final static WorldCore world;
|
||||
|
||||
static {
|
||||
switch (serverPackageVersion) {
|
||||
case "v1_8_R1":
|
||||
anvil = new com.songoda.core.nms.v1_8_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_8_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_8_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_8_R2":
|
||||
anvil = new com.songoda.core.nms.v1_8_R2.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_8_R2.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_8_R2.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_8_R3":
|
||||
anvil = new com.songoda.core.nms.v1_8_R3.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_8_R3.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_8_R3.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_9_R1":
|
||||
anvil = new com.songoda.core.nms.v1_9_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_9_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_9_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_9_R2":
|
||||
anvil = new com.songoda.core.nms.v1_9_R2.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_9_R2.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_9_R2.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_10_R1":
|
||||
anvil = new com.songoda.core.nms.v1_10_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_10_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_10_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_11_R1":
|
||||
anvil = new com.songoda.core.nms.v1_11_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_11_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_11_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_12_R1":
|
||||
anvil = new com.songoda.core.nms.v1_12_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_12_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_12_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_13_R1":
|
||||
anvil = new com.songoda.core.nms.v1_13_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_13_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_13_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_13_R2":
|
||||
anvil = new com.songoda.core.nms.v1_13_R2.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_13_R2.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_13_R2.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_14_R1":
|
||||
anvil = new com.songoda.core.nms.v1_14_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_14_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_14_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_15_R1":
|
||||
anvil = new com.songoda.core.nms.v1_15_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_15_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_15_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_16_R1":
|
||||
anvil = new com.songoda.core.nms.v1_16_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_16_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_16_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_16_R2":
|
||||
anvil = new com.songoda.core.nms.v1_16_R2.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_16_R2.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_16_R2.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_16_R3":
|
||||
anvil = new com.songoda.core.nms.v1_16_R3.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_16_R3.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_16_R3.world.WorldCoreImpl();
|
||||
break;
|
||||
default:
|
||||
Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion);
|
||||
anvil = null;
|
||||
nbt = null;
|
||||
world = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -99,4 +117,12 @@ public class NmsManager {
|
||||
public static boolean hasNbt() {
|
||||
return nbt != null;
|
||||
}
|
||||
|
||||
public static WorldCore getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public static boolean hasWorld() {
|
||||
return world != null;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityUtils {
|
||||
|
||||
@ -77,4 +84,33 @@ public class EntityUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<CompatibleMaterial> getSpawnBlocks(EntityType type) {
|
||||
switch (type.name()) {
|
||||
case "PIG":
|
||||
case "SHEEP":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "RABBIT":
|
||||
case "LLAMA":
|
||||
case "HORSE":
|
||||
case "CAT":
|
||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.GRASS_BLOCK));
|
||||
case "MUSHROOM_COW":
|
||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.MYCELIUM));
|
||||
case "SQUID":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "COD":
|
||||
case "SALMON":
|
||||
case "PUFFERFISH":
|
||||
case "TROPICAL_FISH":
|
||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.WATER));
|
||||
case "OCELOT":
|
||||
return new ArrayList<>(Arrays.asList(CompatibleMaterial.GRASS_BLOCK,
|
||||
CompatibleMaterial.JUNGLE_LEAVES, CompatibleMaterial.ACACIA_LEAVES,
|
||||
CompatibleMaterial.BIRCH_LEAVES, CompatibleMaterial.DARK_OAK_LEAVES,
|
||||
CompatibleMaterial.OAK_LEAVES, CompatibleMaterial.SPRUCE_LEAVES));
|
||||
default:
|
||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
76
Core/src/main/java/com/songoda/core/world/SSpawner.java
Normal file
76
Core/src/main/java/com/songoda/core/world/SSpawner.java
Normal file
@ -0,0 +1,76 @@
|
||||
package com.songoda.core.world;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.hooks.EntityStackerManager;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import com.songoda.core.utils.EntityUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SSpawner {
|
||||
|
||||
private static final WorldCore worldCore = NmsManager.getWorld();
|
||||
|
||||
protected final Location location;
|
||||
|
||||
public SSpawner(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public SSpawner(CreatureSpawner spawner) {
|
||||
this(spawner.getLocation());
|
||||
}
|
||||
|
||||
|
||||
public int spawn(int amountToSpawn, EntityType... types) {
|
||||
return spawn(amountToSpawn, "EXPLOSION_NORMAL", null, null, types);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Spawn the spawner.
|
||||
*
|
||||
* If you want support for stackers you will need to load them
|
||||
* on your plugins enable.
|
||||
*
|
||||
* @return amount of entities spawned
|
||||
*/
|
||||
public int spawn(int amountToSpawn, String particle, Set<CompatibleMaterial> canSpawnOn, SpawnedEntity spawned,
|
||||
EntityType... types) {
|
||||
if (location.getWorld() == null) return 0;
|
||||
|
||||
if (canSpawnOn == null)
|
||||
canSpawnOn = new HashSet<>();
|
||||
|
||||
if (canSpawnOn.isEmpty())
|
||||
canSpawnOn.addAll(EntityUtils.getSpawnBlocks(types[0]));
|
||||
|
||||
boolean useStackPlugin = EntityStackerManager.isEnabled();
|
||||
|
||||
int spawnCountUsed = useStackPlugin ? 1 : amountToSpawn;
|
||||
|
||||
int amountSpawned = 0;
|
||||
while (spawnCountUsed-- > 0) {
|
||||
EntityType type = types[ThreadLocalRandom.current().nextInt(types.length)];
|
||||
LivingEntity entity = worldCore.getSpawner(location).spawnEntity(type, particle, spawned, canSpawnOn);
|
||||
if (entity != null) {
|
||||
// If this entity is indeed stackable then spawn a single stack with the desired stack size.
|
||||
if (useStackPlugin && amountToSpawn >= EntityStackerManager.getMinStackSize(type)) {
|
||||
EntityStackerManager.add(entity, amountToSpawn);
|
||||
amountSpawned = amountToSpawn;
|
||||
break;
|
||||
}
|
||||
amountSpawned++;
|
||||
}
|
||||
}
|
||||
return amountSpawned;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -18,5 +18,12 @@
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
58
NMS/NMS-API/src/com/songoda/core/nms/world/SSpawner.java
Normal file
58
NMS/NMS-API/src/com/songoda/core/nms/world/SSpawner.java
Normal file
@ -0,0 +1,58 @@
|
||||
package com.songoda.core.nms.world;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface SSpawner {
|
||||
|
||||
LivingEntity spawnEntity(EntityType type, Location spawnerLocation);
|
||||
|
||||
LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn);
|
||||
|
||||
default String translateName(EntityType type, boolean capital) {
|
||||
return capital ? TypeTranslations.getUpperFromType(type) : TypeTranslations.getLowerFromType(type);
|
||||
}
|
||||
|
||||
enum TypeTranslations {
|
||||
VINDICATOR("vindication_illager", "VindicationIllager"),
|
||||
SNOWMAN("snowman", "SnowMan"),
|
||||
PIG_ZOMBIE("zombie_pigman", "PigZombie"),
|
||||
EVOKER("evocation_illager", "EvocationIllager"),
|
||||
ILLUSIONER("illusion_illager", "IllusionIllager"),
|
||||
IRON_GOLEM("villager_golem", "VillagerGolem"),
|
||||
MUSHROOM_COW("mooshroom", "MushroomCow"),
|
||||
MAGMA_CUBE("magma_cube", "LavaSlime");
|
||||
|
||||
private final String lower;
|
||||
private final String upper;
|
||||
|
||||
TypeTranslations(String lower, String upper) {
|
||||
this.lower = lower;
|
||||
this.upper = upper;
|
||||
}
|
||||
|
||||
public static String getLowerFromType(EntityType type) {
|
||||
try {
|
||||
TypeTranslations typeTranslation = valueOf(type.name());
|
||||
return typeTranslation.lower;
|
||||
} catch (Exception e) {
|
||||
return type.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUpperFromType(EntityType type) {
|
||||
try {
|
||||
TypeTranslations typeTranslation = valueOf(type.name());
|
||||
return typeTranslation.upper;
|
||||
} catch (Exception e) {
|
||||
return WordUtils.capitalize(type.name().toLowerCase()).replace(" ", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.core.nms.world;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
public interface SpawnedEntity {
|
||||
|
||||
boolean onSpawn(LivingEntity entity);
|
||||
|
||||
}
|
11
NMS/NMS-API/src/com/songoda/core/nms/world/WorldCore.java
Normal file
11
NMS/NMS-API/src/com/songoda/core/nms/world/WorldCore.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.songoda.core.nms.world;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public interface WorldCore {
|
||||
|
||||
SSpawner getSpawner(CreatureSpawner spawner);
|
||||
|
||||
SSpawner getSpawner(Location location);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_10_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_10_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.songoda.core.nms.v1_10_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_10_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_10_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_10_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
compound.setString("id", translateName(type, true));
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.D(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_11_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_11_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.songoda.core.nms.v1_11_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_11_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_11_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_11_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.D(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -202,4 +202,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_12_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_12_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.songoda.core.nms.v1_12_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_12_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_12_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.D(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -202,4 +202,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_13_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_13_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package com.songoda.core.nms.v1_13_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_13_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_13_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_13_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -197,8 +197,13 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_13_R2.world;
|
||||
|
||||
import com.songoda.core.nms.v1_13_R2.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package com.songoda.core.nms.v1_13_R2.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_13_R2.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_13_R2.MobSpawnerData;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_13_R2.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_14_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_14_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.songoda.core.nms.v1_14_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_14_R1.EnumMobSpawn;
|
||||
import net.minecraft.server.v1_14_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.getEntity();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.getRandom();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (!optionalEntity.isPresent()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.setPosition(x, y, z);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(world, damageScaler, EnumMobSpawn.SPAWNER,
|
||||
null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_15_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_15_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.songoda.core.nms.v1_15_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_15_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_15_R1.EnumMobSpawn;
|
||||
import net.minecraft.server.v1_15_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.getEntity();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.getRandom();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (!optionalEntity.isPresent()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.setPosition(x, y, z);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(world, damageScaler, EnumMobSpawn.SPAWNER,
|
||||
null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_16_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_16_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.songoda.core.nms.v1_16_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_16_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_16_R1.EnumMobSpawn;
|
||||
import net.minecraft.server.v1_16_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.getEntity();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.getRandom();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (!optionalEntity.isPresent()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.setPosition(x, y, z);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(world, damageScaler, EnumMobSpawn.SPAWNER,
|
||||
null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_16_R2.world;
|
||||
|
||||
import com.songoda.core.nms.v1_16_R2.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.songoda.core.nms.v1_16_R2.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_16_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R2.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_16_R2.Entity;
|
||||
import net.minecraft.server.v1_16_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_16_R2.EntityTypes;
|
||||
import net.minecraft.server.v1_16_R2.EnumMobSpawn;
|
||||
import net.minecraft.server.v1_16_R2.MobSpawnerData;
|
||||
import net.minecraft.server.v1_16_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R2.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.getEntity();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.getRandom();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (!optionalEntity.isPresent()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.setPosition(x, y, z);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(world, damageScaler, EnumMobSpawn.SPAWNER,
|
||||
null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.16.4</version>
|
||||
<version>1.16.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_16_R3.world;
|
||||
|
||||
import com.songoda.core.nms.v1_16_R3.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.songoda.core.nms.v1_16_R3.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R3.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityInsentient;
|
||||
import net.minecraft.server.v1_16_R3.EntityTypes;
|
||||
import net.minecraft.server.v1_16_R3.EnumMobSpawn;
|
||||
import net.minecraft.server.v1_16_R3.MobSpawnerData;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.getEntity();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.setString("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.getRandom();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (!optionalEntity.isPresent()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.setPosition(x, y, z);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(world, damageScaler, EnumMobSpawn.SPAWNER,
|
||||
null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox()))
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -203,4 +203,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_8_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_8_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.songoda.core.nms.v1_8_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_8_R1.Entity;
|
||||
import net.minecraft.server.v1_8_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_8_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
|
||||
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.E(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -202,4 +202,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_8_R2.world;
|
||||
|
||||
import com.songoda.core.nms.v1_8_R2.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.songoda.core.nms.v1_8_R2.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R2.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_8_R2.Entity;
|
||||
import net.minecraft.server.v1_8_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R2.EntityTypes;
|
||||
import net.minecraft.server.v1_8_R2.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
|
||||
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.E(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -202,4 +202,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_8_R3.world;
|
||||
|
||||
import com.songoda.core.nms.v1_8_R3.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.songoda.core.nms.v1_8_R3.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R3.EntityTypes;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
|
||||
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.E(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_9_R1.world;
|
||||
|
||||
import com.songoda.core.nms.v1_9_R1.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.songoda.core.nms.v1_9_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_9_R1.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_9_R1.Entity;
|
||||
import net.minecraft.server.v1_9_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_9_R1.MobSpawnerData;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
compound.setString("id", translateName(type, true));
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.D(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -25,5 +25,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -201,4 +201,9 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.songoda.core.nms.v1_9_R2.world;
|
||||
|
||||
import com.songoda.core.nms.v1_9_R2.world.spawner.SSpawnerImpl;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.songoda.core.nms.v1_9_R2.world.spawner;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.server.v1_9_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R2.ChunkRegionLoader;
|
||||
import net.minecraft.server.v1_9_R2.DifficultyDamageScaler;
|
||||
import net.minecraft.server.v1_9_R2.Entity;
|
||||
import net.minecraft.server.v1_9_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_9_R2.MobSpawnerData;
|
||||
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R2.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.b();
|
||||
|
||||
compound.setString("id", translateName(type, true));
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.random;
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||
|
||||
BlockPosition position = entity.getChunkCoordinates();
|
||||
DifficultyDamageScaler damageScaler = world.D(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient))
|
||||
continue;
|
||||
|
||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
if (!canSpawn(entityInsentient, spot, canSpawnOn))
|
||||
continue;
|
||||
|
||||
entityInsentient.prepare(damageScaler,null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null)
|
||||
if (!spawned.onSpawn(craftEntity))
|
||||
return null;
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!entityInsentient.canSpawn())
|
||||
return false;
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null)
|
||||
return false;
|
||||
|
||||
if (!spawnedIn.isAir()
|
||||
&& spawnedIn != CompatibleMaterial.WATER
|
||||
&& !spawnedIn.name().contains("PRESSURE")
|
||||
&& !spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ Maven Information
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
@ -37,6 +37,6 @@ repositories {
|
||||
* Artifact:
|
||||
```groovy
|
||||
dependencies {
|
||||
compileOnly 'com.songoda:SongodaCore:2.4.54'
|
||||
compileOnly 'com.songoda:SongodaCore:2.4.55'
|
||||
}
|
||||
```
|
34
compatibility/pom.xml
Normal file
34
compatibility/pom.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.55</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.myles.viaversion-bukkit</groupId>
|
||||
<artifactId>ViaVersion</artifactId>
|
||||
<version>2.1.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>protocolsupport</groupId>
|
||||
<artifactId>ProtocolSupport</artifactId>
|
||||
<version>4.29</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -34,8 +34,8 @@ public class ClientVersion {
|
||||
* Do Not Use: This is handled by SongodaCore.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void onLoginProtocol(Player p) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), () -> {
|
||||
public static void onLoginProtocol(Player p, JavaPlugin plugin) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
if (p.isOnline()) {
|
||||
final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId();
|
||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||
@ -47,8 +47,8 @@ public class ClientVersion {
|
||||
* Do Not Use: This is handled by SongodaCore.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void onLoginVia(Player p) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), () -> {
|
||||
public static void onLoginVia(Player p, JavaPlugin plugin) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
if (p.isOnline()) {
|
||||
final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId());
|
||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||
@ -94,6 +94,9 @@ public class ClientVersion {
|
||||
return ServerVersion.V1_15;
|
||||
case 735:
|
||||
case 736:
|
||||
case 751:
|
||||
case 753:
|
||||
case 754:
|
||||
return ServerVersion.V1_16;
|
||||
}
|
||||
return version > 498 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN;
|
@ -1,6 +1,5 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.utils.NMSUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -127,13 +126,14 @@ public enum CompatibleBiome {
|
||||
compatibleBiomes.add(biome);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_15)) {
|
||||
Class<?> classBiomeBase = NMSUtils.getNMSClass("BiomeBase"),
|
||||
classCraftChunk = NMSUtils.getCraftClass("CraftChunk"),
|
||||
classCraftBlock = NMSUtils.getCraftClass("block.CraftBlock"),
|
||||
classChunk = NMSUtils.getNMSClass("Chunk"),
|
||||
classBiomeStorage = NMSUtils.getNMSClass("BiomeStorage"),
|
||||
classIRegistry = NMSUtils.getNMSClass("IRegistry");
|
||||
try {
|
||||
Class<?> classBiomeBase = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".BiomeBase"),
|
||||
classCraftChunk = Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString() + ".CraftChunk"),
|
||||
classCraftBlock = Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString() + ".block.CraftBlock"),
|
||||
classChunk = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".Chunk"),
|
||||
classBiomeStorage = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".BiomeStorage"),
|
||||
classIRegistry = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".IRegistry");
|
||||
|
||||
methodBiomeToBiomeBase = isAbove1_16_R1 ? classCraftBlock.getMethod("biomeToBiomeBase", classIRegistry, Biome.class)
|
||||
: classCraftBlock.getMethod("biomeToBiomeBase", Biome.class);
|
||||
methodGetHandle = classCraftChunk.getMethod("getHandle");
|
||||
@ -149,7 +149,7 @@ public enum CompatibleBiome {
|
||||
fieldStorageRegistry = classBiomeStorage.getDeclaredField("g");
|
||||
}
|
||||
fieldStorageRegistry.setAccessible(true);
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
} catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.utils.NMSUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -115,10 +114,10 @@ public enum CompatibleHand {
|
||||
|
||||
if (cb_CraftPlayer == null) {
|
||||
try {
|
||||
cb_CraftPlayer = NMSUtils.getCraftClass("entity.CraftPlayer");
|
||||
Class<?> mc_EntityLiving = NMSUtils.getNMSClass("EntityLiving");
|
||||
Class<?> cb_ItemStack = NMSUtils.getCraftClass("inventory.CraftItemStack");
|
||||
Class<?> mc_ItemStack = NMSUtils.getNMSClass("ItemStack");
|
||||
cb_CraftPlayer = Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString() + ".entity.CraftPlayer");
|
||||
Class<?> mc_EntityLiving = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".EntityLiving");
|
||||
Class<?> cb_ItemStack = Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString() + ".inventory.CraftItemStack");
|
||||
Class<?> mc_ItemStack = Class.forName("net.minecraft.server." + ServerVersion.getServerVersionString() + ".ItemStack");
|
||||
getHandle = cb_CraftPlayer.getMethod("getHandle");
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
playBreak = mc_EntityLiving.getDeclaredMethod("a", mc_ItemStack, int.class); //Consistent from 1.16-1.13
|
||||
@ -126,7 +125,7 @@ public enum CompatibleHand {
|
||||
playBreak = mc_EntityLiving.getDeclaredMethod("b", mc_ItemStack); //Consistent from 1.12-1.8
|
||||
playBreak.setAccessible(true);
|
||||
asNMSCopy = cb_ItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
@ -105,7 +105,7 @@ public class CompatibleParticleHandler {
|
||||
final boolean compatibilityMode;
|
||||
final LegacyParticleEffects.Type compatibleEffect;
|
||||
final Object particle;
|
||||
final static Map<String, ParticleType> map = new HashMap();
|
||||
final static Map<String, ParticleType> map = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (ParticleType t : values()) {
|
||||
@ -218,16 +218,24 @@ public class CompatibleParticleHandler {
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) {
|
||||
spawnParticles(type, location, count, offsetX, offsetY, offsetZ, extra, null);
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, Player receiver) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (offsetX * (Math.random() - Math.random()));
|
||||
float yy = (float) (offsetY * (Math.random() - Math.random()));
|
||||
float zz = (float) (offsetZ * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect, 0F, 0F, 0F, (float) extra, 0, null);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect, 0F, 0F, 0F, (float) extra, 0, receiver != null ? Collections.singletonList(receiver) : null);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ, extra);
|
||||
if (receiver == null) {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ, extra);
|
||||
} else {
|
||||
receiver.spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,5 +304,4 @@ public class CompatibleParticleHandler {
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.NORTH);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_WEST);
|
||||
}
|
||||
|
||||
}
|
3
pom.xml
3
pom.xml
@ -2,12 +2,13 @@
|
||||
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.4.54</version>
|
||||
<version>2.4.55</version>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>Core</module>
|
||||
<module>Compatibility</module>
|
||||
<module>NMS/NMS-API</module>
|
||||
<module>NMS/NMS-v1_8_R1</module>
|
||||
<module>NMS/NMS-v1_8_R2</module>
|
||||
|
Loading…
Reference in New Issue
Block a user