use of net.minecraft.entity.item.HangingEntity in project Structurize by ldtteam.
the class Blueprint method transformEntityInfoWithSettings.
/**
* Transform an entity and rotate it.
*
* @param entityInfo the entity nbt.
* @param world the world.
* @param pos the position.
* @param rotation the wanted rotation.
* @param mirror the mirror.
* @return the updated nbt.
*/
private CompoundNBT transformEntityInfoWithSettings(final CompoundNBT entityInfo, final World world, final BlockPos pos, final Rotation rotation, final Mirror mirror) {
final Optional<EntityType<?>> type = EntityType.by(entityInfo);
if (type.isPresent()) {
final Entity finalEntity = type.get().create(world);
if (finalEntity != null) {
try {
finalEntity.deserializeNBT(entityInfo);
final Vector3d entityVec = Blueprint.transformedVector3d(rotation, mirror, finalEntity.position()).add(Vector3d.atLowerCornerOf(pos));
finalEntity.yRotO = (float) (finalEntity.mirror(mirror) - NINETY_DEGREES);
final double rotationYaw = finalEntity.mirror(mirror) + ((double) finalEntity.mirror(mirror) - (double) finalEntity.rotate(rotation));
if (finalEntity instanceof HangingEntity) {
finalEntity.setPos(entityVec.x, entityVec.y, entityVec.z);
} else {
finalEntity.moveTo(entityVec.x, entityVec.y, entityVec.z, (float) rotationYaw, finalEntity.xRot);
}
return finalEntity.serializeNBT();
} catch (final Exception ex) {
Log.getLogger().error("Entity: " + type.get().getDescriptionId() + " failed to load. ", ex);
return null;
}
}
}
return null;
}
use of net.minecraft.entity.item.HangingEntity in project Structurize by ldtteam.
the class BlueprintUtil method createBlueprint.
/**
* Generates a Blueprint objects from the world
*
* @param world The World that is used for the Blueprint
* @param pos The Position of the Blueprint
* @param sizeX The Size on the X-Axis
* @param sizeY The Size on the Y-Axis
* @param sizeZ The Size on the Z-Axis
* @param name a Name for the Structure
* @return the generated Blueprint
*/
public static Blueprint createBlueprint(World world, BlockPos pos, final boolean saveEntities, short sizeX, short sizeY, short sizeZ, String name, Optional<BlockPos> anchorPos) {
final List<BlockState> pallete = new ArrayList<>();
// Allways add AIR to Pallete
pallete.add(Blocks.AIR.defaultBlockState());
final short[][][] structure = new short[sizeY][sizeZ][sizeX];
final List<CompoundNBT> tileEntities = new ArrayList<>();
final List<String> requiredMods = new ArrayList<>();
for (final BlockPos mutablePos : BlockPos.betweenClosed(pos, pos.offset(sizeX - 1, sizeY - 1, sizeZ - 1))) {
BlockState state = world.getBlockState(mutablePos);
String modName = state.getBlock().getRegistryName().getNamespace();
short x = (short) (mutablePos.getX() - pos.getX()), y = (short) (mutablePos.getY() - pos.getY()), z = (short) (mutablePos.getZ() - pos.getZ());
if (!modName.equals("minecraft") && !modName.equals(MOD_ID)) {
if (!ModList.get().getModContainerById(modName).isPresent()) {
structure[y][z][x] = (short) pallete.indexOf(Blocks.AIR.defaultBlockState());
continue;
}
if (!requiredMods.contains(modName)) {
requiredMods.add(modName);
}
}
final TileEntity te = world.getBlockEntity(mutablePos);
if (te != null) {
CompoundNBT teTag = te.serializeNBT();
teTag.putShort("x", x);
teTag.putShort("y", y);
teTag.putShort("z", z);
tileEntities.add(teTag);
}
if (!pallete.contains(state)) {
pallete.add(state);
}
structure[y][z][x] = (short) pallete.indexOf(state);
}
final CompoundNBT[] tes = tileEntities.toArray(new CompoundNBT[0]);
final List<CompoundNBT> entitiesTag = new ArrayList<>();
List<Entity> entities = new ArrayList<>();
if (saveEntities) {
entities = world.getEntities(null, new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + sizeX, pos.getY() + sizeY, pos.getZ() + sizeZ));
}
for (final Entity entity : entities) {
final Vector3d oldPos = entity.position();
final CompoundNBT entityTag = entity.serializeNBT();
if (!entityTag.contains("id"))
continue;
final ListNBT posList = new ListNBT();
posList.add(DoubleNBT.valueOf(oldPos.x - pos.getX()));
posList.add(DoubleNBT.valueOf(oldPos.y - pos.getY()));
posList.add(DoubleNBT.valueOf(oldPos.z - pos.getZ()));
BlockPos entityPos = entity.blockPosition();
if (entity instanceof HangingEntity) {
entityPos = ((HangingEntity) entity).getPos();
}
entityTag.put("Pos", posList);
entityTag.put("TileX", IntNBT.valueOf(entityPos.getX() - pos.getX()));
entityTag.put("TileY", IntNBT.valueOf(entityPos.getY() - pos.getY()));
entityTag.put("TileZ", IntNBT.valueOf(entityPos.getZ() - pos.getZ()));
entitiesTag.add(entityTag);
}
final Blueprint schem = new Blueprint(sizeX, sizeY, sizeZ, (short) pallete.size(), pallete, structure, tes, requiredMods);
schem.setEntities(entitiesTag.toArray(new CompoundNBT[0]));
if (anchorPos.isPresent()) {
BlockPos relativeAnchorPos = new BlockPos(anchorPos.get().subtract(pos));
schem.setCachePrimaryOffset(relativeAnchorPos);
}
// Blueprints do auto-calc anchors when missing, so if it uses a blueprint provider as anchor we fill in the schematic data afterwards to both TE and blueprint
final TileEntity tile = world.getBlockEntity(pos.offset(schem.getPrimaryBlockOffset()));
if (tile instanceof IBlueprintDataProvider) {
final CompoundNBT blueprintData = (CompoundNBT) schem.getBlockInfoAsMap().get(schem.getPrimaryBlockOffset()).getTileEntityData().get(TAG_BLUEPRINTDATA);
if (name != null) {
final String fileName = new File(name).getName();
blueprintData.putString(TAG_SCHEMATIC_NAME, fileName);
((IBlueprintDataProvider) tile).setSchematicName(fileName);
}
final BlockPos corner1 = BlockPos.ZERO.subtract(schem.getPrimaryBlockOffset());
final BlockPos corner2 = new BlockPos(sizeX - 1, sizeY - 1, sizeZ - 1).subtract(schem.getPrimaryBlockOffset());
((IBlueprintDataProvider) tile).setSchematicCorners(corner1, corner2);
BlockPosUtil.writeToNBT(blueprintData, TAG_CORNER_ONE, corner1);
BlockPosUtil.writeToNBT(blueprintData, TAG_CORNER_TWO, corner2);
if (!world.isClientSide) {
((ServerWorld) world).getChunkSource().blockChanged(pos);
}
}
if (name != null) {
schem.setName(name);
}
return schem;
}
use of net.minecraft.entity.item.HangingEntity in project Magma-1.16.x by magmafoundation.
the class CraftWorld method createEntity.
@SuppressWarnings("unchecked")
public net.minecraft.entity.Entity createEntity(Location location, Class<? extends Entity> clazz) throws IllegalArgumentException {
if (location == null || clazz == null) {
throw new IllegalArgumentException("Location or entity class cannot be null");
}
net.minecraft.entity.Entity entity = null;
double x = location.getX();
double y = location.getY();
double z = location.getZ();
float pitch = location.getPitch();
float yaw = location.getYaw();
// order is important for some of these
if (Boat.class.isAssignableFrom(clazz)) {
entity = new BoatEntity(world, x, y, z);
entity.moveTo(x, y, z, yaw, pitch);
} else if (FallingBlock.class.isAssignableFrom(clazz)) {
entity = new FallingBlockEntity(world, x, y, z, world.getBlockState(new BlockPos(x, y, z)));
} else if (Projectile.class.isAssignableFrom(clazz)) {
if (Snowball.class.isAssignableFrom(clazz)) {
entity = new SnowballEntity(world, x, y, z);
} else if (Egg.class.isAssignableFrom(clazz)) {
entity = new EggEntity(world, x, y, z);
} else if (AbstractArrow.class.isAssignableFrom(clazz)) {
if (TippedArrow.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ARROW.create(world);
((ArrowEntity) entity).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SPECTRAL_ARROW.create(world);
} else if (Trident.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.TRIDENT.create(world);
} else {
entity = net.minecraft.entity.EntityType.ARROW.create(world);
}
entity.moveTo(x, y, z, 0, 0);
} else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.EXPERIENCE_BOTTLE.create(world);
entity.moveTo(x, y, z, 0, 0);
} else if (EnderPearl.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ENDER_PEARL.create(world);
entity.moveTo(x, y, z, 0, 0);
} else if (ThrownPotion.class.isAssignableFrom(clazz)) {
if (LingeringPotion.class.isAssignableFrom(clazz)) {
entity = new PotionEntity(world, x, y, z);
((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
entity = new PotionEntity(world, x, y, z);
((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (Fireball.class.isAssignableFrom(clazz)) {
if (SmallFireball.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SMALL_FIREBALL.create(world);
} else if (WitherSkull.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WITHER_SKULL.create(world);
} else if (DragonFireball.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.DRAGON_FIREBALL.create(world);
} else {
entity = net.minecraft.entity.EntityType.FIREBALL.create(world);
}
entity.moveTo(x, y, z, yaw, pitch);
Vector direction = location.getDirection().multiply(10);
((DamagingProjectileEntity) entity).setDirection(direction.getX(), direction.getY(), direction.getZ());
} else if (ShulkerBullet.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SHULKER_BULLET.create(world);
entity.moveTo(x, y, z, yaw, pitch);
} else if (LlamaSpit.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
entity.moveTo(x, y, z, yaw, pitch);
} else if (Firework.class.isAssignableFrom(clazz)) {
entity = new FireworkRocketEntity(world, x, y, z, net.minecraft.item.ItemStack.EMPTY);
}
} else if (Minecart.class.isAssignableFrom(clazz)) {
if (PoweredMinecart.class.isAssignableFrom(clazz)) {
entity = new FurnaceMinecartEntity(world, x, y, z);
} else if (StorageMinecart.class.isAssignableFrom(clazz)) {
entity = new ChestMinecartEntity(world, x, y, z);
} else if (ExplosiveMinecart.class.isAssignableFrom(clazz)) {
entity = new TNTMinecartEntity(world, x, y, z);
} else if (HopperMinecart.class.isAssignableFrom(clazz)) {
entity = new HopperMinecartEntity(world, x, y, z);
} else if (SpawnerMinecart.class.isAssignableFrom(clazz)) {
entity = new SpawnerMinecartEntity(world, x, y, z);
} else if (CommandMinecart.class.isAssignableFrom(clazz)) {
entity = new MinecartEntity(world, x, y, z);
} else {
// Default to rideable minecart for pre-rideable compatibility
entity = new MinecartEntity(world, x, y, z);
}
} else if (EnderSignal.class.isAssignableFrom(clazz)) {
entity = new EyeOfEnderEntity(world, x, y, z);
} else if (EnderCrystal.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.END_CRYSTAL.create(world);
entity.moveTo(x, y, z, 0, 0);
} else if (LivingEntity.class.isAssignableFrom(clazz)) {
if (Chicken.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.CHICKEN.create(world);
} else if (Cow.class.isAssignableFrom(clazz)) {
if (MushroomCow.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.MOOSHROOM.create(world);
} else {
entity = net.minecraft.entity.EntityType.COW.create(world);
}
} else if (Golem.class.isAssignableFrom(clazz)) {
if (Snowman.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SNOW_GOLEM.create(world);
} else if (IronGolem.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.IRON_GOLEM.create(world);
} else if (Shulker.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SHULKER.create(world);
}
} else if (Creeper.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.CREEPER.create(world);
} else if (Ghast.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.GHAST.create(world);
} else if (Pig.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PIG.create(world);
} else if (Player.class.isAssignableFrom(clazz)) {
// need a net server handler for this one
} else if (Sheep.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SHEEP.create(world);
} else if (AbstractHorse.class.isAssignableFrom(clazz)) {
if (ChestedHorse.class.isAssignableFrom(clazz)) {
if (Donkey.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.DONKEY.create(world);
} else if (Mule.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.MULE.create(world);
} else if (Llama.class.isAssignableFrom(clazz)) {
if (TraderLlama.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.TRADER_LLAMA.create(world);
} else {
entity = net.minecraft.entity.EntityType.LLAMA.create(world);
}
}
} else if (SkeletonHorse.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SKELETON_HORSE.create(world);
} else if (ZombieHorse.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ZOMBIE_HORSE.create(world);
} else {
entity = net.minecraft.entity.EntityType.HORSE.create(world);
}
} else if (Skeleton.class.isAssignableFrom(clazz)) {
if (Stray.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.STRAY.create(world);
} else if (WitherSkeleton.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WITHER_SKELETON.create(world);
} else {
entity = net.minecraft.entity.EntityType.SKELETON.create(world);
}
} else if (Slime.class.isAssignableFrom(clazz)) {
if (MagmaCube.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.MAGMA_CUBE.create(world);
} else {
entity = net.minecraft.entity.EntityType.SLIME.create(world);
}
} else if (Spider.class.isAssignableFrom(clazz)) {
if (CaveSpider.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.CAVE_SPIDER.create(world);
} else {
entity = net.minecraft.entity.EntityType.SPIDER.create(world);
}
} else if (Squid.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SQUID.create(world);
} else if (Tameable.class.isAssignableFrom(clazz)) {
if (Wolf.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WOLF.create(world);
} else if (Parrot.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PARROT.create(world);
} else if (Cat.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.CAT.create(world);
}
} else if (PigZombie.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ZOMBIFIED_PIGLIN.create(world);
} else if (Zombie.class.isAssignableFrom(clazz)) {
if (Husk.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.HUSK.create(world);
} else if (ZombieVillager.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ZOMBIE_VILLAGER.create(world);
} else if (Drowned.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.DROWNED.create(world);
} else {
entity = new ZombieEntity(world);
}
} else if (Giant.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.GIANT.create(world);
} else if (Silverfish.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SILVERFISH.create(world);
} else if (Enderman.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ENDERMAN.create(world);
} else if (Blaze.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.BLAZE.create(world);
} else if (AbstractVillager.class.isAssignableFrom(clazz)) {
if (Villager.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.VILLAGER.create(world);
} else if (WanderingTrader.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WANDERING_TRADER.create(world);
}
} else if (Witch.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WITCH.create(world);
} else if (Wither.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.WITHER.create(world);
} else if (ComplexLivingEntity.class.isAssignableFrom(clazz)) {
if (EnderDragon.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ENDER_DRAGON.create(world);
}
} else if (Ambient.class.isAssignableFrom(clazz)) {
if (Bat.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.BAT.create(world);
}
} else if (Rabbit.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.RABBIT.create(world);
} else if (Endermite.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ENDERMITE.create(world);
} else if (Guardian.class.isAssignableFrom(clazz)) {
if (ElderGuardian.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ELDER_GUARDIAN.create(world);
} else {
entity = net.minecraft.entity.EntityType.GUARDIAN.create(world);
}
} else if (ArmorStand.class.isAssignableFrom(clazz)) {
entity = new ArmorStandEntity(world, x, y, z);
} else if (PolarBear.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.POLAR_BEAR.create(world);
} else if (Vex.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.VEX.create(world);
} else if (Illager.class.isAssignableFrom(clazz)) {
if (Spellcaster.class.isAssignableFrom(clazz)) {
if (Evoker.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.EVOKER.create(world);
} else if (Illusioner.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ILLUSIONER.create(world);
}
} else if (Vindicator.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.VINDICATOR.create(world);
} else if (Pillager.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PILLAGER.create(world);
}
} else if (Turtle.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.TURTLE.create(world);
} else if (Phantom.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PHANTOM.create(world);
} else if (Fish.class.isAssignableFrom(clazz)) {
if (Cod.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.COD.create(world);
} else if (PufferFish.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PUFFERFISH.create(world);
} else if (Salmon.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.SALMON.create(world);
} else if (TropicalFish.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.TROPICAL_FISH.create(world);
}
} else if (Dolphin.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.DOLPHIN.create(world);
} else if (Ocelot.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.OCELOT.create(world);
} else if (Ravager.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.RAVAGER.create(world);
} else if (Panda.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PANDA.create(world);
} else if (Fox.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.FOX.create(world);
} else if (Bee.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.BEE.create(world);
} else if (Hoglin.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.HOGLIN.create(world);
} else if (Piglin.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PIGLIN.create(world);
} else if (PiglinBrute.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.PIGLIN_BRUTE.create(world);
} else if (Strider.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.STRIDER.create(world);
} else if (Zoglin.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.ZOGLIN.create(world);
}
if (entity != null) {
entity.absMoveTo(x, y, z, yaw, pitch);
// SPIGOT-3587
entity.setYHeadRot(yaw);
}
} else if (Hanging.class.isAssignableFrom(clazz)) {
BlockFace face = BlockFace.SELF;
// 1 full block, also painting smallest size.
int width = 16;
// 1 full block, also painting smallest size.
int height = 16;
if (ItemFrame.class.isAssignableFrom(clazz)) {
width = 12;
height = 12;
} else if (LeashHitch.class.isAssignableFrom(clazz)) {
width = 9;
height = 9;
}
BlockFace[] faces = new BlockFace[] { BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN };
final BlockPos pos = new BlockPos(x, y, z);
for (BlockFace dir : faces) {
net.minecraft.block.BlockState nmsBlock = world.getBlockState(pos.relative(CraftBlock.blockFaceToNotch(dir)));
if (nmsBlock.getMaterial().isSolid() || RedstoneDiodeBlock.isDiode(nmsBlock)) {
boolean taken = false;
AxisAlignedBB bb = (ItemFrame.class.isAssignableFrom(clazz)) ? ItemFrameEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height) : HangingEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height);
List<net.minecraft.entity.Entity> list = (List<net.minecraft.entity.Entity>) world.getEntities(null, bb);
for (Iterator<net.minecraft.entity.Entity> it = list.iterator(); !taken && it.hasNext(); ) {
net.minecraft.entity.Entity e = it.next();
if (e instanceof HangingEntity) {
// Hanging entities do not like hanging entities which intersect them.
taken = true;
}
}
if (!taken) {
face = dir;
break;
}
}
}
if (LeashHitch.class.isAssignableFrom(clazz)) {
entity = new LeashKnotEntity(world, new BlockPos(x, y, z));
entity.forcedLoading = true;
} else {
// No valid face found
Preconditions.checkArgument(face != BlockFace.SELF, "Cannot spawn hanging entity for %s at %s (no free face)", clazz.getName(), location);
Direction dir = CraftBlock.blockFaceToNotch(face).getOpposite();
if (Painting.class.isAssignableFrom(clazz)) {
entity = new PaintingEntity(world, new BlockPos(x, y, z), dir);
} else if (ItemFrame.class.isAssignableFrom(clazz)) {
entity = new ItemFrameEntity(world, new BlockPos(x, y, z), dir);
}
}
if (entity != null && !((HangingEntity) entity).survives()) {
throw new IllegalArgumentException("Cannot spawn hanging entity for " + clazz.getName() + " at " + location);
}
} else if (TNTPrimed.class.isAssignableFrom(clazz)) {
entity = new TNTEntity(world, x, y, z, null);
} else if (ExperienceOrb.class.isAssignableFrom(clazz)) {
entity = new ExperienceOrbEntity(world, x, y, z, 0);
} else if (LightningStrike.class.isAssignableFrom(clazz)) {
entity = net.minecraft.entity.EntityType.LIGHTNING_BOLT.create(world);
} else if (AreaEffectCloud.class.isAssignableFrom(clazz)) {
entity = new AreaEffectCloudEntity(world, x, y, z);
} else if (EvokerFangs.class.isAssignableFrom(clazz)) {
entity = new EvokerFangsEntity(world, x, y, z, (float) Math.toRadians(yaw), 0, null);
}
if (entity != null) {
return entity;
}
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
use of net.minecraft.entity.item.HangingEntity in project Magma-1.16.x by magmafoundation.
the class CraftItemFrame method setFacingDirection.
@Override
public boolean setFacingDirection(BlockFace face, boolean force) {
HangingEntity hanging = getHandle();
Direction oldDir = hanging.getDirection();
Direction newDir = CraftBlock.blockFaceToNotch(face);
getHandle().setDirection(newDir);
if (!force && !hanging.survives()) {
hanging.setDirection(oldDir);
return false;
}
update();
return true;
}
use of net.minecraft.entity.item.HangingEntity in project LoliServer by Loli-Server.
the class CraftItemFrame method setFacingDirection.
@Override
public boolean setFacingDirection(BlockFace face, boolean force) {
HangingEntity hanging = getHandle();
Direction oldDir = hanging.getDirection();
Direction newDir = CraftBlock.blockFaceToNotch(face);
getHandle().setDirection(newDir);
if (!force && !hanging.survives()) {
hanging.setDirection(oldDir);
return false;
}
update();
return true;
}
Aggregations