use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.
the class BeeJar method fillJar.
@OnlyIn(Dist.CLIENT)
public static void fillJar(ItemStack stack, CustomBeeData beeData) {
EntityType<?> entityType = beeData.getEntityType();
Level world = Minecraft.getInstance().level;
if (world == null)
return;
Entity entity = entityType.create(world);
if (entity != null) {
stack.setTag(BeeInfoUtils.createJarBeeTag((Bee) entity, NBTConstants.NBT_ENTITY));
renameJar(stack, (Bee) entity);
}
}
use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.
the class Smoker method use.
@Override
@NotNull
public InteractionResultHolder<ItemStack> use(Level world, @NotNull Player player, @NotNull InteractionHand hand) {
if (!world.isClientSide) {
int damage = player.getItemInHand(hand).getDamageValue();
int maxDamage = player.getItemInHand(hand).getMaxDamage();
if (flag == 1 && damage < maxDamage) {
player.getItemInHand(hand).hurtAndBreak(1, player, player1 -> player1.broadcastBreakEvent(hand));
flag = 0;
} else {
flag++;
}
Vec3 vec3d = player.getLookAngle();
double x = player.getX() + vec3d.x * 2;
double y = player.getY() + vec3d.y * 2;
double z = player.getZ() + vec3d.z * 2;
AABB axisalignedbb = new AABB((player.getX() + vec3d.x) - 2.5D, (player.getY() + vec3d.y) - 2D, (player.getZ() + vec3d.z) - 2.5D, (player.getX() + vec3d.x) + 2.5D, (player.getY() + vec3d.y) + 2D, (player.getZ() + vec3d.z) + 2.5D);
List<Mob> list = world.getLoadedEntitiesOfClass(Bee.class, axisalignedbb);
list.stream().filter(mobEntity -> mobEntity instanceof Bee && ((Bee) mobEntity).isAngry()).forEach(mobEntity -> {
((Bee) mobEntity).setRemainingPersistentAngerTime(0);
mobEntity.setLastHurtByMob(null);
});
ServerLevel worldServer = (ServerLevel) world;
worldServer.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y + 1.3D, z, 50, 0, 0, 0, 0.01F);
}
return super.use(world, player, hand);
}
use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.
the class BeeBox method interactLivingEntity.
@NotNull
@Override
public InteractionResult interactLivingEntity(@NotNull ItemStack stack, @NotNull Player player, LivingEntity targetIn, @NotNull InteractionHand hand) {
if (targetIn.getCommandSenderWorld().isClientSide() || (!(targetIn instanceof Bee) || !targetIn.isAlive())) {
return InteractionResult.FAIL;
}
if (isTemp)
return InteractionResult.FAIL;
Bee target = (Bee) targetIn;
CompoundTag tag = stack.getTag() == null ? new CompoundTag() : stack.getTag();
ListTag bees = tag.contains(NBTConstants.NBT_BEES) ? tag.getList(NBTConstants.NBT_BEES, 10) : new ListTag();
if (bees.size() == BeeConstants.MAX_BEES_BEE_BOX)
return InteractionResult.FAIL;
CompoundTag entityData = new CompoundTag();
entityData.put(NBTConstants.ENTITY_DATA, BeeInfoUtils.createJarBeeTag(target, NBTConstants.NBT_ID));
bees.add(entityData);
tag.put(NBTConstants.NBT_BEES, bees);
stack.setTag(tag);
player.setItemInHand(hand, stack);
player.swing(hand);
target.remove(true);
return InteractionResult.PASS;
}
use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.
the class BeeJar method useOn.
@NotNull
@Override
public InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
if (player != null) {
Level playerWorld = context.getPlayer().getCommandSenderWorld();
ItemStack stack = context.getItemInHand();
if (playerWorld.isClientSide() || !isFilled(stack))
return InteractionResult.FAIL;
Level worldIn = context.getLevel();
BlockPos pos = context.getClickedPos();
Entity entity = getEntityFromStack(stack, worldIn, true);
if (entity != null) {
if (entity instanceof Bee) {
Bee beeEntity = (Bee) entity;
resetBee(beeEntity);
setBeeAngry(beeEntity, player);
}
BlockPos blockPos = pos.relative(context.getClickedFace());
entity.absMoveTo(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, 0, 0);
worldIn.addFreshEntity(entity);
}
stack.setTag(null);
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}
use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.
the class TieredBeehiveTileEntity method addOccupantWithPresetTicks.
@Override
public void addOccupantWithPresetTicks(@NotNull Entity bee, boolean hasNectar, int ticksInHive) {
if (this.stored.size() < getMaxBees()) {
bee.ejectPassengers();
CompoundTag nbt = new CompoundTag();
bee.save(nbt);
if (this.level != null && bee instanceof Bee) {
int maxTimeInHive = getMaxTimeInHive(bee instanceof ICustomBee ? ((ICustomBee) bee).getCoreData().getMaxTimeInHive() : BeeConstants.MAX_TIME_IN_HIVE);
this.stored.add(new BeeData(nbt, ticksInHive, hasNectar ? maxTimeInHive : MIN_HIVE_TIME));
BlockPos pos = this.getBlockPos();
this.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BEEHIVE_ENTER, SoundSource.BLOCKS, 1.0F, 1.0F);
bee.remove();
}
}
}
Aggregations