use of net.minecraft.world.level.block.BeehiveBlock in project ResourcefulBees by Resourceful-Bees.
the class ShearsDispenserBehavior method execute.
@NotNull
@Override
protected ItemStack execute(@NotNull BlockSource source, @NotNull ItemStack stack) {
ServerLevel world = source.getLevel();
BlockPos blockpos = source.getPos().relative(source.getBlockState().getValue(DispenserBlock.FACING));
BlockState blockstate = world.getBlockState(blockpos);
if (blockstate.getBlock() instanceof TieredBeehiveBlock) {
if (Config.ALLOW_SHEARS.get()) {
int i = blockstate.getValue(BeehiveBlock.HONEY_LEVEL);
if (i >= 5) {
if (stack.hurt(1, world.random, null)) {
stack.setCount(0);
}
TieredBeehiveBlock.dropResourceHoneycomb((TieredBeehiveBlock) blockstate.getBlock(), world, blockpos, false);
((BeehiveBlock) blockstate.getBlock()).releaseBeesAndResetHoneyLevel(world, blockstate, blockpos, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
}
}
} else {
return getDefaultShearsDispenseBehavior().dispense(source, stack);
}
return stack;
}
use of net.minecraft.world.level.block.BeehiveBlock in project Silent-Gear by SilentChaos512.
the class GearShearsItem method useOn.
@Override
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockState state = world.getBlockState(pos);
Player player = context.getPlayer();
if (player != null && getHoneyLevel(state) >= 5) {
world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
BeehiveBlock.dropHoneycomb(world, pos);
context.getItemInHand().hurtAndBreak(1, player, (playerEntity) -> {
playerEntity.broadcastBreakEvent(context.getHand());
});
BeehiveBlock block = (BeehiveBlock) state.getBlock();
if (!CampfireBlock.isSmokeyPos(world, pos)) {
if (block.hiveContainsBees(world, pos)) {
block.angerNearbyBees(world, pos);
}
block.releaseBeesAndResetHoneyLevel(world, state, pos, player, BeehiveBlockEntity.BeeReleaseStatus.EMERGENCY);
} else {
block.resetHoneyLevel(world, state, pos);
}
return InteractionResult.sidedSuccess(world.isClientSide);
}
return GearHelper.onItemUse(context);
}
use of net.minecraft.world.level.block.BeehiveBlock in project Create by Creators-of-Create.
the class IMovedDispenseItemBehaviour method init.
static void init() {
MovedProjectileDispenserBehaviour movedPotionDispenseItemBehaviour = new MovedProjectileDispenserBehaviour() {
@Override
protected Projectile getProjectileEntity(Level world, double x, double y, double z, ItemStack itemStack) {
return Util.make(new ThrownPotion(world, x, y, z), (p_218411_1_) -> p_218411_1_.setItem(itemStack));
}
protected float getProjectileInaccuracy() {
return super.getProjectileInaccuracy() * 0.5F;
}
protected float getProjectileVelocity() {
return super.getProjectileVelocity() * .5F;
}
};
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.SPLASH_POTION, movedPotionDispenseItemBehaviour);
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.LINGERING_POTION, movedPotionDispenseItemBehaviour);
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.TNT, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
PrimedTnt tntentity = new PrimedTnt(context.world, x, y, z, null);
tntentity.push(context.motion.x, context.motion.y, context.motion.z);
context.world.addFreshEntity(tntentity);
context.world.playSound(null, tntentity.getX(), tntentity.getY(), tntentity.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
itemStack.shrink(1);
return itemStack;
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIREWORK_ROCKET, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
FireworkRocketEntity fireworkrocketentity = new FireworkRocketEntity(context.world, itemStack, x, y, z, true);
fireworkrocketentity.shoot(facing.x, facing.y, facing.z, 0.5F, 1.0F);
context.world.addFreshEntity(fireworkrocketentity);
itemStack.shrink(1);
return itemStack;
}
@Override
protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
world.levelEvent(1004, pos, 0);
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIRE_CHARGE, new MovedDefaultDispenseItemBehaviour() {
@Override
protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
world.levelEvent(1018, pos, 0);
}
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
Random random = context.world.random;
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
context.world.addFreshEntity(Util.make(new SmallFireball(context.world, x, y, z, random.nextGaussian() * 0.05D + facing.x + context.motion.x, random.nextGaussian() * 0.05D + facing.y + context.motion.y, random.nextGaussian() * 0.05D + facing.z + context.motion.z), (p_229425_1_) -> p_229425_1_.setItem(itemStack)));
itemStack.shrink(1);
return itemStack;
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.GLASS_BOTTLE, new MovedOptionalDispenseBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
this.successful = false;
BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
BlockState state = context.world.getBlockState(interactAt);
Block block = state.getBlock();
if (state.is(BlockTags.BEEHIVES) && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
((BeehiveBlock) block).releaseBeesAndResetHoneyLevel(context.world, state, interactAt, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
this.successful = true;
return placeItemInInventory(itemStack, new ItemStack(Items.HONEY_BOTTLE), context, pos, facing);
} else if (context.world.getFluidState(interactAt).is(FluidTags.WATER)) {
this.successful = true;
return placeItemInInventory(itemStack, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), context, pos, facing);
} else {
return super.dispenseStack(itemStack, context, pos, facing);
}
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.BUCKET, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
BlockState state = context.world.getBlockState(interactAt);
Block block = state.getBlock();
if (block instanceof BucketPickup) {
ItemStack bucket = ((BucketPickup) block).pickupBlock(context.world, interactAt, state);
return placeItemInInventory(itemStack, bucket, context, pos, facing);
}
return super.dispenseStack(itemStack, context, pos, facing);
}
});
}
use of net.minecraft.world.level.block.BeehiveBlock in project Cyclic by Lothrazar.
the class ShearsMaterial method useOn.
@Override
public InteractionResult useOn(UseOnContext context) {
BlockPos blockPos = context.getClickedPos();
BlockState blockState = context.getLevel().getBlockState(blockPos);
Level worldIn = context.getLevel();
Player player = context.getPlayer();
if (blockState.getBlock() instanceof BeehiveBlock && blockState.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
// replicate the behavior of BeehiveBlock#onBlockActivated
worldIn.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
BeehiveBlock.dropHoneycomb(worldIn, blockPos);
worldIn.setBlockAndUpdate(blockPos, blockState.setValue(BeehiveBlock.HONEY_LEVEL, 0));
UtilItemStack.damageItem(player, context.getItemInHand());
return InteractionResult.SUCCESS;
}
return super.useOn(context);
}
use of net.minecraft.world.level.block.BeehiveBlock 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();
}
}
}
}
Aggregations