use of net.minecraft.world.level.Level in project MyPet by xXKeyleXx.
the class EntityRegistry method createMinecraftEntity.
@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
EntityMyPet petEntity = null;
Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
Level world = ((CraftWorld) bukkitWorld).getHandle();
try {
Constructor<?> ctor = entityClass.getConstructor(Level.class, MyPet.class);
Object obj = ctor.newInstance(world, pet);
if (obj instanceof EntityMyPet) {
petEntity = (EntityMyPet) obj;
}
} catch (Exception e) {
MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
e.printStackTrace();
}
return petEntity;
}
use of net.minecraft.world.level.Level in project MyPet by xXKeyleXx.
the class EntityRegistry method createMinecraftEntity.
@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
EntityMyPet petEntity = null;
Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
Level world = ((CraftWorld) bukkitWorld).getHandle();
try {
Constructor<?> ctor = entityClass.getConstructor(Level.class, MyPet.class);
Object obj = ctor.newInstance(world, pet);
if (obj instanceof EntityMyPet) {
petEntity = (EntityMyPet) obj;
}
} catch (Exception e) {
MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
e.printStackTrace();
}
return petEntity;
}
use of net.minecraft.world.level.Level in project MyPet by xXKeyleXx.
the class RangedAttack method shootProjectile.
public void shootProjectile(LivingEntity target, float damage, Projectile projectile) {
Level world = target.level;
double minY = this.target.getBoundingBox().minY;
switch(projectile) {
case Snowball:
{
MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet);
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - snowball.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
snowball.setDamage(damage);
snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addFreshEntity(snowball);
break;
}
case Egg:
{
MyPetEgg egg = new MyPetEgg(world, entityMyPet);
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - egg.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
egg.setDamage(damage);
egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addFreshEntity(egg);
break;
}
case LargeFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetLargeFireball largeFireball = new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
largeFireball.setPosRaw(largeFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), largeFireball.getZ());
largeFireball.setDamage(damage);
world.addFreshEntity(largeFireball);
entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case SmallFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetSmallFireball smallFireball = new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
smallFireball.setPosRaw(smallFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), smallFireball.getZ());
smallFireball.setDamage(damage);
world.addFreshEntity(smallFireball);
entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case WitherSkull:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetWitherSkull witherSkull = new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ);
witherSkull.setPosRaw(witherSkull.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), witherSkull.getZ());
witherSkull.setDamage(damage);
world.addFreshEntity(witherSkull);
entityMyPet.makeSound("entity.wither.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case DragonFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetDragonFireball dragonFireball = new MyPetDragonFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
dragonFireball.setPosRaw(dragonFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), dragonFireball.getZ());
dragonFireball.setDamage(damage);
world.addFreshEntity(dragonFireball);
entityMyPet.makeSound("entity.ender_dragon.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case Trident:
{
MyPetTrident trident = new MyPetTrident(world, entityMyPet);
trident.setBaseDamage(damage);
trident.setCritArrow(false);
entityMyPet.makeSound("item.trident.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - trident.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
trident.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(trident);
break;
}
case EnderPearl:
{
MyPetEnderPearl enderPearl = new MyPetEnderPearl(world, entityMyPet);
enderPearl.setDamage(damage);
entityMyPet.makeSound("entity.ender_pearl.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - enderPearl.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
enderPearl.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(enderPearl);
break;
}
case LlamaSpit:
{
MyPetLlamaSpit llamaSpit = new MyPetLlamaSpit(world, entityMyPet);
llamaSpit.setDamage(damage);
entityMyPet.makeSound("entity.llama.spit", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + (target.getEyeHeight() / 3.0F) - llamaSpit.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2D;
llamaSpit.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.5F, 10.0F);
world.addFreshEntity(llamaSpit);
break;
}
case Arrow:
default:
{
Arrow arrow = new MyPetArrow(world, entityMyPet);
arrow.setBaseDamage(damage);
arrow.setCritArrow(false);
entityMyPet.makeSound("entity.arrow.shoot", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - arrow.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
arrow.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(arrow);
break;
}
}
}
use of net.minecraft.world.level.Level in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderFullMap.
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
} else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.t(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
use of net.minecraft.world.level.Level in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderFullMap.
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
} else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.setY(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
Aggregations