use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project ResourcefulBees by Resourceful-Bees.
the class HoneyDipper method useOn.
@Override
@NotNull
public InteractionResult useOn(@NotNull UseOnContext useContext) {
if (!useContext.getLevel().isClientSide()) {
Block clickedBlock = useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock();
if (selectedBee instanceof CustomBeeEntity) {
CoreData beeData = ((CustomBeeEntity) selectedBee).getCoreData();
if (!beeData.getBlockFlowers().isEmpty() && beeData.getBlockFlowers().contains(clickedBlock)) {
setFlowerPosition(useContext);
return InteractionResult.SUCCESS;
}
} else if (selectedBee != null && clickedBlock.is(BlockTags.FLOWERS)) {
setFlowerPosition(useContext);
return InteractionResult.SUCCESS;
}
BlockEntity clickedTile = useContext.getLevel().getBlockEntity(useContext.getClickedPos());
if (selectedBee != null && (clickedTile instanceof BeehiveBlockEntity || clickedTile instanceof ApiaryTileEntity)) {
selectedBee.hivePos = useContext.getClickedPos();
sendMessageToPlayer(useContext.getPlayer(), MessageTypes.HIVE, useContext.getClickedPos());
selectedBee = null;
return InteractionResult.SUCCESS;
}
}
return super.useOn(useContext);
}
use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project AlexsMobs by Alex-the-666.
the class GrizzlyBearAIBeehive method eatHive.
private void eatHive() {
if (net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(bear.level, bear)) {
BlockState blockstate = bear.level.getBlockState(this.blockPos);
if (blockstate.is(AMTagRegistry.GRIZZLY_BEEHIVE)) {
if (bear.level.getBlockEntity(this.blockPos) instanceof BeehiveBlockEntity) {
Random rand = new Random();
BeehiveBlockEntity beehivetileentity = (BeehiveBlockEntity) bear.level.getBlockEntity(this.blockPos);
beehivetileentity.emptyAllLivingFromHive(null, blockstate, BeehiveBlockEntity.BeeReleaseStatus.EMERGENCY);
bear.level.updateNeighbourForOutputSignal(this.blockPos, blockstate.getBlock());
ItemStack stack = new ItemStack(Items.HONEYCOMB);
int level = 0;
if (blockstate.getBlock() instanceof BeehiveBlock) {
level = blockstate.getValue(BeehiveBlock.HONEY_LEVEL);
}
for (int i = 0; i < level; i++) {
ItemEntity itementity = new ItemEntity(bear.level, blockPos.getX() + rand.nextFloat(), blockPos.getY() + rand.nextFloat(), blockPos.getZ() + rand.nextFloat(), stack);
itementity.setDefaultPickUpDelay();
bear.level.addFreshEntity(itementity);
}
bear.level.destroyBlock(blockPos, false);
if (blockstate.getBlock() instanceof BeehiveBlock) {
bear.level.setBlockAndUpdate(blockPos, blockstate.setValue(BeehiveBlock.HONEY_LEVEL, 0));
}
double d0 = 15;
for (Bee bee : bear.level.getEntitiesOfClass(Bee.class, new AABB((double) blockPos.getX() - d0, (double) blockPos.getY() - d0, (double) blockPos.getZ() - d0, (double) blockPos.getX() + d0, (double) blockPos.getY() + d0, (double) blockPos.getZ() + d0))) {
bee.setRemainingPersistentAngerTime(100);
bee.setTarget(bear);
bee.setStayOutOfHiveCountdown(400);
}
stop();
}
}
}
}
use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project BYG by AOCAWOL.
the class BeeHiveFeature method place.
public boolean place(WorldGenLevel world, ChunkGenerator generator, Random rand, BlockPos pos, NoneFeatureConfiguration config) {
if (world.isEmptyBlock(pos) && world.isEmptyBlock(pos.below())) {
if (world.getBlockState(pos.above()).is(BlockTags.LEAVES) || world.getBlockState(pos.above()).is(BlockTags.LOGS) || world.getBlockState(pos.above()).is(BYGBlocks.EMBUR_GEL_BLOCK)) {
Direction direction;
if (world.isEmptyBlock(pos.north()))
direction = Direction.NORTH;
else if (world.isEmptyBlock(pos.south()))
direction = Direction.SOUTH;
else if (world.isEmptyBlock(pos.west()))
direction = Direction.WEST;
else
direction = Direction.EAST;
BlockState beeHiveState = Blocks.BEE_NEST.defaultBlockState().setValue(BeehiveBlock.FACING, direction);
world.setBlock(pos, beeHiveState, 2);
BlockEntity tileEntity = world.getBlockEntity(pos);
if (tileEntity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehiveTileEntity = (BeehiveBlockEntity) tileEntity;
int beeCount = rand.nextInt(4);
for (int bee = 0; bee <= beeCount; bee++) {
Bee beeEntity = new Bee(EntityType.BEE, world.getLevel());
beehiveTileEntity.addOccupantWithPresetTicks(beeEntity, false, rand.nextInt(599));
}
}
return true;
}
}
return false;
}
use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project ResourcefulBees by Resourceful-Bees.
the class MixinEnterBeehiveGoal method start.
/**
* @author epic_oreo
* @reason crashes when switching to vanilla code due to hivePos being null. retained vanilla checks in overwrite.
*/
@Overwrite()
public void start() {
if (beeEntity.hivePos != null) {
BlockEntity tileentity = beeEntity.level.getBlockEntity(beeEntity.hivePos);
if (tileentity != null) {
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehivetileentity = (BeehiveBlockEntity) tileentity;
beehivetileentity.addOccupant(beeEntity, beeEntity.hasNectar());
} else if (tileentity instanceof ApiaryTileEntity) {
ApiaryTileEntity apiaryTileEntity = (ApiaryTileEntity) tileentity;
apiaryTileEntity.tryEnterHive(beeEntity, beeEntity.hasNectar(), false);
}
}
}
}
use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project Mohist by MohistMC.
the class CraftBeehive method releaseEntities.
@Override
public List<Bee> releaseEntities() {
ensureNoWorldGeneration();
List<Bee> bees = new ArrayList<>();
if (isPlaced()) {
BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
for (Entity bee : beehive.releaseBees(this.getHandle(), BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED, true)) {
bees.add((Bee) bee.getBukkitEntity());
}
}
return bees;
}
Aggregations