mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-23 06:51:19 +01:00
Added WorldCore with some spawner functions.
This commit is contained in:
parent
a818050daf
commit
1dd3f00978
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
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);
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user