use of net.minecraft.server.v1_16_R2.World in project SimplePets by brainsynder-Dev.
the class SpawnUtil method spawn.
public IEntityPet spawn(Location l, IPet pet, String className) {
try {
World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
EntityTypes<?> types = EntityUtils.getType((className.equals("EntityControllerPet")) ? EntityWrapper.ZOMBIE : pet.getEntityType());
EntityPet customEntity = (EntityPet) petMap.get(className).getDeclaredConstructor(EntityTypes.class, World.class, IPet.class).newInstance(types, mcWorld, pet);
customEntity.setInvisible(false);
customEntity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
if (customEntity instanceof IEntityControllerPet) {
if (pet.getPetType() instanceof ArmorStandDefault) {
ArmorStand stand = EntityArmorStandPet.spawn(l, ((EntityControllerPet) customEntity));
stand.setGravity(false);
stand.setArms(true);
stand.setCollidable(false);
stand.setLeftLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setRightLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setLeftArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setRightArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
((IEntityControllerPet) customEntity).setDisplayEntity(stand);
} else if (pet.getPetType() instanceof ShulkerDefault) {
ArmorStand stand = EntityGhostStandPet.spawn(l, pet);
stand.setGravity(false);
stand.setCollidable(false);
stand.setSmall(true);
Shulker shulker = EntityShulkerPet.spawn(l, (EntityControllerPet) customEntity);
shulker.setAI(false);
shulker.setCollidable(false);
stand.addPassenger(shulker);
((IEntityControllerPet) customEntity).setDisplayEntity(stand);
}
}
return customEntity;
} catch (Exception e) {
e.printStackTrace();
throw new SimplePetsException("Could not summon the " + pet.getPetType().getConfigName() + " Pet", e);
}
}
use of net.minecraft.server.v1_16_R2.World in project SimplePets by brainsynder-Dev.
the class SpawnUtil method spawn.
public IEntityPet spawn(Location l, IPet pet, String className) {
try {
World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
EntityPet customEntity = (EntityPet) petMap.get(className).getDeclaredConstructor(World.class, IPet.class).newInstance(mcWorld, pet);
customEntity.setInvisible(false);
customEntity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
if (customEntity instanceof IEntityControllerPet) {
if (pet.getPetType() instanceof ArmorStandDefault) {
ArmorStand stand = EntityArmorStandPet.spawn(l, ((EntityControllerPet) customEntity));
stand.setGravity(false);
stand.setArms(true);
stand.setCollidable(false);
stand.setLeftLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setRightLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setLeftArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
stand.setRightArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
((IEntityControllerPet) customEntity).setDisplayEntity(stand);
} else if (pet.getPetType() instanceof ShulkerDefault) {
ArmorStand stand = EntityGhostStandPet.spawn(l, pet);
stand.setGravity(false);
stand.setCollidable(false);
stand.setSmall(true);
Shulker shulker = EntityShulkerPet.spawn(l, (EntityControllerPet) customEntity);
shulker.setAI(false);
shulker.setCollidable(false);
stand.setPassenger(shulker);
((IEntityControllerPet) customEntity).setDisplayEntity(stand);
}
}
return customEntity;
} catch (Exception e) {
throw new SimplePetsException("Could not summon the " + pet.getPetType().getConfigName() + " Pet", e);
}
}
use of net.minecraft.server.v1_16_R2.World in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_8_R3 method updateSpawner.
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
use of net.minecraft.server.v1_16_R2.World in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_8_R3 method removeLoader.
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if (tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R3::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityList.remove(tileEntityChunkLoader);
}
if (spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
use of net.minecraft.server.v1_16_R2.World in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_7_R4 method removeLoader.
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
long tileEntityLong = LongHash.toLong(x >> 4, z >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if (tileEntityChunkLoader != null) {
tileEntityChunkLoader.removed = true;
world.tileEntityList.remove(tileEntityChunkLoader);
}
if (spawnParticle)
world.a(null, 2001, x, y, z, Block.getId(world.getType(x, y, z)) + (world.getData(x, y, z) << 12));
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
// noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
}
Aggregations