use of net.minecraft.block.BeehiveBlock in project minecolonies by ldtteam.
the class ItemScepterBeekeeper method useOn.
@Override
public ActionResultType useOn(final ItemUseContext useContext) {
// if server world, do nothing
if (useContext.getLevel().isClientSide) {
return ActionResultType.FAIL;
}
final PlayerEntity player = useContext.getPlayer();
final ItemStack scepter = useContext.getPlayer().getItemInHand(useContext.getHand());
final CompoundNBT compound = scepter.getOrCreateTag();
final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), useContext.getLevel());
final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
final IBuilding hut = colony.getBuildingManager().getBuilding(hutPos);
final BuildingBeekeeper building = (BuildingBeekeeper) hut;
if (useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock() instanceof BeehiveBlock) {
final Collection<BlockPos> positions = building.getHives();
final BlockPos pos = useContext.getClickedPos();
if (positions.contains(pos)) {
LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.removehive");
building.removeHive(pos);
SoundUtils.playSoundForPlayer((ServerPlayerEntity) player, SoundEvents.NOTE_BLOCK_BELL, (float) SoundUtils.VOLUME * 2, 0.5f);
} else {
if (positions.size() < building.getMaximumHives()) {
LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.addhive");
building.addHive(pos);
SoundUtils.playSuccessSound(player, player.blockPosition());
}
if (positions.size() >= building.getMaximumHives()) {
LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.maxhives");
player.inventory.removeItemNoUpdate(player.inventory.selected);
}
}
} else {
player.inventory.removeItemNoUpdate(player.inventory.selected);
}
return super.useOn(useContext);
}
Aggregations